# 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

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         35           3
#> 3       -4616.952         34           3
#> 4       -4616.952         39           3
#> 5       -4616.952         34           3
#> 6       -4616.952         32           3
#> 7       -4616.952         29           3
#> 8       -4616.952         37           3
#> 9       -4616.952         36           3
#> 10      -4616.952         29           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:                    29
#> Elapsed Time:          0h:0m:0.2s
#> 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.086744  0.8517   0.3944
#> hev              0.806621   1.265764  0.6373   0.5240
#> phev10           1.166184   1.659620  0.7027   0.4823
#> phev20           1.647799   2.175965  0.7573   0.4489
#> phev40           2.579862   2.598669  0.9928   0.3208
#> bev75          -16.046949  13.974825 -1.1483   0.2509
#> bev100         -13.003583  11.297217 -1.1510   0.2497
#> bev150          -9.573957   8.179314 -1.1705   0.2418
#> american         2.344231   1.647315  1.4231   0.1547
#> japanese        -0.374587   1.270317 -0.2949   0.7681
#> chinese        -10.268774   9.786305 -1.0493   0.2940
#> skorean         -6.030943   5.634857 -1.0703   0.2845
#> phevFastcharge   2.878852   2.453859  1.1732   0.2407
#> bevFastcharge    2.919100   2.150728  1.3573   0.1747
#> opCost          -1.636062   1.844096 -0.8872   0.3750
#> accelTime       -1.697051   1.737777 -0.9766   0.3288
#>
#> Log-Likelihood:         -4616.9517794
#> Null Log-Likelihood:    -6328.0067827
#> AIC:                     9265.9035589
#> BIC:                     9372.4426000
#> Number of Clusters       5760.0000000
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 30 3 #> 3 -3425.630 33 3 #> 4 -3425.630 32 3 #> 5 -3425.630 31 3 #> 6 -3425.631 30 3 #> 7 -3425.630 32 3 #> 8 -3425.631 26 3 #> 9 -3425.630 33 3 #> 10 -3425.630 32 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: 3 of 10 #> Iterations: 33 #> Elapsed Time: 0h:0m:0.24s #> Algorithm: NLOPT_LD_LBFGS #> Weights Used?: TRUE #> Cluster ID: obsnum #> Robust? TRUE #> #> Model Coefficients: #> Estimate Std. Error z-value Pr(>|z|) #> lambda 0.052284 0.185883 0.2813 0.7785 #> hev -1.175868 5.401998 -0.2177 0.8277 #> phev10 0.028264 5.440590 0.0052 0.9959 #> phev20 1.695843 9.811486 0.1728 0.8628 #> phev40 2.650509 10.230222 0.2591 0.7956 #> bev75 -20.136602 52.384588 -0.3844 0.7007 #> bev100 -19.497217 50.963941 -0.3826 0.7020 #> bev150 -13.692313 40.059932 -0.3418 0.7325 #> american 8.185484 21.329910 0.3838 0.7012 #> japanese 0.934638 3.385319 0.2761 0.7825 #> chinese -19.008104 59.417321 -0.3199 0.7490 #> skorean -9.509561 30.637850 -0.3104 0.7563 #> phevFastcharge 3.944094 13.849371 0.2848 0.7758 #> bevFastcharge 3.343823 8.767533 0.3814 0.7029 #> opCost -1.597516 5.560861 -0.2873 0.7739 #> accelTime -1.171739 4.368629 -0.2682 0.7885 #> #> Log-Likelihood: -3425.6302910 #> Null Log-Likelihood: -4360.5909275 #> AIC: 6883.2605821 #> 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.07387833 0.05228367 #> hev 0.80662120 -1.17586755 #> phev10 1.16618412 0.02826435 #> phev20 1.64779897 1.69584283 #> phev40 2.57986245 2.65050920 #> bev75 -16.04694918 -20.13660244 #> bev100 -13.00358333 -19.49721667 #> bev150 -9.57395662 -13.69231272 #> american 2.34423108 8.18548420 #> japanese -0.37458651 0.93463770 #> chinese -10.26877410 -19.00810384 #> skorean -6.03094345 -9.50956120 #> phevFastcharge 2.87885233 3.94409429 #> bevFastcharge 2.91910049 3.34382338 #> opCost -1.63606241 -1.59751642 #> accelTime -1.69705050 -1.17173907 Here is a comparison of the log-likelihood for the weighted and unweighted models: c( "Unweighted" = mnl_wtp_unweighted$logLik,
#>  -4616.952  -3425.630