名称(类)<-clean_terms(名称(类))中的错误,“名称”属性的长度必须与向量的长度相同

时间:2018-07-12 11:25:58

标签: r

我正在运行概率模型进行统计。

probit <- glm(fine ~ mphover + age + female + cdl + outtown + statepol + budget_issue, data=speed, family=binomial(link="probit"))

我想像这样计算利润率 https://cran.r-project.org/web/packages/margins/margins.pdfhttps://cran.r-project.org/web/packages/margins/vignettes/Introduction.html#interactions_in_logit

但是在运行margins()时,我在几个数据集中遇到了这个错误。到目前为止,似乎没有任何帮助。尝试手动删除“名称”属性。重新进行所有计算,现在我被困住了。

> margins(probit, type="response")
Error in names(classes) <- clean_terms(names(classes)) : 
  'names' attribute [4] must be the same length as the vector [2]

如果有帮助,请使用traceback()

4: find_terms_in_model.default(model, variables = variables)
3: find_terms_in_model(model, variables = variables)
2: margins.glm(probit, type = "response")
1: margins(probit, type = "response")

2 个答案:

答案 0 :(得分:1)

问题解决了。谢谢!

当我已经使用speed$fine定义了数据集时,使用data=speed等进行了查找,并且会导致此错误。

答案 1 :(得分:1)

我遇到了同样的错误,并通过将我的数据(从 .csv 文件导入)转换为来自 tibble 的数据框并确保数据框中的变量名称与对 glm 的调用一致来解决它。

相关问题