首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多项logistic模型在mlogit中的作用

多项logistic模型在mlogit中的作用
EN

Stack Overflow用户
提问于 2015-06-16 19:00:11
回答 1查看 1.2K关注 0票数 6

我得到了一些很好的帮助,使我的数据格式化正确,用mlogit (Formatting data for mlogit)生成了一个多项逻辑模型。

然而,我现在试图分析协变量在我的模型中的影响。我发现mlogit.effects()中的帮助文件内容不多。其中一个问题是,该模型似乎产生了大量的NAs (参见下面的index(mod1) )。

  1. 有人能澄清为什么我的数据会产生这些NAs吗?
  2. 有人能帮我让mlogit.effects处理下面的数据吗?
  3. 我会考虑将分析转移到multinom()。但是,我不知道如何格式化数据以适应使用multinom()的公式。我的数据是由七个不同项目(可访问性、信息、权衡、辩论、社交和响应)组成的系列排名,我是否只是对他们选择的第一名进行建模,而忽略了他们在其他排名中所选择的?我可以得到那个信息。

可复制代码如下:

代码语言:javascript
复制
#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)

下面是我试图设置一个类似于帮助文件中描述的数据框架的尝试。它不起作用。我承认,虽然我很了解应聘者的家庭,但对我来说,tapply是个模糊的人。

代码语言:javascript
复制
with(mlogit.out, data.frame(economic=tapply(economic, index(mod1)$alt, mean)))

从帮助中比较:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-23 21:43:05

您使用的是排序数据,而不仅仅是多项选择数据。mlogit中排名数据的结构是,一个人的第一组记录都是选项,其次是除排名第一之外的所有选项,依此类推。但是索引每次都假定相同数量的选项。所以一群纳特人。我们只需要除掉他们。

代码语言:javascript
复制
> 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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30876000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档