时变协变量结构的R纵向增长曲线模型/多重模型nlme

问题描述

我有国家,年份和一些变量的数据,如下所示:

df <- structure(list(country = c(1,1,2,3,3),continent = structure(c(3L,3L,4L,2L,2L),.Label = c("Africa","Americas","Asia","Europe","Oceania"),class = "factor"),year = c(0,2),lifeExp = c(80.69,82,82.603,77.218,78.471,79.425,76.81,77.31,78.242),pop = c(125956499L,127065841L,127467972L,58808266L,59912431L,60776238L,272911760L,287675526L,301139947L),gdpPercap = c(28816.58499,28604.5919,31656.06806,26074.53136,29478.99919,33203.26128,35767.43303,39097.09955,42951.65309)),class = "data.frame",row.names = c(NA,-9L))

  country continent year lifeExp       pop gdpPercap
1       1      Asia    0  80.690 125956499  28816.58
2       1      Asia    1  82.000 127065841  28604.59
3       1      Asia    2  82.603 127467972  31656.07
4       2    Europe    0  77.218  58808266  26074.53
5       2    Europe    1  78.471  59912431  29479.00
6       2    Europe    2  79.425  60776238  33203.26
7       3  Americas    0  76.810 272911760  35767.43
8       3  Americas    1  77.310 287675526  39097.10
9       3  Americas    2  78.242 301139947  42951.65

我感兴趣的是研究国家life expectancy随着timeyear的变化,同时添加另一个预测变量-随时间变化的协变量,是gdpPercap。我正在使用逐步模型构建过程,方法是使用r软件包nlme向每个后续模型添加复杂性:

randomIntercept <- lme(lifeExp ~ 1,random=~1|country,data=df,method='ML') # random intercept model
yearRI <- lme(lifeExp ~ year,method='ML') # add year as fixed effect
ARModel <- update(yearRI,correlation=corAR1()) # include first-order autocorrelation
gdp_tvc <- update(ARModel,.~. + gdpPercap) # adding gdp as time-varying covariate

我想知道这是否是添加时变协变量的正确方法?所以我最后一个完整的模型是:

gdp_tvc <- lme(lifeExp ~ year + gdpPercap,correlation=corAR1(),method='ML')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...