[R] Mixed Effects Model on Within-Subjects Design

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu May 20 11:01:15 CEST 2010


Dear Dave,

I think you want this model.

lme(value~condition:diff - 1,random=~1|subject)

Note that I removed the replicate ID from the model. Include it in the model makes only sense if you can expect a similar replication effects the first/second/thirth time that a subject performs your test.

HTH,

Thierry

----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
  

> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org 
> [mailto:r-help-bounces op r-project.org] Namens Dave Deriso
> Verzonden: donderdag 20 mei 2010 9:27
> Aan: David Atkins
> CC: r-help op r-project.org
> Onderwerp: Re: [R] Mixed Effects Model on Within-Subjects Design
> 
> Hi Dave,
> 
> Thank you for your helpful advice. I will take a look at the 
> multicomp package.
> 
> I was wondering where the lme() function outputs the
> interaction between condition*difficulty?
> 
> Below is the output to the code I had originally sent. Which 
> one of these is condition*difficulty?
> 
> Fixed effects: value ~ condition * diff
>                       Value Std.Error  DF   t-value p-value
> (Intercept)       300109.95  9506.690 688 31.568289  0.0000
> condition2         27717.65  9071.048 688  3.055617  0.0023
> condition3        -23718.72  9071.048 688 -2.614772  0.0091
> diff50             56767.55  9071.048 688  6.258103  0.0000
> diff75            120031.80  9071.048 688 13.232408  0.0000
> condition2:diff50 -45481.21 12828.399 688 -3.545354  0.0004
> condition3:diff50   7333.37 12828.399 688  0.571651  0.5677
> condition2:diff75 -38765.77 12828.399 688 -3.021871  0.0026
> condition3:diff75  12919.59 12828.399 688  1.007109  0.3142
> 
> Also, why are diff25 and condition1 missing from the output??
> 
> Thanks again for your generous help!!!
> 
> Best,
> Dave Deriso
> 
> 
> On Wed, May 19, 2010 at 10:08 PM, David Atkins 
> <datkins op u.washington.edu> wrote:
> >
> > Dave--
> >
> > 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 op u.washington.edu
> >
> > Center for the Study of Health and Risk Behaviors (CSHRB) 
> 1100 NE 45th 
> > Street, Suite 300 Seattle, WA  98105
> > 206-616-3879
> > http://depts.washington.edu/cshrb/
> > (Mon-Wed)
> >
> > Center for Healthcare Improvement, for Addictions, Mental Illness,
> >  Medically Vulnerable Populations (CHAMMP)
> > 325 9th Avenue, 2HH-15
> > Box 359911
> > Seattle, WA 98104?
> > 206-897-4210
> > http://www.chammp.org
> > (Thurs)
> >
> > 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",
> > header=T)
> > attach(study.data)
> > 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
> > library(nlme)
> > study.lme = lme(value~condition*diff,random=~1|subject/rep)
> > summary(study.lme)
> >
> >
> >
> > Thank you so much for your generous help!!!
> >
> > Best,
> > Dave Deriso
> > UCSD Psychology
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help op r-project.org 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.
> 
> ______________________________________________
> R-help op r-project.org 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.
> 

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.



More information about the R-help mailing list