knitr::opts_chunk$set( collapse = TRUE, warning = FALSE, message = FALSE, fig.retina = 3, comment = "#>" )
This vignette demonstrates an example of how to use the logitr()
function with the weights
argument to estimate weighted logit models.
In the utility models described below, the data variables are represented as follows:
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. [-@Helveston2015]:
where all the $\omega$ parameters have units of dollars and $\lambda$ is the scale parameter.
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)
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) 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)
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) )
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 )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.