Estimating Weighted Logit Models

This vignette demonstrates an example of how to use the logitr() function with the weights argument to estimate weighted logit models.

The data

This example uses the cars_us data set from Helveston et al. (2015) containing 384 stated choice observations from US car buyers. Conjoint surveys were fielded in 2012 online in the US on Amazon Mechanical Turk and in person at the 2013 Pittsburgh Auto show. Participants were asked to select a vehicle from a set of three alternatives. Each participant answered 15 choice questions.

In the utility models described below, the data variables are represented as follows:

Symbol Variable
\(p\) The price in US dollars.
\(x_{j}^{\mathrm{hev}}\) Dummy variable for HEV vehicle type
\(x_{j}^{\mathrm{phev10}}\) Dummy variable for PHEV10 vehicle type
\(x_{j}^{\mathrm{phev20}}\) Dummy variable for PHEV20 vehicle type
\(x_{j}^{\mathrm{phev40}}\) Dummy variable for PHEV40 vehicle type
\(x_{j}^{\mathrm{bev75}}\) Dummy variable for BEV75 vehicle type
\(x_{j}^{\mathrm{bev100}}\) Dummy variable for BEV100 vehicle type
\(x_{j}^{\mathrm{bev150}}\) Dummy variable for BEV150 vehicle type
\(x_{j}^{\mathrm{phevFastcharge}}\) Dummy variable for if the PHEV has a fast charging capability
\(x_{j}^{\mathrm{bevFastcharge}}\) Dummy variable for if the BEV has a fast charging capability
\(x_{j}^{\mathrm{opCost}}\) The vehicle operating costs (cents / mile)
\(x_{j}^{\mathrm{accelTime}}\) The vehicle 0-60mph acceleration time
\(x_{j}^{\mathrm{american}}\) Dummy variable for an American brand
\(x_{j}^{\mathrm{japanese}}\) Dummy variable for a Japanese brand
\(x_{j}^{\mathrm{chinese}}\) Dummy variable for a Chinese brand
\(x_{j}^{\mathrm{skorean}}\) Dummy variable for a S. Korean brand

The utility model

In this example, we’ll estimate two versions of the following utility model in the WTP space: one without weights and one with weights. Notation is taken from Helveston et al. (2015):

\[\begin{equation} \begin{split} &u_{j} = \lambda (\\ &\omega_1 x_{j}^{\mathrm{hev}} + \omega_2 x_{j}^{\mathrm{phev10}} + \omega_3 x_{j}^{\mathrm{phev20}} + \omega_4 x_{j}^{\mathrm{phev40}} +\\ &\omega_5 x_{j}^{\mathrm{bev75}} + \omega_6 x_{j}^{\mathrm{bev100}} + \omega_7 x_{j}^{\mathrm{bev150}} +\\ &\omega_8 x_{j}^{\mathrm{phevFastcharge}} + \omega_9 x_{j}^{\mathrm{bevFastcharge}} + \omega_{10} x_{j}^{\mathrm{opCost}} + \omega_{11} x_{j}^{\mathrm{accelTime}} +\\ &\omega_{12} x_{j}^{\mathrm{american}} + \omega_{13} x_{j}^{\mathrm{japanese}} + \omega_{14} x_{j}^{\mathrm{chinese}} + \omega_{15} x_{j}^{\mathrm{skorean}} - p_{j}\\ &) +\varepsilon_{j} \end{split} \label{eq:mnlWtpCarsExample} \end{equation}\]

where all the \(\omega\) parameters have units of dollars and \(\lambda\) is the scale parameter.

Unweighted model

To estimate the model, first load the logitr package:

library(logitr)

Estimate the unweighted model using the logitr() function. In this example, I have set robust = TRUE since it will also be TRUE in the weighted model:

mnl_wtp_unweighted <- logitr(
  data   = cars_us,
  choice = 'choice',
  obsID  = 'obsnum',
  pars   = c(
    'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
    'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
    'bevFastcharge','opCost', 'accelTime'),
  price = 'price',
  modelSpace = 'wtp',
  robust = TRUE,
  # Since WTP space models are non-convex, run a multistart
  numMultiStarts = 10
)
#> Running Multistart 1 of 10...
#> 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!
summary(mnl_wtp_unweighted)
#> =================================================
#> Call:
#> logitr(data = cars_us, choice = "choice", obsID = "obsnum", pars = c("hev", 
#>     "phev10", "phev20", "phev40", "bev75", "bev100", "bev150", 
#>     "american", "japanese", "chinese", "skorean", "phevFastcharge", 
#>     "bevFastcharge", "opCost", "accelTime"), price = "price", 
#>     modelSpace = "wtp", robust = TRUE, numMultiStarts = 10)
#> 
#> Frequencies of alternatives:
#>       1       2       3 
#> 0.34323 0.33507 0.32170 
#> 
#> Summary Of Multistart Runs:
#>    Log Likelihood Iterations Exit Status
#> 1       -4616.952         26           3
#> 2       -4616.952         35           3
#> 3       -4616.952         33           3
#> 4       -4616.952         36           3
#> 5       -4616.952         30           3
#> 6       -4616.952         33           3
#> 7       -4616.952         41           3
#> 8       -4616.952         39           3
#> 9       -4616.952         32           3
#> 10      -4616.952         30           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:                7 of 10
#> Iterations:                    41
#> Elapsed Time:          0h:0m:0.3s
#> Algorithm:         NLOPT_LD_LBFGS
#> Weights Used?:              FALSE
#> Cluster ID:                obsnum
#> Robust?                      TRUE
#> 
#> Model Coefficients: 
#>                   Estimate  Std. Error  z-value  Pr(>|z|)    
#> lambda           0.0738774   0.0021928  33.6903 < 2.2e-16 ***
#> hev              0.8068105   0.9990704   0.8076 0.4193432    
#> phev10           1.1655082   1.0615103   1.0980 0.2722169    
#> phev20           1.6470398   1.0617561   1.5512 0.1208439    
#> phev40           2.5790927   1.0499387   2.4564 0.0140328 *  
#> bev75          -16.0461167   1.2541408 -12.7945 < 2.2e-16 ***
#> bev100         -13.0033544   1.2388689 -10.4962 < 2.2e-16 ***
#> bev150          -9.5726763   1.1641675  -8.2228 2.220e-16 ***
#> american         2.3435603   0.7979767   2.9369 0.0033153 ** 
#> japanese        -0.3751133   0.7998408  -0.4690 0.6390804    
#> chinese        -10.2691976   0.8859574 -11.5911 < 2.2e-16 ***
#> skorean         -6.0309966   0.8514345  -7.0833 1.407e-12 ***
#> phevFastcharge   2.8797253   0.8028932   3.5867 0.0003349 ***
#> bevFastcharge    2.9179902   0.9181378   3.1782 0.0014821 ** 
#> opCost          -1.6361119   0.0686339 -23.8382 < 2.2e-16 ***
#> accelTime       -1.6968792   0.1638076 -10.3590 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>                                      
#> Log-Likelihood:         -4616.9517823
#> Null Log-Likelihood:    -6328.0067827
#> AIC:                     9265.9035646
#> BIC:                     9372.4426000
#> McFadden R2:                0.2703940
#> Adj McFadden R2:            0.2678655
#> Number of Observations:  5760.0000000
#> Number of Clusters       5760.0000000

Weighted model

To estimate the weighted model, simply add the weights argument to the call to logitr(), referring to the column of weights that will be used to weight each choice observation. In this example, the weights used in the weights column range from 0.2 to 5:

summary(cars_us$weights)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#>  0.2000  0.2000  0.2000  0.6891  0.2000  5.0000
mnl_wtp_weighted <- logitr(
  data   = cars_us,
  choice = 'choice',
  obsID  = 'obsnum',
  pars   = c(
    'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
    'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
    'bevFastcharge','opCost', 'accelTime'),
  price = 'price',
  modelSpace = 'wtp',
  weights = 'weights', # This is the key argument for enabling weights
  robust = TRUE,
  numMultiStarts = 10
)
#> Running Multistart 1 of 10...
#> 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_weighted)
#> =================================================
#> Call:
#> logitr(data = cars_us, choice = "choice", obsID = "obsnum", pars = c("hev", 
#>     "phev10", "phev20", "phev40", "bev75", "bev100", "bev150", 
#>     "american", "japanese", "chinese", "skorean", "phevFastcharge", 
#>     "bevFastcharge", "opCost", "accelTime"), price = "price", 
#>     modelSpace = "wtp", weights = "weights", robust = TRUE, numMultiStarts = 10)
#> 
#> Frequencies of alternatives:
#>       1       2       3 
#> 0.34323 0.33507 0.32170 
#> 
#> Summary Of Multistart Runs:
#>    Log Likelihood Iterations Exit Status
#> 1       -3425.633         19           3
#> 2       -3425.630         77           3
#> 3       -3425.630         32           3
#> 4       -3425.630         36           3
#> 5       -3425.631         30           3
#> 6       -3425.630         38           3
#> 7       -3425.630         30           3
#> 8       -3425.630         34           3
#> 9       -3425.630         31           3
#> 10      -3425.630         35           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:               10 of 10
#> Iterations:                    35
#> Elapsed Time:         0h:0m:0.26s
#> Algorithm:         NLOPT_LD_LBFGS
#> Weights Used?:               TRUE
#> Cluster ID:                obsnum
#> Robust?                      TRUE
#> 
#> Model Coefficients: 
#>                   Estimate  Std. Error z-value  Pr(>|z|)    
#> lambda           0.0522811   0.0040689 12.8490 < 2.2e-16 ***
#> hev             -1.1764087   2.9132799 -0.4038 0.6863532    
#> phev10           0.0266510   3.1279789  0.0085 0.9932019    
#> phev20           1.6941283   3.0996697  0.5466 0.5846871    
#> phev40           2.6488505   2.9851295  0.8873 0.3748912    
#> bev75          -20.1366815   3.6671367 -5.4911 3.994e-08 ***
#> bev100         -19.4959042   3.6254896 -5.3775 7.555e-08 ***
#> bev150         -13.6908843   3.4926184 -3.9199 8.857e-05 ***
#> american         8.1880844   2.4052803  3.4042 0.0006636 ***
#> japanese         0.9332383   2.3603314  0.3954 0.6925592    
#> chinese        -19.0073173   2.8540077 -6.6599 2.741e-11 ***
#> skorean         -9.5100157   2.5233806 -3.7688 0.0001641 ***
#> phevFastcharge   3.9442637   2.3624064  1.6696 0.0949994 .  
#> bevFastcharge    3.3426271   2.8086447  1.1901 0.2339988    
#> opCost          -1.5975200   0.1948439 -8.1990 2.220e-16 ***
#> accelTime       -1.1717338   0.4834611 -2.4236 0.0153660 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>                                      
#> Log-Likelihood:         -3425.6302856
#> Null Log-Likelihood:    -4360.5909275
#> AIC:                     6883.2605711
#> BIC:                     6989.7997000
#> McFadden R2:                0.2144115
#> Adj McFadden R2:            0.2107422
#> Number of Observations:  5760.0000000
#> Number of Clusters       5760.0000000

Compare results

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:

data.frame(
  Unweighted = coef(mnl_wtp_unweighted),
  Weighted   = coef(mnl_wtp_weighted)
)
#>                  Unweighted     Weighted
#> lambda           0.07387743   0.05228108
#> hev              0.80681046  -1.17640867
#> phev10           1.16550815   0.02665103
#> phev20           1.64703981   1.69412832
#> phev40           2.57909274   2.64885054
#> bev75          -16.04611672 -20.13668150
#> bev100         -13.00335442 -19.49590417
#> bev150          -9.57267628 -13.69088432
#> american         2.34356027   8.18808444
#> japanese        -0.37511329   0.93323828
#> chinese        -10.26919764 -19.00731726
#> skorean         -6.03099656  -9.51001567
#> phevFastcharge   2.87972528   3.94426374
#> bevFastcharge    2.91799016   3.34262710
#> opCost          -1.63611192  -1.59752002
#> accelTime       -1.69687918  -1.17173381

Here is a comparison of the log-likelihood for the weighted and unweighted models:

c(
  "Unweighted" = mnl_wtp_unweighted$logLik,
  "Weighted" = mnl_wtp_weighted$logLik
)
#> Unweighted   Weighted 
#>  -4616.952  -3425.630

References

Helveston, John Paul, Yimin Liu, Eleanor Mcdonnell Feit, Erica R. H. Fuchs, Erica Klampfl, and Jeremy J. Michalek. 2015. Will Subsidies Drive Electric Vehicle Adoption? Measuring Consumer Preferences in the U.S. and China.” Transportation Research Part A: Policy and Practice 73: 96–112. https://doi.org/10.1016/j.tra.2015.01.002.