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

missing z-value in logitr of preference space model #55

Closed miaejeong630 closed 7 months ago

miaejeong630 commented 8 months ago

Hi I'm Researcher who had studied on choice experiment of green infrastructure at South Korea. when I found R package of 'logitr', I'm very excited on estimating model of WTP and preference. Now, I'm suffered from this error of z-value missing. How coud I figure out the errors in my data and code? `` A tibble: 1,498 × 19 id idx Q8tt price choice alt age reg

1 1 1127 0 5000 0 1 3 7 2 1 1127 0 2000 1 2 3 7 3 2 412 0 5000 0 1 4 2 4 2 412 0 1000 1 2 4 2 5 3 418 0 5000 0 1 4 2 6 3 418 0 1000 1 2 4 2 7 4 410 0 5000 0 1 5 7 8 4 410 0 1000 1 2 5 7 9 5 218 0 5000 0 1 3 4 10 5 218 0 2000 1 2 3 4 11 more variables: edu , mar , bud , tran , time , area , satis , fee , gar , gre , act `` Using logitr version: 1.1.1 Call: logitr(data = wtp2.7, outcome = "choice", obsID = "id", pars = c("price", "age", "edu", "bud", "act", "gar", "gre")) Frequencies of alternatives: 1 2 0.5514 0.4486 Exit Status: 3, Optimization stopped because ftol_rel or ftol_abs was reached. Model Type: Multinomial Logit Model Space: Preference Model Run: 1 of 1 Iterations: 25 Elapsed Time: 0h:0m:0.02s Algorithm: NLOPT_LD_LBFGS Weights Used?: FALSE Robust? FALSE Model Coefficients: Estimate Std. Error z-value Pr(>|z|) price -0.00051319 NA NA NA age 0.00000000 NA NA NA edu 24.90583872 NA NA NA bud 0.25813579 NA NA NA act -6.32432679 NA NA NA gar 0.00000000 NA NA NA gre 14.52830879 NA NA NA Log-Likelihood: -261.2535918 Null Log-Likelihood: -519.1672382 AIC: 536.5071836 BIC: 568.8384000 McFadden R2: 0.4967834 Adj McFadden R2: 0.4833002 Number of Observations: 749.0000000
jhelvy commented 8 months ago

can you provide me more information? It looks like you have your data formatted correctly but perhaps are not providing the appropriate arguments to the logitr() function. It would help if you posted the first 6 rows of your dataset (all of the columns, so I can see what variables you have). Also see here: https://jhelvy.github.io/logitr/articles/basic_usage.html#data-format

miaejeong630 commented 7 months ago

Thank you for your response. I am grateful that your package makes it easy to do analysis. I did include the part about obsID as you suggested, but it still didn't produce a z-value. I also read the data formatting paper you suggested. However, the coefficients are calculated, but the z-value is not, and the final WTP modeling does not proceed. First, the preference model results are shown below.

`mnl_pref<-logitr(`
`` data = wtpt3.1,
`` outcome = 'choice',
 `obsID` = 'id',
 pars = c('price','age','edu') )'

Running model... Done!`

<results>

> Model Coefficients:

Estimate Std. Error z-value Pr(>|z|)
price -0.00051319 NA NA NA
age 0.00000000 NA NA NA
edu 24.90583872 NA NA NA
bud 0.25813579 NA NA NA
act -6.32432679 NA NA NA
gar 0.00000000 NA NA NA
gre 14.52830879 NA NA NA

Log-Likelihood: -261.2535918
Null Log-Likelihood: -519.1672382
AIC: 536.5071836
BIC: 568.8384000
McFadden R2: 0.4967834
Adj McFadden R2: 0.4833002
Number of Observations: 749.0000000

data formatting are as belown

> # A tibble: 1,498 × 13

      id   idx  Q8tt price choice   alt   age   edu   bud satis   gar   gre   act
   <dbl> <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
 1     1  1127     0  5000      0     1     3     4     4     3     2     1     2
 2     1  1127     0  2000      1     2     3     4     4     3     2     1     2
 3     2   412     0  5000      0     1     4     3     4     3     1     1     1
 4     2   412     0  1000      1     2     4     3     4     3     1     1     1
 5     3   418     0  5000      0     1     4     4     8     3     1     1     1
 6     3   418     0  1000      1     2     4     4     8     3     1     1     1
 7     4   410     0  5000      0     1     5     3     2     3     2     1     2
 8     4   410     0  1000      1     2     5     3     2     3     2     1     2
 9     5   218     0  5000      0     1     3     3     4     4     2     1     1
10     5   218     0  2000      1     2     3     3     4     4     2     1     1
WTP Model results are as below
'wtp(mnl_pref, scalePar = 'price')

Error` in eigen(S, symmetric = TRUE) : infinite or missing values in 'x'

is there a problem on my data such as shortage of alternative, variety of covariance, price data? or other things? How could I fix this? please help. Thanks so much..

Sincerely

Miae Jeong

jhelvy commented 7 months ago

Usually when you have NAs like this, it means your model is not properly specified. It is likely that one or more of your variables are perfectly or highly correlated. I would start by estimating as simple a model as you can, maybe with just one parameter like price and see if you get reasonable results. Then add more and you'll see which variables are problematic. You could also just look at the correlations between variables and see the ones that are highly correlated. Finally, it looks like in many of these variables there is no variation within a feature. gre for example looks like it might be 1 for the whole dataset?

miaejeong630 commented 7 months ago

Thanks for your comments. It helped a lot on my analysis. I'll consider more variables for fitting model. Thanks again.

jhelvy commented 7 months ago

I'm going to mark this issue as closed because this isn't an issue with the package.