鉴于我似乎无法在nlmer中的新数据集上使用predict()
(请参阅yesterday's question),我正在尝试手动预测nlmer模型的输出,但有些事情并非如此右。
我运行模型:
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))))
然后我将随机效果合并到我的原始数据(调用列b0_re
)并将固定效果保存为fe <- fixef(out)
:
> fe
M_agesero D_intercept D_agesero b0 b2 b3
0.005944058 -1.798036528 -0.001427386 4.405443370 0.633165740 2.961626278
最后,我称之为两种预测方法:
data$predicted_auto <- predict(out)
data[, predicted_manual:= fe[["b0"]]+b0_re + fe[["b2"]]*exp(-fe[["b3"]]*M_visit_time) +
fe[["M_agesero"]]*M_agesero +
fe[["D_intercept"]]*D_intercept + fe[["D_agesero"]]*D_agesero]
但两种方法的结果并不相同:
variable value b0_re M_visit_time M_agesero D_intercept D_agesero predicted_auto predicted_manual
1: vl 4.542850 -0.2946956 1.624658 33.16164 0 0.00000 4.312766 4.313013
2: vl 4.408664 -0.2946956 2.010959 33.16164 0 0.00000 4.309310 4.309503
3: vl 4.493095 -0.2946956 2.219178 33.16164 0 0.00000 4.308612 4.308748
4: vl 4.540980 -0.2946956 2.583562 33.16164 0 0.00000 4.308100 4.308163
5: vl 2.844477 -0.2946956 3.293151 33.16164 0 0.00000 4.307888 4.307899
6: observed_survival 1.198478 -0.2946956 0.000000 0.00000 1 33.16164 1.053172 2.898543
'vl'的两种方法看起来非常接近,但'observed_survival'的方法非常错误。我哪里误入歧途?