如何解决时变协变量结构的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
随着time
或year
的变化,同时添加另一个预测变量-随时间变化的协变量,是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 举报,一经查实,本站将立刻删除。