【发布时间】:2020-10-31 04:24:01
【问题描述】:
我是 R 新手。我使用负二项式模型来测试 2 个变量(1 个二元变量和 1 个连续变量)和计数响应变量的影响。我还将他们的交互添加到模型中。
由于glm.nb 的结果很少,我想以某种方式绘制结果,尤其是交互。
我这样做是为了运行模型:
Y<- cbind(N_Cooperations)
Model8 <- glm.nb(Y ~ Condition + NR + Condition*NR)
summary(Model8)
Call:
glm.nb(formula = Y ~ Condition + NR + Condition * NR, init.theta = 2.012332023,
link = log)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.2063 -0.9508 -0.1757 0.3389 2.5682
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.5379 0.6920 2.222 0.02626 *
Condition -2.9514 1.0876 -2.714 0.00665 **
NR -0.1470 0.2065 -0.712 0.47654
Condition:NR 0.7771 0.3170 2.451 0.01423 *
---
然后我尝试使用effects 包中的plot(allEffects(Model8)) 来绘制交互,但这是我收到的消息:
plot(allEffects(Model8))
Error in mod.matrix[, components] : subscript out of bounds
In addition: Warning messages:
1: In factor.cols & stranger.cols :
longer object length is not a multiple of shorter object length
2: In (!factor.cols) & stranger.cols :
longer object length is not a multiple of shorter object length
我错过了什么?
再说一次,我对 R 很陌生。如果这听起来很愚蠢,请提前道歉。
【问题讨论】:
-
嗨,John,
allEffects来自哪个包? -
对不起,忘了说。它来自
Effects。 -
如果将
data参数添加到模型会发生什么? -
@Edward 当我这样做时
Model8 <- glm.nb(Y ~ Condition + NR + Condition*NR, data=naw_Data)我得到了同样的错误。 -
好的。好吧,
allEffects函数确实 接受“negbin”类的模型(您可以从 glm.nb 的帮助页面尝试示例),所以它必须是您的数据。但由于我们缺少您的数据,因此很难知道问题出在哪里。
标签: r plot regression