我是R的新手,我正在尝试从我的数据中估算离散选择模型。我在估计我的模型的过程中陷入困境,并感谢你的帮助。
我正在使用' gmnl'包估计S-MNL(Scale Multinomial Logit)。有四种交通方式作为替代方案,而替代方案特定的变量是“收费”。而且'时间'个人特定变量是收入和性别(它们都作为虚拟变量输入模型,收入变量定义为收入6收入组。)
我开始估计一个S-MNL,其中替代特定常数是固定的而不是缩放的,这是收敛的。
> smnl<- gmnl(choice~time+toll |1, data=u, model="smnl", R=100, notscale=c(1,1,1,0,0))
> summary(smnl)
然后,我根据他们的收入允许比例在个人之间有所不同(我在“公式”的第五部分中指出,可变收入和无常数都包含在比例中。
> 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)
但是,我收到了以下错误:
H [i ,,, drop = FALSE]:下标超出范围
时出错
我不知道为什么会出现这个错误。我尝试了以下参数来找出导致它的原因:
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
汇总时出错:承诺已经在评估中:递归默认参数引用还是早期问题?
Selection: 14
Called from: top level
Browse[1]> ls()
[1] "x" "y"
Browse[1]> x
汇总时出错:承诺已经在评估中:递归默认参数引用还是早期问题?
Browse[1]> y
het.Income2 het.Income3 het.Income4 het.Income5 het.Income6
[1,] 0 0 0 0 0
我无法理解这是什么问题。我认为这可能是因为使用虚拟变量。请帮我解决问题。谢谢!
答案 0 :(得分:0)
您可能错误地输入了notscale
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)
我原以为它看起来更像是这样的: smnl.het&lt; -gmnl(choice~time + toll | 1 | 0 | 0 | Income1 - 1,data = u,model =&#34; smnl&#34;,R = 100,notscale = c(1,1, 1,0,0))
您是否尝试过如上所述的较窄的命令集?