使用'predict'和newdata lme4选择'未定义列'

时间:2015-06-30 00:14:14

标签: r predict lme4

我正在尝试在运行nlmer模型后对新数据使用'predict'函数,并且遇到了问题。

我用于模型的数据集看起来是这样的(除了patient_id有一个实际值,我无法分享):

> data
   patient_id          variable    value M_visit_time M_agesero D_intercept D_agesero
1:     SECRET                vl 4.542850     1.624658  33.16164           0   0.00000
2:     SECRET                vl 4.408664     2.010959  33.16164           0   0.00000
3:     SECRET                vl 4.493095     2.219178  33.16164           0   0.00000
4:     SECRET                vl 4.540980     2.583562  33.16164           0   0.00000
5:     SECRET                vl 2.844477     3.293151  33.16164           0   0.00000
...

我运行模型:

model_formula <- "value~ModelGradient(time=M_visit_time,b0,b2,b3)~ M_agesero +
              D_intercept + D_agesero + (b0|patient_id)"

Model<- ~b0+b2*exp(-b3*time)
ModelGradient<-deriv(Model,namevec=c("b0","b2","b3"),
                    function.arg=c("time","b0","b2","b3"))

out<-do.call("nlmer", list( as.formula(model_formula),
                          data=quote(data),
                          start = c(b0=3,b2=1,b3=4),
                          control=nlmerControl(optimizer="bobyqa",
                                               optCtrl=list(maxfun=200000))))

我想要预测的数据集如下所示:

> newdata
    patient_id          variable    value M_visit_time M_agesero D_intercept D_agesero
 1:     SECRET observed_survival 1.198478          0.0   0.00000           1  33.16164
 2:     SECRET                vl 4.542850          0.0  33.16164           0   0.00000
 3:     SECRET                vl 4.542850          0.5  33.16164           0   0.00000
 4:     SECRET                vl 4.542850          1.0  33.16164           0   0.00000
 5:     SECRET                vl 4.542850          1.5  33.16164           0   0.00000
...

但是当我运行命令时

newdata$predicted <- predict(out, newdata=newdata)

我收到错误:

Error in `[.data.frame`(fr, vars) : undefined columns selected

然而,运行data$predicted <- predict(out)的工作正常。

输入赞赏!

0 个答案:

没有答案