This vignette demonstrates an example of how to use the
logitr()
function to estimate multinomial logit (MNL)
models with preference space and WTP space utility
parameterizations.
This example uses the yogurt data set from Jain et al. (1994). The data set contains 2,412 choice observations from a series of yogurt purchases by a panel of 100 households in Springfield, Missouri, over a roughly two-year period. The data were collected by optical scanners and contain information about the price, brand, and a “feature” variable, which identifies whether a newspaper advertisement was shown to the customer. There are four brands of yogurt: Yoplait, Dannon, Weight Watchers, and Hiland, with market shares of 34%, 40%, 23% and 3%, respectively.
In the utility models described below, the data variables are represented as follows:
Symbol | Variable |
---|---|
The price in US dollars. | |
Dummy variable for whether the newspaper advertisement was shown to the customer. | |
Dummy variable for the “Highland” brand. | |
Dummy variable for the “Weight Watchers” brand. | |
Dummy variable for the “Yoplait” brand. |
This example will estimate the following homogeneous multinomial logit model in the preference space:
where the parameters , , , , and have units of utility.
Estimate the model using the logitr()
function:
library("logitr")
mnl_pref <- logitr(
data = yogurt,
outcome = 'choice',
obsID = 'obsID',
pars = c('price', 'feat', 'brand')
)
Print a summary of the results:
summary(mnl_pref)
#> =================================================
#>
#> Model estimated on: Fri Nov 01 19:41:51 2024
#>
#> Using logitr version: 1.1.2
#>
#> Call:
#> logitr(data = yogurt, outcome = "choice", obsID = "obsID", pars = c("price",
#> "feat", "brand"))
#>
#> Frequencies of alternatives:
#> 1 2 3 4
#> 0.402156 0.029436 0.229270 0.339138
#>
#> Exit Status: 3, Optimization stopped because ftol_rel or ftol_abs was reached.
#>
#> Model Type: Multinomial Logit
#> Model Space: Preference
#> Model Run: 1 of 1
#> Iterations: 21
#> Elapsed Time: 0h:0m:0.02s
#> Algorithm: NLOPT_LD_LBFGS
#> Weights Used?: FALSE
#> Robust? FALSE
#>
#> Model Coefficients:
#> Estimate Std. Error z-value Pr(>|z|)
#> price -0.366555 0.024365 -15.0441 < 2.2e-16 ***
#> feat 0.491439 0.120062 4.0932 4.254e-05 ***
#> brandhiland -3.715477 0.145417 -25.5506 < 2.2e-16 ***
#> brandweight -0.641138 0.054498 -11.7645 < 2.2e-16 ***
#> brandyoplait 0.734519 0.080642 9.1084 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Log-Likelihood: -2656.8878790
#> Null Log-Likelihood: -3343.7419990
#> AIC: 5323.7757580
#> BIC: 5352.7168000
#> McFadden R2: 0.2054148
#> Adj McFadden R2: 0.2039195
#> Number of Observations: 2412.0000000
View the estimated model coefficients:
coef(mnl_pref)
#> price feat brandhiland brandweight brandyoplait
#> -0.3665546 0.4914392 -3.7154773 -0.6411384 0.7345195
Compute the WTP implied from the preference space model:
wtp_mnl_pref <- wtp(mnl_pref, scalePar = "price")
wtp_mnl_pref
#> Estimate Std. Error z-value Pr(>|z|)
#> scalePar 0.366555 0.024388 15.0299 < 2.2e-16 ***
#> feat 1.340699 0.359070 3.7338 0.0001886 ***
#> brandhiland -10.136219 0.585204 -17.3208 < 2.2e-16 ***
#> brandweight -1.749094 0.181314 -9.6468 < 2.2e-16 ***
#> brandyoplait 2.003848 0.143059 14.0071 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
This example will estimate the following homogeneous multinomial logit model in the WTP space:
where the parameters , , , and have units of dollars and is the scale parameter.
Estimate the model using the logitr()
function:
mnl_wtp <- logitr(
data = yogurt,
outcome = 'choice',
obsID = 'obsID',
pars = c('feat', 'brand'),
scalePar = 'price',
# Since WTP space models are non-convex, run a multistart
numMultiStarts = 10,
# Use the computed WTP from the preference space model as the starting
# values for the first run:
startVals = wtp_mnl_pref$Estimate
)
Print a summary of the results:
summary(mnl_wtp)
#> =================================================
#>
#> Model estimated on: Fri Nov 01 19:41:52 2024
#>
#> Using logitr version: 1.1.2
#>
#> Call:
#> logitr(data = yogurt, outcome = "choice", obsID = "obsID", pars = c("feat",
#> "brand"), scalePar = "price", startVals = wtp_mnl_pref$Estimate,
#> numMultiStarts = 10)
#>
#> Frequencies of alternatives:
#> 1 2 3 4
#> 0.402156 0.029436 0.229270 0.339138
#>
#> Summary Of Multistart Runs:
#> Log Likelihood Iterations Exit Status
#> 1 -2656.888 84 3
#> 2 -2805.308 82 4
#> 3 -2656.888 35 3
#> 4 -2656.888 36 3
#> 5 -2656.888 51 3
#> 6 -2656.888 37 3
#> 7 -2656.888 36 3
#> 8 -2804.821 87 4
#> 9 -2656.888 45 3
#> 10 -2656.888 39 3
#>
#> Use statusCodes() to view the meaning of each status code
#>
#> Exit Status: 3, Optimization stopped because ftol_rel or ftol_abs was reached.
#>
#> Model Type: Multinomial Logit
#> Model Space: Willingness-to-Pay
#> Model Run: 1 of 10
#> Iterations: 84
#> Elapsed Time: 0h:0m:0.07s
#> Algorithm: NLOPT_LD_LBFGS
#> Weights Used?: FALSE
#> Robust? FALSE
#>
#> Model Coefficients:
#> Estimate Std. Error z-value Pr(>|z|)
#> scalePar 0.366585 0.024366 15.0450 < 2.2e-16 ***
#> feat 1.340566 0.355864 3.7671 0.0001652 ***
#> brandhiland -10.135707 0.576078 -17.5943 < 2.2e-16 ***
#> brandweight -1.749066 0.179896 -9.7227 < 2.2e-16 ***
#> brandyoplait 2.003824 0.142377 14.0741 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Log-Likelihood: -2656.8878779
#> Null Log-Likelihood: -3343.7419990
#> AIC: 5323.7757559
#> BIC: 5352.7168000
#> McFadden R2: 0.2054148
#> Adj McFadden R2: 0.2039195
#> Number of Observations: 2412.0000000
View the estimated model coefficients:
coef(mnl_wtp)
#> scalePar feat brandhiland brandweight brandyoplait
#> 0.3665849 1.3405656 -10.1357075 -1.7490664 2.0038243
Since WTP space models are non-convex, you cannot be certain that the model reached a global solution, even when using a multi-start. However, homogeneous models in the preference space are convex, so you are guaranteed to find the global solution in that space. Therefore, it can be useful to compute the WTP from the preference space model and compare it against the WTP from the WTP space model. If the WTP values and log-likelihood values from the two model spaces are equal, then the WTP space model is likely at a global solution.
To compare the WTP and log-likelihood values between the preference
space and WTP space models, use the wtpCompare()
function:
wtpCompare(mnl_pref, mnl_wtp, scalePar = 'price')
#> pref wtp difference
#> scalePar 0.3665546 0.3665849 0.00003030
#> feat 1.3406987 1.3405656 -0.00013309
#> brandhiland -10.1362190 -10.1357075 0.00051155
#> brandweight -1.7490940 -1.7490664 0.00002759
#> brandyoplait 2.0038476 2.0038243 -0.00002336
#> logLik -2656.8878790 -2656.8878779 0.00000106