我运行了一个 logit 模型并试图绘制概率曲线。我在这里发布问题而不是统计板,因为它更像是一个 R 问题而不是统计数据,或者至少我是这样认为的。
我的模型看起来像:
mod1 = glm(factor(status1) ~ our_bid1 + factor(state) + factor(type),
data=mydat, family=binomial(link="logit"))
print(summary(mod1))
Status1
是一个有两个级别的因子,our_bid
范围从 0 到 20,状态是 11 个级别(人口最多的 10 个,其他的一个),类型有三个级别。
为了获得预测的概率,我运行了以下代码
all.x1 <- expand.grid(status1=unique(status1), our_bid1=unique(our_bid1),
state=unique(state), type=unique(type))
y.hat.new1 <- predict(mod1, newdata=all.x1, type="response")
当我尝试绘制曲线时会出现问题。在给定模型的情况下,我试图为我们的出价变化提供一般曲线。
plot(our_bid1<-000:1600,
predict(mod1, newdata=data.frame(our_bid1<-c(000:1600)), type="response"),
lwd=5, col="blue", type="l")
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) :
variable lengths differ (found for 'factor(state)')
In addition: Warning message:
'newdata' had 1601 rows but variable(s) found have 29532 rows
我是否必须在 plot 命令中指定所有自变量?我究竟做错了什么?