0

我正在尝试创建一个类似于链接上的情节的情节:http: //www.ats.ucla.edu/stat/r/dae/nbreg.htm

对于带有置信区间的预测结果图。下面列出了我正在使用的代码,对于我能够找到的所有内容,它与上面引用的网站上列出的代码相同。

 summary(modelpoisson<-glmer(respiratory_morbidity~mdata2$prevpercent+mdata2$weightclass+mdata2$interpretation+(1|feedlot),family="poisson",offset=log(mdata2$starting_head)),data=mdata2)

    newdata2p <- data.frame(
      prevpercent = rep(seq(from = min(mdata2$prevpercent), to = max(mdata2$prevpercent), length.out = 20), 5),
      interpretation  = factor(rep(1:5, each = 20), levels = 1:5, labels =
                      levels(mdata2$interpretation )))

    newdata2p <- cbind(newdata2p, predict(modelpoisson, newdata2p,type="link", se.fit=TRUE))
    newdata2p <- within(newdata2, {
      respiratory_morbidity <- exp(fit)
      LL <- exp(fit - 1.96 * se.fit)
      UL <- exp(fit + 1.96 * se.fit)
    })

但是,当我运行此代码时,当我尝试创建数据框 newdata2p 时出现以下错误

有人可以告诉我我做错了什么吗?

出现以下错误:

  newdata2p <- data.frame(
    + prevpercent = rep(seq(from = min(mdata2$prevpercent), to = max(mdata2$prevpercent), length.out = 20), 5),
    + interpretation  = factor(rep(1:5, each = 20), levels = 1:5, labels =
    + levels(mdata2$interpretation )))
    > View(newdata2p)
    > newdata2p <- cbind(newdata2p, predict(modelpoisson, newdata2p,type="link", se.fit=TRUE))
    Error in `[[<-.data.frame`(`*tmp*`, i, value = integer(0)) : 
      replacement has 0 rows, data has 100
    In addition: Warning messages:
    1: In predict.merMod(modelpoisson, newdata2p, type = "link", se.fit = TRUE) :
      unused arguments ignored
    2: 'newdata' had 100 rows but variables found have 134 rows 

谢谢!

4

0 回答 0