如何根据 R 中的 gee、lme、glmer 和 gamm4 拟合的新数据绘制预测?
我使用各种函数来拟合离散计数数据以进行比较。我使用 geepack 拟合 GEE 模型,这是使用 lme
(nlme) 在 log(count)
上建立的线性混合效应模型>),在 R 中使用 glmer
(lme4) 的 GLMM 和使用 gamm4
(gamm4) 的 GAMM。
我有兴趣比较这些模型并希望绘制一组新数据(预测变量)的预期(预测)值。我的目标是比较每个模型在特定条件(x 个变量)下的预测效果。特别令人感兴趣的是边际 (GEE) 和条件估计之间的比较。
我认为我的主要问题可能是使用正确的标签和属性等以正确的形式获取新数据。我仍然是一个 R 新手,并且在这些方面很挣扎(不幸的是,我的大学没有这方面的课程)。
我目前已经拟合了模型
gee1 lme1 lmer1 gamm1
,并且可以毫无问题地提取其固定效应系数和标准误差。我也没有问题从对数尺度转换它们或估计随机效应的置信区间。
我还有新的数据框 newdat
,其中包含 23 个变量的 365 个观测值(一年中每一天的平均环境数据)。
我陷入了如何从中预测新的计数估计的困境。我尝试了 model.matrix 函数,但无法让它工作。例如,我尝试过:
mm = model.matrix(terms(glmm1), newdat) # Error in model.frame.default(object,
# data, xlev = xlev) : object is not a matrix
newdat$pcount = mm %*% fixef(glmm1)
任何建议或好的参考资料将不胜感激。任何人都可以帮助解决上面的错误吗?
I have fit my discrete count data using a variety of functions for comparison. I fit a GEE model using geepack, a linear mixed effect model on the log(count)
using lme
(nlme), a GLMM using glmer
(lme4), and a GAMM using gamm4
(gamm4) in R.
I am interested in comparing these models and would like to plot the expected (predicted) values for a new set of data (predictor variables). My goal is to compare the predicted effects for each model under particular conditions (x variables). Of particular interest is the comparison between marginal (GEE) and conditional estimates.
I think my main problem might be getting the new data in the correct form with the correct labels and attributes and such. I am still very much an R novice and struggle with this stuff (no course on this at my university unfortunately).
I currently have fitted models
gee1 lme1 lmer1 gamm1
and can extract their fixed effect coefficients and standard errors without a problem. I also don't have a problem converting them from the log scale or estimating confidence intervals accounting for the random effects.
I also have my new dataframe newdat
which has 365 observations of 23 variables (average environmental data for each day of the year).
I am stuck on how to predict new count estimates from this. I played around with the model.matrix function but couldn't get it to work. For example, I tried:
mm = model.matrix(terms(glmm1), newdat) # Error in model.frame.default(object,
# data, xlev = xlev) : object is not a matrix
newdat$pcount = mm %*% fixef(glmm1)
Any suggestions or good references would be greatly appreciated. Can anyone help with the error above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获取 lme() 和 lmer() 的预测记录在 http://glmm.wikidot.com/faq
Getting predictions for lme() and lmer() is documented on http://glmm.wikidot.com/faq