当替代选项是尚未选择的选项时使用mlogit

时间:2020-07-22 19:17:23

标签: r mlogit

我有一个数据集,其中按优先级选择项目,我试图弄清楚如何告诉mlogit在给定时间段内所有未选择的选择都是 。可以做到这一点吗?

人为的例子:

library("mlogit")
library("dplyr")
library("plm")

data("Produc", package = "plm")

# add a variable for order chosen (sepatately for each year)
Produc <- Produc %>%
  group_by(year) %>%
  mutate(rank = dense_rank(pcap))

# make an arbitrary categorical var to predict
Produc <- Produc %>%
  mutate(category = case_when(unemp < 5 ~ "LOW",
                              unemp < 9 ~ "MID",
                              TRUE ~ "HIGH"))

# Pretend that each state chose an item that contained all the values in columns between hwy and emp.
# This choosing process takes place in order of "rank".
# So the options for each state grow more constricted as more states pick.
# Pretend that this process happens each year.
# I want to see if those characteristics in the columns between hwy and emp can predict the category.

# Transform data for mlogit
Dt <- dfidx(Produc,idx = list(c("state","region"),"year"))
head(Dt)

# Try to predict categorical variable
M.Dt <- mlogit(category ~ hwy + water + util, Dt)

最后一行代码返回错误:

if(abs(x-oldx)

我猜这是因为我没有一个变量来说明是否选择了一个选项...但是我觉得应该可以说所有选择都是后来选择的。

我在这里树错树了吗?

0 个答案:

没有答案