# [R] Question on mixed effect models with LME

Kingsford Jones kingsfordjones at gmail.com
Thu Oct 22 04:38:06 CEST 2009

```On Wed, Oct 21, 2009 at 11:06 AM, Peter Flom
<peterflomconsulting at mindspring.com> wrote:
...
> I have a longitudinal data set, with data on schools and their test scores over a four year period.  I have centered year, and run the following
>
>
> m1.mod1 <- lme(fixed = math_1 ~ I(year-2007.5)*TFC_,
>               data = long,
>               random = ~I(year-2007.5)|schoolnum,
>               na.action = "na.omit")
>
> where math_1 is a percentage of students in a given school that are at the lowest math achievement level, year is year, TFC_ is a categorical variable for a treatment I wish to evaluate, and schoolnum is an identifier.
>
> When I run summary on this model, I get a strong negative correlation (-0.91) between the intercept and I(year-2007.5), despite the fact that the mean of year is 2007.5.
>

Hi Peter,

For the "what's going on here?" questions it's very helpful to have a
reproducible example.  I tried to create data fitting your
description, but the correlation disappeared as expected:

set.seed(777)
library(nlme)
school <- factor(rep(1:20, each=4))
year <- rep(2006:2009, 20)
year.c <- year - mean(year)
tmt <- sample(0:1, 20, replace = TRUE)[school]
math <- rnorm(80, 2 + tmt + .001*year + .0001*tmt*year, 1.5) + rnorm(20)[school]
tmt <- factor(tmt)
dfr <- data.frame(math, school, tmt, year, year.c)
rm(math, school, year, tmt)
f1 <- lme(math ~ year*tmt, data = dfr, random=~1|school)
f2 <- update(f1, . ~ year.c*tmt)
summary(f1)\$corFixed['year', '(Intercept)']
#  -0.9999997
summary(f2)\$corFixed['year.c', '(Intercept)']
#  0

A possibility is that the data are not of the expected classes.  What
does str(long) report?

hth,
Kingsford Jones

> I am puzzled, as I thought centering the time variable should eliminate, or at least strongly reduce, this correlation.
>
> Any insights appreciated
>
> thanks
>
> Peter
>
>
> Peter L. Flom, PhD
> Statistical Consultant
> Website: www DOT peterflomconsulting DOT com
> Writing; http://www.associatedcontent.com/user/582880/peter_flom.html