我如何从新的数据中预测与gee、lme、glmer和gamm4在R中的预测?

时间:2021-07-16 23:46:43

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.

我使用各种函数来比较我的离散计数数据。我使用geepack来匹配一个GEE模型,一个使用lme (nlme)的线性混合效应模型,一个使用glmer (lme4)的GLMM,以及在R中使用gamm4 (gamm4)的一个GAMM。

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.

我对比较这些模型感兴趣,并希望为一组新的数据(预测变量)绘制预期的(预测值)值。我的目标是比较每种模型在特定条件下的预测效果(x变量)。特别感兴趣的是边际(GEE)和条件估计的比较。

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

我还有一个新的dataframe newdat,它有365个对23个变量的观察(平均每天的环境数据)。

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?

如有任何建议或良好的参考,我们将不胜感激。有人能帮助解决上面的错误吗?

1 个解决方案

#1


6  

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

对lme()和lmer()的预测被记录在http://glmm.wikidot.com/faq上。

#1


6  

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

对lme()和lmer()的预测被记录在http://glmm.wikidot.com/faq上。