[R] “Error in if (abs(x - oldx) < ftol)” when using “lognormal” distribution in mixed logit

Henric Winell nilsson.henric at gmail.com
Fri Jul 24 13:16:27 CEST 2015


Den 2015-07-24 kl. 00:33, skrev Dera:

> Hi, 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.

I've never used the 'mlogit' package but that error message has likely 
nothing to do with missingness in your data.

The error message is pretty clear: for some reason 'if (abs(x - oldx) < 
ftol)', which looks like a check for convergence, doesn't evaluate to 
TRUE or FALSE as expected.  Perhaps due to the warning message about 
problems with NaN in the starting values?  Have you checked your data? 
That warning message is typical for when you try to take logs of a 
negative number:

 > log(-1)
[1] NaN
Warning message:
In log(-1) : NaNs produced

Unless this helps you identify the problem, we need a (preferably small) 
reproducible example demonstrating the issue to be able to provide 
further help.

BTW, have you asked the package maintainer (as per the posting guide)?


Henric Winell



>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Error-in-if-abs-x-oldx-ftol-when-using-lognormal-distribution-in-mixed-logit-tp4710284.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list