绘制概率方程
我运行了一个 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,state 为 11 个级别(人口最多的前 10 个级别和一个其他级别),并且type 有三个级别。
为了获得预测概率,我运行了以下代码。
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
我是否必须在绘图命令中指定所有自变量?我做错了什么?
I ran a logit model and am trying to plot the probability curve. I'm posting the question here and not the stats board because it's more an R question than a stats on, or at least I think so.
My model looks like:
mod1 = glm(factor(status1) ~ our_bid1 + factor(state) + factor(type),
data=mydat, family=binomial(link="logit"))
print(summary(mod1))
Status1
is a factor with two levels, our_bid
ranges from 0 to 20, state is 11 levels (top 10 populous and one which is other), and type has three levels.
To get the predicted probabilities, I ran the following code
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")
The problem happens when I am trying to plot the curve. I'm trying to have a general curve for change in our bid given the model.
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
Do I have to specify all the independent variables in the plot command? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mydata
的工作示例),您确实需要指定<-
和=
(它们不能完全互换,尽管它们在赋值的上下文中):你想要类似(我在这里需要一些文本,所以将格式化正确编码)
mydata
)<-
and=
(which are not quite interchangeable, although they are in the context of assignment): you want something like(I need some text here so SO will format the code properly)