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.
xjhev Dummy variable for HEV vehicle type
xjphev10 Dummy variable for PHEV10 vehicle type
xjphev20 Dummy variable for PHEV20 vehicle type
xjphev40 Dummy variable for PHEV40 vehicle type
xjbev75 Dummy variable for BEV75 vehicle type
xjbev100 Dummy variable for BEV100 vehicle type
xjbev150 Dummy variable for BEV150 vehicle type
xjphevFastcharge Dummy variable for if the PHEV has a fast charging capability
xjbevFastcharge Dummy variable for if the BEV has a fast charging capability
xjopCost The vehicle operating costs (cents / mile)
xjaccelTime The vehicle 0-60mph acceleration time
xjamerican Dummy variable for an American brand
xjjapanese Dummy variable for a Japanese brand
xjchinese Dummy variable for a Chinese brand
xjskorean 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):

where all the ω parameters have units of dollars and λ 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,
  outcome = 'choice',
  obsID   = 'obsnum',
  pars    = c(
    'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
    'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
    'bevFastcharge','opCost', 'accelTime'),
  scalePar   = 'price',
  robust     = TRUE,
  # Since WTP space models are non-convex, run a multistart
  numMultiStarts = 10
)

Print a summary of the results:

summary(mnl_wtp_unweighted)
#> =================================================
#> 
#> Model estimated on: Fri Nov 01 08:44:14 PM 2024 
#> 
#> Using logitr version: 1.1.2 
#> 
#> Call:
#> logitr(data = cars_us, outcome = "choice", obsID = "obsnum", 
#>     pars = c("hev", "phev10", "phev20", "phev40", "bev75", "bev100", 
#>         "bev150", "american", "japanese", "chinese", "skorean", 
#>         "phevFastcharge", "bevFastcharge", "opCost", "accelTime"), 
#>     scalePar = "price", 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         34           3
#> 3       -4616.952         32           3
#> 4       -4616.952         31           3
#> 5       -4616.952         37           3
#> 6       -4616.952         49           3
#> 7       -4616.952         31           3
#> 8       -4616.952         43           3
#> 9       -4616.952         37           3
#> 10      -4616.952         31           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:                5 of 10
#> Iterations:                    37
#> Elapsed Time:         0h:0m:0.45s
#> Algorithm:         NLOPT_LD_LBFGS
#> Weights Used?:              FALSE
#> Cluster ID:                obsnum
#> Robust?                      TRUE
#> 
#> Model Coefficients: 
#>                   Estimate  Std. Error  z-value  Pr(>|z|)    
#> scalePar         0.0738786   0.0021929  33.6895 < 2.2e-16 ***
#> hev              0.8065397   0.9990614   0.8073  0.419495    
#> phev10           1.1657364   1.0614989   1.0982  0.272118    
#> phev20           1.6474014   1.0617448   1.5516  0.120758    
#> phev40           2.5795258   1.0499275   2.4569  0.014016 *  
#> bev75          -16.0466921   1.2541522 -12.7949 < 2.2e-16 ***
#> bev100         -13.0039544   1.2388737 -10.4966 < 2.2e-16 ***
#> bev150          -9.5737796   1.1641845  -8.2236  2.22e-16 ***
#> american         2.3444015   0.7979726   2.9379  0.003304 ** 
#> japanese        -0.3743637   0.7998322  -0.4681  0.639747    
#> chinese        -10.2685079   0.8859402 -11.5905 < 2.2e-16 ***
#> skorean         -6.0306837   0.8514284  -7.0830  1.41e-12 ***
#> phevFastcharge   2.8789794   0.8028802   3.5858  0.000336 ***
#> bevFastcharge    2.9194001   0.9181366   3.1797  0.001474 ** 
#> opCost          -1.6360850   0.0686333 -23.8381 < 2.2e-16 ***
#> accelTime       -1.6970764   0.1638104 -10.3600 < 2.2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>                                      
#> Log-Likelihood:         -4616.9517800
#> Null Log-Likelihood:    -6328.0067827
#> AIC:                     9265.9035600
#> 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,
  outcome = 'choice',
  obsID   = 'obsnum',
  pars    = c(
    'hev', 'phev10', 'phev20', 'phev40', 'bev75', 'bev100', 'bev150',
    'american', 'japanese', 'chinese', 'skorean', 'phevFastcharge',
    'bevFastcharge','opCost', 'accelTime'),
  scalePar = 'price',
  weights  = 'weights', # This enables the weights
  robust   = TRUE,
  numMultiStarts = 10
)

Print a summary of the results:

summary(mnl_wtp_weighted)
#> =================================================
#> 
#> Model estimated on: Fri Nov 01 08:44:17 PM 2024 
#> 
#> Using logitr version: 1.1.2 
#> 
#> Call:
#> logitr(data = cars_us, outcome = "choice", obsID = "obsnum", 
#>     pars = c("hev", "phev10", "phev20", "phev40", "bev75", "bev100", 
#>         "bev150", "american", "japanese", "chinese", "skorean", 
#>         "phevFastcharge", "bevFastcharge", "opCost", "accelTime"), 
#>     scalePar = "price", 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         33           3
#> 3       -3425.630         27           3
#> 4       -3425.630         29           3
#> 5       -3425.630         41           3
#> 6       -3425.631         28           3
#> 7       -3425.630         34           3
#> 8       -3425.630         29           3
#> 9       -3425.631         30           3
#> 10      -3425.630         54           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:                    34
#> Elapsed Time:         0h:0m:0.31s
#> Algorithm:         NLOPT_LD_LBFGS
#> Weights Used?:               TRUE
#> Cluster ID:                obsnum
#> Robust?                      TRUE
#> 
#> Model Coefficients: 
#>                   Estimate  Std. Error z-value  Pr(>|z|)    
#> scalePar         0.0522813   0.0040705 12.8438 < 2.2e-16 ***
#> hev             -1.1770882   2.9133463 -0.4040 0.6861884    
#> phev10           0.0236398   3.1280863  0.0076 0.9939702    
#> phev20           1.6921068   3.0997393  0.5459 0.5851437    
#> phev40           2.6467438   2.9851657  0.8866 0.3752770    
#> bev75          -20.1392200   3.6675739 -5.4912 3.993e-08 ***
#> bev100         -19.4986760   3.6258751 -5.3776 7.547e-08 ***
#> bev150         -13.6927275   3.4929007 -3.9202 8.849e-05 ***
#> american         8.1886230   2.4053972  3.4043 0.0006634 ***
#> japanese         0.9328830   2.3604002  0.3952 0.6926788    
#> chinese        -19.0104675   2.8546662 -6.6594 2.749e-11 ***
#> skorean         -9.5124220   2.5236795 -3.7693 0.0001637 ***
#> phevFastcharge   3.9477847   2.3626244  1.6709 0.0947351 .  
#> bevFastcharge    3.3423981   2.8087638  1.1900 0.2340507    
#> opCost          -1.5977284   0.1948958 -8.1979 2.220e-16 ***
#> accelTime       -1.1720447   0.4834954 -2.4241 0.0153461 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>                                      
#> Log-Likelihood:         -3425.6302977
#> Null Log-Likelihood:    -4360.5909275
#> AIC:                     6883.2605953
#> 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
#> scalePar         0.07387864   0.05228126
#> hev              0.80653971  -1.17708825
#> phev10           1.16573636   0.02363980
#> phev20           1.64740143   1.69210675
#> phev40           2.57952581   2.64674383
#> bev75          -16.04669207 -20.13922002
#> bev100         -13.00395436 -19.49867598
#> bev150          -9.57377957 -13.69272750
#> american         2.34440151   8.18862304
#> japanese        -0.37436373   0.93288303
#> chinese        -10.26850790 -19.01046749
#> skorean         -6.03068374  -9.51242197
#> phevFastcharge   2.87897942   3.94778466
#> bevFastcharge    2.91940008   3.34239811
#> opCost          -1.63608499  -1.59772840
#> accelTime       -1.69707643  -1.17204475

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.