绘制概率方程

发布于 2025-01-04 15:27:18 字数 1148 浏览 1 评论 0原文

我运行了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福丶如此 2025-01-11 15:27:18
  • 所有独立变量(我更喜欢“预测器”)的值,这会更容易一些
  • 这是不可重现的,如果是的话(即给我们一个 mydata 的工作示例),您确实需要指定
  • 您的 规范混淆了 <-= (它们不能完全互换,尽管它们在赋值的上下文中):你想要类似

(我在这里需要一些文本,所以将格式化正确编码)

bidvec <- 0:1600
plot(bidvec,predict(mod1,
    newdata=data.frame(our_bid1=bidvec,
                       state=ref_state,type=ref_type),
                        type="response"), 
lwd=5, col="blue", type="l")
  • this is not reproducible, it would be a little easier if it were (i.e. give us a working example of mydata)
  • you do need to specify values of all the independent (I prefer "predictor") variables
  • your specification confuses <- 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)

bidvec <- 0:1600
plot(bidvec,predict(mod1,
    newdata=data.frame(our_bid1=bidvec,
                       state=ref_state,type=ref_type),
                        type="response"), 
lwd=5, col="blue", type="l")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文