mlogit:需要TRUE/FALSE的缺失值 [英] mlogit: missing value where TRUE/FALSE needed

查看:253
本文介绍了mlogit:需要TRUE/FALSE的缺失值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自离散选择实验(DCE)的数据,研究了来自不同部门的人员的招聘偏好.我已将其格式化为长格式.我想使用mlogit建模.我已经导出了数据,并且可以使用asclogit命令在Stata中成功运行模型,但是我无法使其在R中运行.

I have data from a discrete choice experiment (DCE), looking at hiring preferences for individuals from different sectors. that I've formatted into long format. I want to model using mlogit. I have exported the data and can successfully run the model in Stata using the asclogit command, but I'm having trouble getting it to run in R.

这是前25行数据的快照:

Here's a snapshot of the first 25 rows of data:

> data[1:25,]
   userid    chid item sector outcome cul fit ind led prj rel
1   11275  211275    2      1       1   0   1   0   1   1   1
2   11275  211275    2      2       0   1   0   0   0   0   0
3   11275  211275    2      0       0   0   0   1   1   0   1
4   11275  311275    3      0       1   1   1   0   0   0   1
5   11275  311275    3      2       0   0   1   0   0   0   1
6   11275  311275    3      1       0   0   1   0   0   0   0
7   11275  411275    4      0       0   1   0   1   1   0   0
8   11275  411275    4      2       1   0   1   1   1   1   0
9   11275  411275    4      1       0   0   1   0   1   0   0
10  11275  511275    5      1       1   1   0   1   0   1   1
11  11275  511275    5      2       0   0   0   1   1   0   0
12  11275  511275    5      0       0   0   0   1   1   1   0
13  11275  611275    6      0       0   0   1   1   0   0   1
14  11275  611275    6      1       1   1   1   1   0   0   1
15  11275  611275    6      2       0   1   1   1   0   1   0
16  11275  711275    7      1       0   0   0   0   0   1   0
17  11275  711275    7      0       0   1   0   0   1   1   0
18  11275  711275    7      2       1   1   0   0   1   1   1
19  11275  811275    8      0       1   0   1   0   0   1   1
20  11275  811275    8      1       0   1   0   1   1   1   1
21  11275  811275    8      2       0   0   0   0   0   1   1
22  11275  911275    9      0       0   1   1   0   0   1   0
23  11275  911275    9      2       1   1   1   1   1   0   1
24  11275  911275    9      1       0   1   0   1   1   0   0
25  11275 1011275   10      0       0   0   0   0   0   0   0

userid和chid是因子变量,其余为数字.变量: 用户ID是唯一的响应者ID chid是每个受访者的唯一选择集ID 项目是选择集ID(在受访者中重复) 行业是替代品(3个不同行业) 在给定的选择集中由受访者选择结果 cul-rel是二元因子变量,根据实验设计的不同,具体因变量而异.

userid and chid are factor variables, the rest are numeric. The variables: Userid is unique respondent ID chid is unique choice set ID per respondent item is choice set ID (they are repeated across respondents) sector is alternatives (3 different sectors) outcome is alternative selected by respondent in the given choice set cul-rel is binary factor variables, alternative specific that vary across alternatives according to the experimental design.

这是我的mlogit语法:

Here is my mlogit syntax:

mlogit(outcome~cul+fit+ind+led+prj+rel,shape="long",
       data=data,id.var=userid,chid.var="chid",
       choice=outcome,alt.var="sector")

这是我得到的错误:

Error in if (abs(x - oldx) < ftol) { : 
  missing value where TRUE/FALSE needed

我确保没有丢失的数据,并且每个选择集正好有1个选择的替代项. 当模型在具有完全相同的数据集的Stata中运行良好时,关于为什么会出现此错误的任何想法?我可能在某处误读了mlogit语法.如果有帮助,我的Stata语法为: asclogit结果cul fit rel ind fit led prj,case(chid)替代项(sector)

I've made sure there are no missing data, and that each choice set has exactly 1 selected alternative. Any ideas about why I'm getting this error, when the model runs fine in Stata with the exact same dataset? I've probably misread the mlogit syntax somewhere. If it helps, my Stata syntax is: asclogit outcome cul fit rel ind fit led prj, case(chid) alternatives(sector)

推荐答案

在我发现问题后在这里回答自己的问题.

Answering my own question here as I figured it out.

在选择集中未选择任何替代项时,R mlogit无法处理. R还需要正确排序数据,选择集中的每个替代项都必须排成一行.由于某些数据管理,我没有这样做.有趣的是,Stata可以处理这两种情况,因此这就是我的Stata命令起作用的原因.

R mlogit can't handle when none of the alternatives in a choice set is selected. R also needs the data ordered properly, each alternative in a choice set must be in a row. I hadn't done that due to some data management. Interestingly, Stata can handle both of these conditions, so that's why my Stata commands worked.

顺便说一句,对于那些感兴趣的人,Stata的asclogit和R的mlogit给出了完全相同的结果.发生这种情况时总是很高兴.

As an aside, for those interested, Stata's asclogit and R's mlogit give the exact same results. Always nice when that happens.

这篇关于mlogit:需要TRUE/FALSE的缺失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆