0

I have a question about how to use the mlogit package in R to do analysis of discrete choice survey data. Our survey is about asking people to choose from different insurance policies(with two attributes of deductible and premium).

The code I used to fit mixed logit is:

[1] ml <- mlogit.data (mydata, choice="choice", shape = "wide", id = "individual", 
               opposite =c ('deductible', 'premium'),varying = 5:10)

[2] ml.w5 <- mlogit (choice~deductible+premium|0, ml, panel = TRUE, 
             rpar = c(deductible='ln', premium='ln'), 
             R = 100, halton = NA, print.level=0)

I try to use lognormal because we hope the coefficients for both deductible and premium are negative. And I use "opposite" in [1] to reverse the sign because lognormal is always positive.

But I always get the error warning:

"Error in if (abs(x - oldx) < ftol) { : missing value where TRUE/FALSE needed
In addition: Warning message: In log(start[ln]) : NaNs produced"

I double check the data and am sure there isn't any missing data. And if I change the lognormal "ln" to "n" or "cn", it will work without any warning.

Does anyone know how to deal with this? Thank you for your help.

mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
Dera
  • 1
  • 3
  • Post output of `str(mydata)` .... as an edit to the question .... not as a comment. – IRTFM Jul 23 '15 at 23:35
  • The error message makes me suspect that, in spite of the use of "opposite", you are somewhere attempting to take the logarithm of a negative number. If `x` is negative `ln(x)` will produce NaN. Maybe you could test this by checking the result of `any(c(mydata$deductible, mydata$premium) < 0)`. A similar problem occurs if any entry is equal to zero. Then you have `ln(0)` equal to `-Inf`, which is not much more useful than NaN. – RHertel Jul 24 '15 at 05:47
  • @RHertel, Thank you so much! Yeah, I should have noticed this earlier. It is because our survey allowed people to choose neither of the choices we gave, so we added a choice "Neither" with both deductible and premium being 0, which caused this problem. I tried to delete the "0" entries just now and it worked! Thank you and I think I need to find a way do deal with the "Neither" choice in another way. – Dera Jul 24 '15 at 22:23

0 Answers0