[R] Mixed Effects Model on Within-Subjects Design

David Atkins datkins at u.washington.edu
Thu May 20 07:08:03 CEST 2010


Given that you want all comparisons among all means in your design, you 
won't get that directly in a call to lme (or lmer in lme4 package). 
Take a look at multcomp package and its vignettes, where I think you'll 
find what you're looking for.

cheers, Dave

Dave Atkins, PhD
Research Associate Professor
Department of Psychiatry and Behavioral Science
University of Washington
datkins at u.washington.edu

Center for the Study of Health and Risk Behaviors (CSHRB)		
1100 NE 45th Street, Suite 300 	
Seattle, WA  98105 	

Center for Healthcare Improvement, for Addictions, Mental Illness,
   Medically Vulnerable Populations (CHAMMP)
325 9th Avenue, 2HH-15
Box 359911
Seattle, WA 98104?

Dear R Experts,

I am attempting to run a mixed effects model on a within-subjects repeated
measures design, but I am unsure if I am doing it properly. I was hoping
that someone would be able to offer some guidance.

There are 5 independent variables (subject, condition, difficulty,
repetition) and 1 dependent measure (value). Condition and difficulty are
fixed effects and have 3 levels each (1,2,3 and 25,50,75 respectively),
while subject and repetition are random effects. Three repeated measurements
(repetitions) were taken for each condition x difficulty pair for each
subject, making this an entirely within-subject design.

I would like an output that compares the significance of the 3 levels of
difficulty for each condition, as well as the overall interaction of
condition*difficulty. The ideal output would look like this:

condition1:diff25 vs. condition1:diff50  p_value = ....
condition1:diff25 vs. condition1:diff75  p_value = ....
condition1:diff50 vs. condition1:diff75  p_value = ....

condition2:diff25 vs. condition1:diff50  p_value = ....
condition2:diff25 vs. condition1:diff75  p_value = ....
condition2:diff50 vs. condition1:diff75  p_value = ....

condition3:diff25 vs. condition1:diff50  p_value = ....
condition3:diff25 vs. condition1:diff75  p_value = ....
condition3:diff50 vs. condition1:diff75  p_value = ....

condition*diff  p_value = ....

Here is my code:

#get the data
study.data =read.csv("http://files.davidderiso.com/example_data.csv",
subject = factor(subject)
condition = factor(condition)
diff = factor(diff)
rep = factor(rep)

#visualize whats happening
interaction.plot(diff, condition, value, ylim=c(240000,
450000),ylab="value", xlab="difficulty", trace.label="condition")

#compute the significance
study.lme = lme(value~condition*diff,random=~1|subject/rep)

Thank you so much for your generous help!!!

Dave Deriso
UCSD Psychology

	[[alternative HTML version deleted]]

More information about the R-help mailing list