我正在使用以下软件包:
library(mlogit)
我的数据准备如下
data(CollegeDistance, package="AER")
testdata <- CollegeDistance
testdata$Dist[testdata$distance<0.4] <- 1
testdata$Dist[testdata$distance<1 & testdata$distance>=0.4] <- 2
testdata$Dist[testdata$distance<2.5 & testdata$distance>=1] <- 3
testdata$Dist[testdata$distance>=2.5] <- 4
这是我的模型
testmodel <- mlogit(as.formula(Dist ~ 1|urban + unemp + tuition|1), testdata, shape='wide', choice='Dist')
现在,当我运行以下代码时,结果很奇怪
as.character(attr(testmodel$formula, 'rhs')[[2]])
> as.character(attr(testmodel$formula, 'rhs')[[2]])
[1] "+" "urban + unemp" "tuition"
我期望的是这样的:
chr [1:3] "urban" "unemp" "tuition"