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 |
---|---|
\(p\) | The price in US dollars. |
\(x_{j}^{\mathrm{Feat}}\) | Dummy variable for whether the newspaper advertisement was shown to the customer. |
\(x_{j}^{\mathrm{Hiland}}\) | Dummy variable for the “Highland” brand. |
\(x_{j}^{\mathrm{Yoplait}}\) | Dummy variable for the “Yoplait” brand. |
\(x_{j}^{\mathrm{Dannon}}\) | Dummy variable for the “Dannon” brand. |
This example will estimate the following homogeneous multinomial logit model in the preference space:
\[\begin{equation} u_{j} = \alpha p_{j} + \beta_1 x_{j}^{\mathrm{Feat}} + \beta_2 x_{j}^{\mathrm{Hiland}} + \beta_3 x_{j}^{\mathrm{Yoplait}} + \beta_4 x_{j}^{\mathrm{Dannon}} + \varepsilon_{j} \label{eq:mnlPrefExample} \end{equation}\]
where the parameters \(\alpha\), \(\beta_1\), \(\beta_2\), \(\beta_3\), and \(\beta_4\) have units of utility.
To estimate the model, first load the logitr package:
library(logitr)
Estimate the model using the logitr()
function:
<- logitr(
mnl_pref data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('price', 'feat', 'brand')
)
#> Running Model...
#> Done!
Print a summary of the results:
summary(mnl_pref)
#> =================================================
#> MODEL SUMMARY:
#>
#> Model Space: Preference
#> Model Run: 1 of 1
#> Iterations: 21
#> Elapsed Time: 0h:0m:0.13s
#> Exit Status: 3
#> Weights Used?: FALSE
#> robust? FALSE
#>
#> Model Coefficients:
#> Estimate StdError tStat pVal signif
#> price -0.366543 0.024365 -15.0439 0 ***
#> feat 0.491433 0.120061 4.0932 0 ***
#> brandhiland -3.715428 0.145416 -25.5504 0 ***
#> brandweight -0.641128 0.054498 -11.7643 0 ***
#> brandyoplait 0.734496 0.080642 9.1082 0 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Model Fit Values:
#>
#> Log-Likelihood: -2656.8878799
#> Null Log-Likelihood: -3343.7419990
#> AIC: 5323.7758000
#> 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.3665429 0.4914329 -3.7154279 -0.6411280 0.7344962
Compute the WTP implied from the preference space model:
<- wtp(mnl_pref, priceName = "price") wtp_mnl_pref
wtp_mnl_pref#> Estimate StdError tStat pVal signif
#> lambda 0.366543 0.024471 14.9786 0e+00 ***
#> feat 1.340724 0.360552 3.7185 2e-04 ***
#> brandhiland -10.136406 0.585214 -17.3209 0e+00 ***
#> brandweight -1.749121 0.181712 -9.6258 0e+00 ***
#> brandyoplait 2.003848 0.143493 13.9647 0e+00 ***
This example will estimate the following homogeneous multinomial logit model in the WTP space:
\[\begin{equation} u_{j} = \lambda ( \omega_1 x_{j}^{\mathrm{Feat}} + \omega_2 x_{j}^{\mathrm{Hiland}} + \omega_3 x_{j}^{\mathrm{Yoplait}} + \omega_4 x_{j}^{\mathrm{Dannon}} - p_{j}) + \varepsilon_{j} \label{eq:mnlWtpExample} \end{equation}\]
where the parameters \(\omega_1\), \(\omega_2\), \(\omega_3\), and \(\omega_4\) have units of dollars and \(\lambda\) is the scale parameter.
Estimate the model using the logitr()
function:
<- logitr(
mnl_wtp data = yogurt,
choiceName = 'choice',
obsIDName = 'obsID',
parNames = c('feat', 'brand'),
priceName = 'price',
modelSpace = 'wtp',
options = list(
# Since WTP space models are non-convex, run a multistart:
numMultiStarts = 10,
# If you want to view the results from each multistart run,
# set keepAllRuns=TRUE:
keepAllRuns = TRUE,
# Use the computed WTP from the preference space model as the starting
# values for the first run:
startVals = wtp_mnl_pref$Estimate)
)
#> Running Multistart 1 of 10...
#> NOTE: Using user-provided starting values for this run
#> Running Multistart 2 of 10...
#> Running Multistart 3 of 10...
#> Running Multistart 4 of 10...
#> Running Multistart 5 of 10...
#> Running Multistart 6 of 10...
#> Running Multistart 7 of 10...
#> Running Multistart 8 of 10...
#> Running Multistart 9 of 10...
#> Running Multistart 10 of 10...
#> Done!
Print a summary of the results:
summary(mnl_wtp)
#> =================================================
#> SUMMARY OF ALL MULTISTART RUNS:
#>
#> run logLik iterations status
#> 1 1 -2656.888 48 3
#> 2 2 -2656.888 45 3
#> 3 3 -2803.817 71 3
#> 4 4 -2656.888 36 3
#> 5 5 -2656.888 37 3
#> 6 6 -2803.795 89 3
#> 7 7 -2656.888 39 3
#> 8 8 -2804.379 89 3
#> 9 9 -2803.827 94 3
#> 10 10 -2656.888 43 3
#> ---
#> Use statusCodes() to view the meaning of the status codes
#>
#> Below is the summary of run 10 of 10 multistart runs
#> (the run with the largest log-likelihood value)
#> =================================================
#> MODEL SUMMARY:
#>
#> Model Space: Willingness-to-Pay
#> Model Run: 10 of 10
#> Iterations: 43
#> Elapsed Time: 0h:0m:0.23s
#> Exit Status: 3
#> Weights Used?: FALSE
#> robust? FALSE
#>
#> Model Coefficients:
#> Estimate StdError tStat pVal signif
#> lambda 0.366585 0.024366 15.0449 0e+00 ***
#> feat 1.340571 0.355864 3.7671 2e-04 ***
#> brandhiland -10.135735 0.576086 -17.5941 0e+00 ***
#> brandweight -1.749063 0.179896 -9.7227 0e+00 ***
#> brandyoplait 2.003818 0.142377 14.0740 0e+00 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Model Fit Values:
#>
#> Log-Likelihood: -2656.8878779
#> Null Log-Likelihood: -3343.7419990
#> AIC: 5323.7758000
#> 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)
#> lambda feat brandhiland brandweight brandyoplait
#> 0.3665854 1.3405708 -10.1357346 -1.7490629 2.0038178
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, priceName = 'price') wtp_mnl_comparison
wtp_mnl_comparison#> pref wtp difference
#> lambda 0.366543 0.3665854 0.00004238
#> feat 1.340724 1.3405708 -0.00015315
#> brandhiland -10.136406 -10.1357346 0.00067139
#> brandweight -1.749121 -1.7490629 0.00005807
#> brandyoplait 2.003848 2.0038178 -0.00003018
#> logLik -2656.887880 -2656.8878779 0.00000194