Skip to content

repeated measures regression

5 messages · Bert Gunter, John Christie, Nordlund, Dan (DSHS/RDA) +1 more

#
How does one go about doing a repeated measure regression? The  
documentation I have on it (Lorch & Myers 1990) says to use linear /  
(subj x linear) to get your F.  However, if I put subject into glm or  
lm I can't get back a straight error term because it assumes  
(rightly) that subject is a nominal predictor of some sort.

In looking at LME it seems like it just does the right thing here if  
I enter the random effect the same as when looking for ANOVA like  
results out of it.  But, part of the reason I'm asking is that I  
wanted to compare the two methods.  I suppose I could get it out of  
aov but isn't that built on lm?  I guess what I'm asking is how to  
calculate the error terms easily with lm.
#
You need to gain some background. MIXED EFFECTS MODELS in S and S-PLUS by
Pinheiro and Bates is a canonical reference for how to do this with R.
Chapter 10  of Venables and Ripley's MASS(4th ed.) contains a more compact
but very informative overview that may suffice. Other useful references can
also be found on CRAN.


Bert Gunter
Genentech Nonclinical Statistics

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of John Christie
Sent: Thursday, May 17, 2007 10:06 AM
To: R-help at stat.math.ethz.ch
Subject: [R] repeated measures regression


How does one go about doing a repeated measure regression? The  
documentation I have on it (Lorch & Myers 1990) says to use linear /  
(subj x linear) to get your F.  However, if I put subject into glm or  
lm I can't get back a straight error term because it assumes  
(rightly) that subject is a nominal predictor of some sort.

In looking at LME it seems like it just does the right thing here if  
I enter the random effect the same as when looking for ANOVA like  
results out of it.  But, part of the reason I'm asking is that I  
wanted to compare the two methods.  I suppose I could get it out of  
aov but isn't that built on lm?  I guess what I'm asking is how to  
calculate the error terms easily with lm.

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
6 days later
#
Hmmm, been away and got this...  I appreciate the effort but there  
wasn't anything, in principle, in MASS on this I didn't already  
know.  My question is just more about the functioning of the lm  
command and deriving these values.  I understand that its the wrong  
approach for repeated measures design and lme is more appropriate.   
But, I wanted to examine / compare.  So, my question still stands.   
How does one get something like the subject x effect interaction term  
from lm?

Also, while I'm at it, anyone familiar with Blouin & Riopelle on  
confidence intervals and repeated measures deigns?  Is there a reason  
the intervals() command should give me different values for the  
narrow inference confidence intervals than they get from SAS?
On May 17, 2007, at 2:20 PM, Bert Gunter wrote:

            
#
If you just want to piece together a repeated measures analysis from lm(), it is certainly possible.  Say you have 10 subjects, each measured under 2 conditions.  You could do something like this:

#create sample data
y <- sample(1:10, 20, replace=TRUE) #response variable
subj <- as.factor(c(1:10, 1:10)) #subject id
condition <- as.factor(c(rep(1,10),rep(2,10))) #experimental condition
test.dat <- as.data.frame(cbind(y, subj, condition))
test.dat

#model response as a function of subj and condition
test.lm <- lm(y ~ as.factor(subj) + as.factor(condition), data=test.dat) 
summary(test.lm)
anova(test.lm)

If you look at the anova() output, you will have sums of squares for subj, condition and residuals.  For this simple and balanced example, Residuals is the subj x condition interaction which can be used as the error term for testing the condition effect.  But as has been pointed out, there are better and easier ways to analyze repeated measures, especially as the designs get more complex.


Hope this is helpful,

Dan

Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA  98504-5204
#
Hi John,

I have collected a few methods for doing this in a very empyrical
fashion. I've asked a few questions on r-help about them, and got
mixed responses. You can find the archived thread at:

http://tolstoy.newcastle.edu.au/R/e2/help/07/05/16660.html

The responses and linked resources might be of some interest to you,
too... Basically, my understanding is that ANOVA procedures are the
most powerful ones, provided you can meet their  assumptions. MANOVA
procedures do not require sphericity, but your design should be
balanced and time intervals should be equally-spaced. Finally,
assumptions for lme(r) models are the most forgiving, but their power
is also reduced.

I may be wrong on my conclusions, though, so I'm looking forward to
comments on this, especially on the lme(r) approaches...

Regards,