mlogit.data() 错误:分配的数据 `ids` 必须与现有数据兼容 [英] mlogit.data() Error: Assigned data `ids` must be compatible with existing data
问题描述
我一直在努力解决这个问题,但我找不到任何解决问题的方法.希望这里有人可以提供帮助.
I have been working hours on that and I simply cannot find any solution to the problem. Hopefully someone here can help.
我正在尝试为一些具有以下结构的数据创建个人选择矩阵:
I'm trying to create a personal choice matrix for some data with the following structure:
# A tibble: 2,152 x 32
age choice canton lr_s dist_svp dist_fdp dist_bdp dist_cvp dist_glp dist_sp
<dbl> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 39 sp GE 3 49 25 25 4 16 1
2 67 sp ZH 0 100 49 64 4 25 0
3 42 svp ZH 7 4 4 1 36 4 36
dist_gps pid_svp pid_fdp pid_bdp pid_cvp pid_glp pid_sp pid_gps french italian
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0 0 0 0 0 0 0 1 1 0
2 9 0 0 0 0 0 1 0 0 0
3 36 0 0 0 0 0 1 0 0 0
现在,我需要创建一个个人选择矩阵,其中包含列中 dist_*/pid_* 指示的 7 个备选方案.
Now, I need to create a personal choice matrix with the 7 alternatives that are indicated by dist_* / pid_* in the columns.
根据我的理解,这应该使用以下代码:
This should, according to my understanding, work with the following code:
work.pc <- mlogit.data(work,
varying = c(5:11, 12:18),
choice = "choice",
shape = "wide",
sep = "_")
但是,当我运行此代码时,我收到以下错误消息和一些警告消息:
However, when I run this code, I get the following Error message and a few Warning messages:
Error: Assigned data `ids` must be compatible with existing data.
x Existing data has 15064 rows.
x Assigned data has 2152 rows.
ℹ Only vectors of size 1 are recycled.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning messages:
1: Setting row names on a tibble is deprecated.
2: Setting row names on a tibble is deprecated.
3: Setting row names on a tibble is deprecated.
4: Setting row names on a tibble is deprecated.
5: Setting row names on a tibble is deprecated.
6: Setting row names on a tibble is deprecated.
7: Setting row names on a tibble is deprecated.
这里有什么问题?我很感激任何帮助!我什么都试过了.
What's the issue here? I'm grateful for any help! I've tried everything.
推荐答案
问题解决:tibble work"必须转换为数据帧.
Problem solved: the tibble "work" has to be converted into dataframe.
使用后
work <- as.data.frame(work)
代码运行正常,即消除了错误消息.
the code functions properly i.e. the Error message is eliminated.
这篇关于mlogit.data() 错误:分配的数据 `ids` 必须与现有数据兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!