I am new to R, and I am trying to estimate a discrete choice model from my data. I got stuck in the process of estimating my model and would appreciate your helps.
I am using 'gmnl' package to estimate the S-MNL (Scale Multinomial Logit). There are four modes of transportation as the alternatives and the alternative-specific variables are 'toll' and 'time'. Individual-specific variables are income and gender (they both enter the model as dummy variables and income variables defined as income 6 income groups).
I started by estimating an S-MNL where the alternative-specific constants are fixed and not scaled, which was converged.
> smnl<- gmnl(choice~time+toll |1, data=u, model="smnl", R=100, notscale=c(1,1,1,0,0))
> summary(smnl)
Then, I allowed the scale to differ across individuals according to their income (I specified in the fifth part of the 'formula' that the variable income and no constant are included in the scale.
> smnl.het<-gmnl (choice ~ time + toll | 1 | 0 | 0 | Income1 +Income2 + Income3 + Income4 + Income5 + Income6 -1 , data=u, model="smnl", R=100, notscale= c (1,1,1, rep(0,2)))
> Summary (smnl.het)
But, I got the following error:
Error in H[i, , drop = FALSE] : subscript out of bounds
I do not know why I got this error. I tried the following argument to figure out what caused it:
options(error=recover)
smnl.het<-gmnl (choice ~ time + toll | 1 | 0 | 0 | Income1 +Income2 + Income3 + Income4 + Income5 + Income6-1 , data=u, model="smnl", R=100, notscale= c (1,1,1, rep(0,2)))
Enter a frame number, or 0 to exit
1: gmnl(choice ~ time + toll | 1 | 0 | 0 | Income - 1, data = u, model = "smnl", R
2: eval(opt, sys.frame(which = nframe))
3: eval(expr, envir, enclos)
4: maxLik(method = "bfgs", start = c(-0.948352323447934, -2.54330549099491, -4.394
5: maxRoutine(fn = logLik, grad = grad, hess = hess, start = start, constraints =
6: maxOptim(fn = fn, grad = grad, hess = hess, start = start, method = "BFGS", fix
7: callWithoutSumt(start, "logLikFunc", fnOrig = fn, gradOrig = grad, hessOrig = h
8: callWithoutArgs(theta, fName = fName, args = names(formals(sumt)), ...)
9: eval(f, sys.frame(sys.parent()))
10: eval(expr, envir, enclos)
11: logLikFunc(theta, fnOrig = ..1, gradOrig = ..2, hessOrig = ..3, X = ..4, y = ..
12: fnOrig(theta, ...)
13: drop(tcrossprod(H[i, , drop = FALSE], t(delta)))
14: tcrossprod(H[i, , drop = FALSE], t(delta))
Selection: 13
Called from: top level
Browse[1]> ls()
[1] "x"
Browse[1]> x
Error during wrapup: promise already under evaluation: recursive default argument reference or earlier problems?
Selection: 14
Called from: top level
Browse[1]> ls()
[1] "x" "y"
Browse[1]> x
Error during wrapup: promise already under evaluation: recursive default argument reference or earlier problems?
Browse[1]> y
het.Income2 het.Income3 het.Income4 het.Income5 het.Income6
[1,] 0 0 0 0 0
I cannot understand what is the problem. I think it might cause because of using dummy variables. Please help me to solve the problem. Thank you!