如何根据 R 中的 gee、lme、glmer 和 gamm4 拟合新数据的预测? [英] How do I plot predictions from new data fit with gee, lme, glmer, and gamm4 in R?

查看:50
本文介绍了如何根据 R 中的 gee、lme、glmer 和 gamm4 拟合新数据的预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用各种函数拟合了离散计数数据以进行比较.我使用 geepack 拟合了 GEE 模型,这是使用 lme (nlmelog(count) 上的线性混合效应模型>)、使用 glmer (lme4) 的 GLMM,以及 R 中使用 gamm4 (gamm4) 的 GAMM.

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.

我对比较这些模型很感兴趣,并想绘制一组新数据(预测变量)的预期(预测)值.我的目标是比较每个模型在特定条件(x 个变量)下的预测效果.特别令人感兴趣的是边际 (GEE) 和条件估计之间的比较.

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.

我认为我的主要问题可能是以正确的标签和属性等以正确的形式获取新数据.我仍然是一个 R 新手并且在这些东西上挣扎(不幸的是,我的大学没有这方面的课程).

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).

我目前有合适的模型

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.

我还有我的新数据框 newdat,其中包含 23 个变量的 365 个观测值(一年中每一天的平均环境数据).

I also have my new dataframe newdat which has 365 observations of 23 variables (average environmental data for each day of the year).

我被困在如何从中预测新的计数估计值上.我玩弄了 model.matrix 函数,但无法让它工作.例如,我试过:

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?

推荐答案

获取 lme() 和 lmer() 的预测记录在 http://glmm.wikidot.com/faq

Getting predictions for lme() and lmer() is documented on http://glmm.wikidot.com/faq

这篇关于如何根据 R 中的 gee、lme、glmer 和 gamm4 拟合新数据的预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆