Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 绘制概率方程_R_Statistics_Glm - Fatal编程技术网

R 绘制概率方程

R 绘制概率方程,r,statistics,glm,R,Statistics,Glm,我运行了一个logit模型,并试图绘制概率曲线。我把这个问题贴在这里而不是统计板上,因为这更像是一个R问题而不是统计问题,或者至少我这么认为 我的模型看起来像: mod1 = glm(factor(status1) ~ our_bid1 + factor(state) + factor(type), data=mydat, family=binomial(link="logit")) print(summary(mod1)) Status1是一个有两个级别的因子,我们的投

我运行了一个logit模型,并试图绘制概率曲线。我把这个问题贴在这里而不是统计板上,因为这更像是一个R问题而不是统计问题,或者至少我这么认为

我的模型看起来像:

mod1 = glm(factor(status1) ~ our_bid1 + factor(state) + factor(type),
           data=mydat, family=binomial(link="logit"))
print(summary(mod1))
Status1
是一个有两个级别的因子,
我们的投标范围从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")
all.x1
  • 这是不可复制的,如果是的话会容易一些(即,给我们一个
    mydata
    的工作示例)
  • 您确实需要指定所有独立(我更喜欢“预测器”)变量的值
  • 您的规范混淆了
    • 这是不可复制的,如果是的话会容易一些(即,给我们一个
      mydata
      的工作示例)
    • 您确实需要指定所有独立(我更喜欢“预测器”)变量的值
    • 您的规范混淆了
      
      
      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 
      
      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")