[R] Measuring correlations in repeated measures data
Ben Bolker
bbolker at gmail.com
Mon Feb 28 09:24:48 CET 2011
Brant Inman <brant.inman <at> mac.com> writes:
>
> R-helpers:
>
> I would like to measure the correlation coefficient between the repeated
measures of a single variable
> that is measured over time and is unbalanced. As an example, consider the
Orthodont dataset from package
> nlme, where the model is:
>
> fit <- lmer(distance ~ age + (1 | Subject), data=Orthodont)
>
> I would like to measure the correlation b/t the variable "distance" at
different ages such that I would have
> a matrix of correlation coefficients like the following:
>
> age08 age09 age10 age11 age12 age13 age14
> age08 1
> age09 1
> age10 1
> age11 1
> age12 1
> age13 1
> age14 1
>
> The idea would be to demonstrate that the correlations b/t
> repeated measures of the variable "distance"
> decrease as the time b/t measures increases. For example,
> one might expect the correlation
> coefficient b/t age08 and age09 to be higher than that
> between age08 and age14.
>
This stuff is not currently possible in lmer/lme4 but is
easy in nlme:
library(nlme)
Orthodont$age0 <- Orthodont$age/2-3
## later code requires a time index of consecutive integers
## (which apparently must also start at 1, although not stated)
fit <- lme(distance~age,random=~1|Subject,data=Orthodont)
## compute autocorrelation on the basis of lag only, plot
a <- ACF(fit)
plot(a,alpha=0.05)
fit2 <- update(fit, correlation=corSymm(form=~age0|Subject))
fit3 <- update(fit, correlation=corAR1(form=~age0|Subject))
AIC(fit,fit2,fit3)
## at least on the basis of AIC, this extra complexity is
## not warranted
anova(fit,fit2) ## likelihood ratio test
More information about the R-help
mailing list