jhelvy / logitr

Fast estimation of multinomial (MNL) and mixed logit (MXL) models in R with "Preference" space or "Willingness-to-pay" (WTP) space utility parameterizations in R
https://jhelvy.github.io/logitr/
Other
43 stars 15 forks source link

WTP estimation with "brand" dummies #59

Open jonah-allen opened 1 week ago

jonah-allen commented 1 week ago

Hi John,

It’s me again—now running into a quirk implementing dummies. I currently have two dummy columns, crop_change and tech_change. These are analogous to the yogurt brands in your example, as each respondent receives three options in their survey question: no change, a cropping change, or a technology change to the farm. Here’s a snapshot of the data:

wtp_risk

# A tibble: 180 × 12
   version  risk loss_value id      original_choice Policy alt   choice obsID clusterID crop_change
   <fct>   <dbl>      <dbl> <chr>   <fct>            <dbl> <fct>  <dbl> <int>     <int>       <dbl>
 1 CO1         8         0  R_bf8T… c                    0 a          0    53         1           0
 2 CO1         4       113. R_bf8T… c                    0 b          0    53         1           1
 3 CO1         4       113. R_bf8T… c                    0 c          1    53         1           0
 4 CO1         8         0  R_2tnw… a                    0 a          1    27         1           0
 5 CO1         4       113. R_2tnw… a                    0 b          0    27         1           1
 6 CO1         4       113. R_2tnw… a                    0 c          0    27         1           0
 7 CO1         8         0  R_2S9c… c                    0 a          0    17         1           0
 8 CO1         4       113. R_2S9c… c                    0 b          0    17         1           1
 9 CO1         4       113. R_2S9c… c                    0 c          1    17         1           0
10 CO1         8         0  R_31F6… a                    0 a          1    29         1           0
# ℹ 170 more rows
# ℹ 1 more variable: tech_change <dbl>
# ℹ Use `print(n = ...)` to see more rows

Observations and Issues

  1. NaNs in WTP Estimation When estimating WTP directly, I get the following warning:
Warning message: In sqrt(diag(stats::vcov(object))) : NaNs produced

And the model output is:

mnl_wtp <- logitr(
  data = wtp_risk, 
  outcome = "choice",
  obsID = "obsID", 
  pars = c("risk", "tech_change", "crop_change"),
  scalePar = "loss_value",
  options = list(numMultiStarts = 10) # ensures global solution
)

Model Coefficients: 
              Estimate Std. Error z-value            Pr(>|z|)    
scalePar      0.010608   0.010107  1.0496              0.2939    
risk        -10.505535   1.141731 -9.2014 <0.0000000000000002 ***
sd_scalePar  -0.050373        NaN     NaN                 NaN 

I suspect this issue might be due to the small data size (60 observations). However, the problem does not occur during preference-space estimation.

  1. Large Standard Errors in WTP Estimation The standard errors for WTP estimation are very large, regardless of whether clustering is applied. Example output:
mnl_pref <- logitr(
  data = wtp_risk, 
  outcome = "choice",
  obsID = "obsID", 
  pars = c("loss_value", "risk", "crop_change", "tech_change")
)

wtp(mnl_pref, scalePar = "loss_value")
                  Estimate    Std. Error z-value Pr(>|z|)  
scalePar          0.0083484     0.0048013  1.7388  0.08208 .
risk            -25.6952811  7150.6716715 -0.0036  0.99713  
crop_change    -142.2892161 51064.3296005 -0.0028  0.99778  
tech_change     -80.8290757 43298.7631545 -0.0019  0.99851 
  1. Differences Between WTP Estimation Methods WTP estimates differ substantially between direct estimation and preference-space estimation. Additionally, the dummy variables (crop_change and tech_change) do not appear in the direct WTP estimation, though this is probably expected. The direct estimation is the same as the results (on both approaches) without "brand" dummies.

I also tested the results with only only one dummy (tech_change), and the issues persist,

Questions

•   Could the NaNs issue be entirely due to the small data size, or might there be something else at play?
•   What might explain the large standard errors in the WTP estimation, even when clustering isn’t applied?
•   Is the difference between WTP estimation methods expected, or might it indicate an implementation issue?

Please let me know if you’d like a portion of my data to replicate these issues. Once again, thank you for this incredibly useful package!

Best, Jonah

jhelvy commented 12 hours ago

This is almost certainly because the model is converging to a local minimum. What is the log-likelihood of the WTP space model, and what is it for the preference space model? A preference space MNL model has a convex log-likelihood function, so it will always converge to the global minimum. You can use this to compare - your WTP space LL should be the same. If it's not then you need to keep searching.

It also looks like you're using the outdata API for specifying multi-starts. It should be this (here I'm using 100 starts to search a broader space):

mnl_wtp <- logitr(
  data = wtp_risk, 
  outcome = "choice",
  obsID = "obsID", 
  pars = c("risk", "tech_change", "crop_change"),
  scalePar = "loss_value",
  numMultiStarts = 100
)