I am fairly new to R and mixed models analysis.
I wanted to produce a single estimate for the change in the variable ln_ahr
based on time
for every individual. I believe this can be thought of as a slope of change in time. Here is how my data is structured (long format):
v001 ln_ahr time
13404 28337 0.28438718 0
13405 28337 NA 3
13406 28337 NA 6
13407 28337 1.05015991 9
13408 28337 NA 12
13409 28337 1.33345188 15
13410 28337 NA 19
13413 28355 1.14904314 0
13414 28355 NA 3
13415 28355 1.06546008 6
13416 28355 NA 9
13417 28355 1.17865500 12
13418 28355 2.84949593 15
13423 29983 0.07015499 0
13424 29983 0.21056477 3
13426 29983 0.36125306 9
13427 29983 0.66139848 12
13428 29983 0.16962391 16
where v001
is the subject identifier.
I tried to calculate the slope using the nlme
package in R as:
slope <- lme(ln_ahr~time,random=~1+time|v001,
data=restructured,na.action="na.omit")
and I tried obtained the ranef(slope)
and coef(slope)
values. I read that the coef(slope)
values "computes the sum of the fixed and random effects coefficients for each explanatory variable of each grouping factor" thus I believed that printing out the coefficients for time (leaving out the intercept values) would give me an estimate of each individual's change in ln_ahr
over time and I can use that as my "slope" or estimate for change in ln_ahr
.
Time is calculated as years where time
0 indicates the first year of ln_ahr
measurement; everyone is measured every three years.
I am wondering if this a correct approach at all or if I did it correctly; if not what are your suggestions?