# 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{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}$$$

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

# Unweighted model

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:

library("logitr")

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
)

Print a summary of the results:

summary(mnl_wtp_unweighted)
#> =================================================
#> Call:
#> logitr(data = cars_us, 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, choice = "choice")
#>
#> 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         30           3
#> 3       -4616.952         31           3
#> 4       -4616.952         34           3
#> 5       -4616.952         36           3
#> 6       -4616.952         31           3
#> 7       -4616.952         36           3
#> 8       -4616.952         30           3
#> 9       -4616.952         37           3
#> 10      -4616.952         33           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:                4 of 10
#> Iterations:                    34
#> Elapsed Time:         0h:0m:0.27s
#> Algorithm:         NLOPT_LD_LBFGS
#> Weights Used?:              FALSE
#> Cluster ID:                obsnum
#> Robust?                      TRUE
#>
#> Model Coefficients:
#>                  Estimate Std. Error z-value Pr(>|z|)
#> lambda           0.073878   0.086743  0.8517   0.3944
#> hev              0.806265   1.265897  0.6369   0.5242
#> phev10           1.166364   1.659837  0.7027   0.4822
#> phev20           1.648138   2.176476  0.7573   0.4489
#> phev40           2.580016   2.598904  0.9927   0.3208
#> bev75          -16.046659  13.974054 -1.1483   0.2508
#> bev100         -13.003932  11.297783 -1.1510   0.2497
#> bev150          -9.574449   8.180213 -1.1704   0.2418
#> american         2.344207   1.647268  1.4231   0.1547
#> japanese        -0.374974   1.270779 -0.2951   0.7679
#> chinese        -10.268904   9.786426 -1.0493   0.2940
#> skorean         -6.031561   5.636011 -1.0702   0.2845
#> phevFastcharge   2.879086   2.454254  1.1731   0.2408
#> bevFastcharge    2.919025   2.150587  1.3573   0.1747
#> opCost          -1.636038   1.844037 -0.8872   0.3750
#> accelTime       -1.697021   1.737714 -0.9766   0.3288
#>
#> Log-Likelihood:         -4616.9517805
#> Null Log-Likelihood:    -6328.0067827
#> AIC:                     9265.9035610
#> BIC:                     9372.4426000
#> 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 ) Print a summary of the results: summary(mnl_wtp_weighted) #> ================================================= #> Call: #> logitr(data = cars_us, 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, #> choice = "choice") #> #> 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 29 3 #> 3 -3425.630 34 3 #> 4 -3425.630 30 3 #> 5 -3425.630 28 3 #> 6 -3425.630 33 3 #> 7 -3425.630 33 3 #> 8 -3425.630 31 3 #> 9 -3425.630 32 3 #> 10 -3425.630 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: 33 #> Elapsed Time: 0h:0m:0.27s #> Algorithm: NLOPT_LD_LBFGS #> Weights Used?: TRUE #> Cluster ID: obsnum #> Robust? TRUE #> #> Model Coefficients: #> Estimate Std. Error z-value Pr(>|z|) #> lambda 0.052281 0.185824 0.2813 0.7784 #> hev -1.177247 5.407398 -0.2177 0.8277 #> phev10 0.027019 5.434982 0.0050 0.9960 #> phev20 1.694261 9.799627 0.1729 0.8627 #> phev40 2.648828 10.218173 0.2592 0.7955 #> bev75 -20.137602 52.375758 -0.3845 0.7006 #> bev100 -19.497457 50.950456 -0.3827 0.7020 #> bev150 -13.692384 40.048567 -0.3419 0.7324 #> american 8.183664 21.312242 0.3840 0.7010 #> japanese 0.931731 3.376466 0.2759 0.7826 #> chinese -19.008667 59.402781 -0.3200 0.7490 #> skorean -9.512281 30.646213 -0.3104 0.7563 #> phevFastcharge 3.942576 13.835920 0.2850 0.7757 #> bevFastcharge 3.344391 8.768913 0.3814 0.7029 #> opCost -1.597425 5.559116 -0.2874 0.7738 #> accelTime -1.171726 4.367804 -0.2683 0.7885 #> #> Log-Likelihood: -3425.6302924 #> Null Log-Likelihood: -4360.5909275 #> AIC: 6883.2605847 #> 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.0738776 0.05228086 #> hev 0.8062652 -1.17724655 #> phev10 1.1663642 0.02701852 #> phev20 1.6481383 1.69426073 #> phev40 2.5800158 2.64882834 #> bev75 -16.0466588 -20.13760189 #> bev100 -13.0039320 -19.49745677 #> bev150 -9.5744492 -13.69238365 #> american 2.3442073 8.18366397 #> japanese -0.3749741 0.93173122 #> chinese -10.2689043 -19.00866681 #> skorean -6.0315614 -9.51228141 #> phevFastcharge 2.8790864 3.94257610 #> bevFastcharge 2.9190249 3.34439143 #> opCost -1.6360382 -1.59742522 #> accelTime -1.6970214 -1.17172604 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.