> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of John Christie
> Sent: Wednesday, May 23, 2007 6:09 PM
> To: Bert Gunter
> Cc: [email protected]
> Subject: Re: [R] repeated measures regression
> 
> 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?

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

______________________________________________
[email protected] 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.

Reply via email to