【发布时间】:2020-12-03 12:41:42
【问题描述】:
所以我的示例数据如下所示:
library(dplyr)
library(plm)
library(car)
library(margins)
test <- structure(list(period = c(1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4,
5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10,
10, 1, 2, 2, 2, 3, 3, 3, 3, 5, 6, 6, 7, 7, 7, 7, 8, 8), indicator = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L)), row.names = c(NA, -50L), class = "data.frame")
在下一步中,我为periodvariable 创建不同的类别
test$factor_period <-car::recode(test$period,"0:2='<2';3:5='3-5';6='6';7='7';8='8';9='9';10='10';11='11';12:44='>12'")
我现在正在计算一个概率模型。
model_time <- glm(indicator ~ factor_period, family = binomial(link = "probit"), data = test)
到目前为止一切顺利。现在我正在尝试确定factor_period 对indicator 在factor_period = "8" 上的边际效应,如下所示:
res_time <- summary(margins(model = model_time, at = list(factor_period = "8"), data = test))
这会返回错误信息:
Error in attributes(.Data) <- c(attributes(.Data), attrib) :
'names'[1] attribute must be the same length as the vector[0]
似乎对period 数据进行分类是个问题。如果没有 atargurment,marginscommand 就可以正常工作...有人知道如何解决这个问题吗?
【问题讨论】:
标签: r glm margins marginal-effects