下面是一些代码,它试图计算模型中每个预测变量的边际效应(使用effects包),然后绘制结果。为此,我正在循环对象的"term.labels"
属性glm
terms
)。
library(DAAG)
library(effects)
formula = pres.abs ~ altitude + distance + NoOfPools + NoOfSites + avrain + meanmin + meanmax
summary(logitFrogs <- glm(formula = formula, data = frogs, family = binomial(link = "logit")))
par(mfrow = c(4, 2))
for (predictorName in attr(logitFrogs$terms, "term.labels")) {
print(predictorName)
effLogitFrogs <- effect(predictorName, logitFrogs)
plot(effLogitFrogs)
}
这根本不会产生图像。另一方面,明确说明预测变量名称确实有效:
effLogitFrogs <- effect("distance", logitFrogs)
plot(effLogitFrogs)
我究竟做错了什么?