Skip to content

Commit e42828d

Browse files
committed
updated simulations vignette
1 parent 69a04d7 commit e42828d

15 files changed

+53
-27
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
## Summary of larger updates:
55

66
- Added support for auto creating interactions amongst variables
7+
- exported `getCoefTable()` function
78

89
## Summary of smaller updates:
910

README.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ knitr::opts_chunk$set(
1010
warning = FALSE,
1111
message = FALSE,
1212
comment = "#>",
13-
fig.path = "man/figures/",
13+
fig.path = "man/figs/",
1414
fig.retina = 3
1515
)
1616
```
1717

18-
# logitr <a href='https://jhelvy.github.io/logitr/'><img src='man/figures/logitr-hex.png' align="right" height="139" /></a>
18+
# logitr <a href='https://jhelvy.github.io/logitr/'><img src='man/figs/logitr-hex.png' align="right" height="139" /></a>
1919

2020
<!-- badges: start -->
2121
[![Lifecycle:

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<!-- README.md is generated from README.Rmd. Please edit that file -->
33

4-
# logitr <a href='https://jhelvy.github.io/logitr/'><img src='man/figures/logitr-hex.png' align="right" height="139" /></a>
4+
# logitr <a href='https://jhelvy.github.io/logitr/'><img src='man/figs/logitr-hex.png' align="right" height="139" /></a>
55

66
<!-- badges: start -->
77

@@ -88,16 +88,16 @@ citation("logitr")
8888
#>
8989
#> To cite logitr in publications use:
9090
#>
91-
#> John Paul Helveston. logitr: Random utility logit models with
92-
#> preference and willingness to pay space parameterizations (2020)
91+
#> John Paul Helveston (2020). logitr: Random utility logit models with
92+
#> preference and willingness to pay space parameterizations.
9393
#>
9494
#> A BibTeX entry for LaTeX users is
9595
#>
9696
#> @Manual{,
9797
#> title = {logitr: Random utility logit models with preference and willingness to pay space parameterizations},
9898
#> author = {John Paul Helveston},
9999
#> year = {2020},
100-
#> note = {R package version 0.0.4},
100+
#> note = {R package version 0.0.5},
101101
#> url = {https://jhelvy.github.io/logitr/},
102102
#> }
103103
```

_pkgdown.yml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ reference:
5454
contents:
5555
- summary.logitr
5656
- coef.logitr
57+
- getCoefTable
5758
- statusCodes
5859
- title: "Computing and Comparing WTP"
5960
desc: "Functions for computing and comparing WTP from estimated models."

inst/example/simulations.R

+16-10
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ sim_mxl_pref
4949
sim_mxl_wtp <- simulateShares(mxl_wtp, alts, priceName = 'price')
5050
sim_mxl_wtp
5151

52-
# Plot simulation results from preference space MNL model:
53-
library(ggplot2)
54-
sim_mnl_pref$alt <- row.names(sim_mnl_pref)
55-
ggplot(sim_mnl_pref, aes(x = alt, y = share_mean)) +
56-
geom_bar(stat = 'identity', width = 0.7, fill = "dodgerblue") +
57-
geom_errorbar(aes(ymin = share_low, ymax = share_high), width = 0.2) +
58-
scale_y_continuous(limits = c(0, 1)) +
59-
labs(x = 'Alternative', y = 'Expected Share') +
60-
theme_bw()
61-
6252
# Save results
6353
saveRDS(sim_mnl_pref,
6454
here::here('inst', 'extdata', 'sim_mnl_pref.Rds'))
@@ -68,3 +58,19 @@ saveRDS(sim_mxl_pref,
6858
here::here('inst', 'extdata', 'sim_mxl_pref.Rds'))
6959
saveRDS(sim_mxl_wtp,
7060
here::here('inst', 'extdata', 'sim_mxl_wtp.Rds'))
61+
62+
# Plot simulation results from each model:
63+
library(ggplot2)
64+
65+
sims <- rbind(sim_mnl_pref, sim_mnl_wtp, sim_mxl_pref, sim_mxl_wtp)
66+
sims$model <- c(rep("mnl_pref", 4), rep("mnl_wtp", 4),
67+
rep("mxl_pref", 4), rep("mxl_wtp", 4))
68+
sims$alt <- rep(row.names(alts), 4)
69+
70+
ggplot(sims, aes(x = alt, y = share_mean, fill = model)) +
71+
geom_bar(stat = 'identity', width = 0.7, position = "dodge") +
72+
geom_errorbar(aes(ymin = share_low, ymax = share_high),
73+
width = 0.2, position = position_dodge(width = 0.7)) +
74+
scale_y_continuous(limits = c(0, 1)) +
75+
labs(x = 'Alternative', y = 'Expected Share') +
76+
theme_bw()

inst/extdata/sim_mnl_pref.Rds

-3 Bytes
Binary file not shown.

inst/extdata/sim_mnl_wtp.Rds

0 Bytes
Binary file not shown.

inst/extdata/sim_mxl_pref.Rds

1 Byte
Binary file not shown.

inst/extdata/sim_mxl_wtp.Rds

1 Byte
Binary file not shown.
File renamed without changes.
File renamed without changes.

next_release.md

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
# logitr 0.0.5
1+
# logitr 0.0.6
22

33
## Summary of larger updates:
44

5-
- Added support for creating interactions amongst variables
65

76
## Summary of smaller updates:
8-
9-
- Added new documentation for prepping data:
10-
- overall structure
11-
- dummyCode() function
12-
- handling interactions
13-
- All vignettes proof-read with lots of small changes to examples
14-
- Added a hex sticker

vignettes/figs/unnamed-chunk-11-1.png

89.5 KB
Loading

vignettes/mnl_models_weighted.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ summary(mnl_wtp_weighted)
158158

159159
# Compare results
160160

161-
Here is a comparison of the coefficients between the weighted and unweighted models. All of the significant coefficients:
161+
Here is a comparison of the coefficients between the weighted and unweighted models. All of the significant coefficients have the same sign, but the magnitudes shift some based on the differential weighting of each individual choice in the weighted model:
162162

163163
```{r}
164164
coef_compare <- data.frame(
@@ -167,7 +167,7 @@ coef_compare <- data.frame(
167167
coef_compare
168168
```
169169

170-
Compare the log-likelihood between the weighted and unweighted models:
170+
Here is a comparison of the log-likelihood for the weighted and unweighted models:
171171

172172
```{r}
173173
logLik_compare <- c(

vignettes/simulations.Rmd

+26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ knitr::opts_chunk$set(
1313
collapse = TRUE,
1414
warning = FALSE,
1515
message = FALSE,
16+
fig.path = "figs/",
1617
fig.retina = 3,
1718
comment = "#>"
1819
)
@@ -60,6 +61,10 @@ You can also use WTP space models to simulate shares, but you must provide the a
6061
```{r, eval=FALSE}
6162
sim_mnl_wtp <- simulateShares(mnl_wtp, alts, priceName = 'price')
6263
```
64+
```
65+
#> **Using results for model 1 of 10,
66+
#> the best model (largest log-likelihood) from the multistart**
67+
```
6368
```{r}
6469
sim_mnl_wtp
6570
```
@@ -83,3 +88,24 @@ sim_mxl_wtp <- simulateShares(mxl_wtp, alts, priceName = 'price')
8388
```{r}
8489
sim_mxl_wtp
8590
```
91+
92+
Here is a bar plot of the results from each model:
93+
94+
```{r, fig.width=6, fig.height=4}
95+
library(ggplot2)
96+
97+
sims <- rbind(sim_mnl_pref, sim_mnl_wtp, sim_mxl_pref, sim_mxl_wtp)
98+
sims$model <- c(rep("mnl_pref", 4), rep("mnl_wtp", 4),
99+
rep("mxl_pref", 4), rep("mxl_wtp", 4))
100+
sims$alt <- rep(row.names(alts), 4)
101+
102+
ggplot(sims, aes(x = alt, y = share_mean, fill = model)) +
103+
geom_bar(stat = 'identity', width = 0.7, position = "dodge") +
104+
geom_errorbar(aes(ymin = share_low, ymax = share_high),
105+
width = 0.2, position = position_dodge(width = 0.7)) +
106+
scale_y_continuous(limits = c(0, 1)) +
107+
labs(x = 'Alternative', y = 'Expected Share') +
108+
theme_bw()
109+
```
110+
111+
# References

0 commit comments

Comments
 (0)