多项Logistic模型对mlogit的影响

spi*_*tor 6 r mlogit

我收到了一些很好的帮助,我的数据格式正确,在这里用mlogit生成一个多项逻辑模型(格式化mlogit的数据)

但是,我现在正在尝试分析协变量在我的模型中的影响.我发现帮助文件mlogit.effects()不是很有用.其中一个问题是该模型似乎产生了大量的NA(见下文index(mod1)).

  1. 任何人都可以澄清我的数据产生这些NA的原因吗?
  2. 任何人都可以帮助我mlogit.effects使用下面的数据吗?
  3. 我会考虑将分析转移到multinom().但是,我无法弄清楚如何格式化数据以适合使用的公式multinom().我的数据是七个不同项目(可访问,信息,权衡,辩论,社交和响应)的一系列排名我是否只是模拟他们选择的第一个等级并忽略他们在其他等级中选择的内容?我可以得到这些信息.

可重现的代码如下:

#Loadpackages 
library(RCurl)
library(mlogit)
library(tidyr)
library(dplyr)
#URL where data is stored
dat.url <- 'https://raw.githubusercontent.com/sjkiss/Survey/master/mlogit.out.csv'

#Get data
dat <- read.csv(dat.url)

#Complete cases only as it seems mlogit cannot handle missing values or tied data which in this case you might get because of median imputation
dat <- dat[complete.cases(dat),]

#Change the choice index variable (X) to have no interruptions, as a result of removing some incomplete cases
dat$X <- seq(1,nrow(dat),1)

#Tidy data to get it into long format
dat.out <- dat %>%
  gather(Open, Rank, -c(1,9:12)) %>%
  arrange(X, Open, Rank)

#Create mlogit object
mlogit.out <- mlogit.data(dat.out, shape='long',alt.var='Open',choice='Rank', ranked=TRUE,chid.var='X')

#Fit Model
mod1 <- mlogit(Rank~1|gender+age+economic+Job,data=mlogit.out)
Run Code Online (Sandbox Code Playgroud)

这是我尝试设置一个类似于帮助文件中描绘的数据框的数据框.它不起作用.我承认虽然我很了解申请家庭,但对我来说,tapply是黑暗的.

with(mlogit.out, data.frame(economic=tapply(economic, index(mod1)$alt, mean)))
Run Code Online (Sandbox Code Playgroud)

比较帮助:

data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
m <- mlogit(mode ~ price | income | catch, data = Fish)

# compute a data.frame containing the mean value of the covariates in
# the sample data in the help file for effects
z <- with(Fish, data.frame(price = tapply(price, index(m)$alt, mean),
                       catch = tapply(catch, index(m)$alt, mean),
                       income = mean(income)))

# compute the marginal effects (the second one is an elasticity
effects(m, covariate = "income", data = z)
Run Code Online (Sandbox Code Playgroud)

JAR*_*ARH 0

您正在使用排名数据,而不仅仅是多项选择数据。mlogit 中排名数据的结构是,一个人的第一组记录都是选项,然后第二组记录是除了排名第一的记录之外的所有选项,依此类推。但该指数每次都假定相同数量的选项。所以一堆 NA。我们只需要摆脱它们。

> with(mlogit.out, data.frame(economic=tapply(economic, index(mod1)$alt[complete.cases(index(mod1)$alt)], mean)))
            economic
Accessible      5.13
Debate          4.97
Information     5.08
Officials       4.92
Responsive      5.09
Social          4.91
Trade.Offs      4.91
Run Code Online (Sandbox Code Playgroud)