[R] Mixed Effects Model on Within-Subjects Design

Dave Deriso dderiso at ucsd.edu
Thu May 20 11:23:54 CEST 2010


Hi Thierry,

Thank you so much for your response! I ran the model and I obtained
some strange results (see below). Is there a simple way to compute a
condition x difference interaction with the lme? Also, I read in the R
Book (Crawley, 2007) that repeated measures on the same day would be
temporal pseudoreplication. Being that I have 3 repeated measures for
each condition x difference pair, I assumed that each measurement
(variable "rep") would be a random effect variable along with subject.
Is this a correct assumption? If not, should I switch back to a
repeated measures ANOVA?

Thank you so much!!

Best,
Dave Deriso
UCSD Psychology

study.lme = lme(value~condition:diff - 1,random=~1|subject)
> summary(study.lme)
Linear mixed-effects model fit by REML
 Data: NULL
      AIC      BIC    logLik
 19354.54 19405.71 -9666.272

Random effects:
 Formula: ~1 | subject
       (Intercept) Residual
StdDev:    37786.52 59827.67

Fixed effects: value ~ condition:diff - 1
                    Value Std.Error  DF  t-value p-value
condition1:diff25 300110.0   9506.69 746 31.56829       0
condition2:diff25 327827.6   9506.69 746 34.48388       0
condition3:diff25 276391.2   9506.69 746 29.07334       0
condition1:diff50 356877.5   9506.69 746 37.53962       0
condition2:diff50 339113.9   9506.69 746 35.67108       0
condition3:diff50 340492.1   9506.69 746 35.81606       0
condition1:diff75 420141.8   9506.69 746 44.19432       0
condition2:diff75 409093.6   9506.69 746 43.03218       0
condition3:diff75 409342.6   9506.69 746 43.05837       0
 Correlation:
                 cn1:25 cn2:25 cn3:25 cn1:50 cn2:50 cn3:50 cn1:75 cn2:75
condition2:diff25 0.545
condition3:diff25 0.545  0.545
condition1:diff50 0.545  0.545  0.545
condition2:diff50 0.545  0.545  0.545  0.545
condition3:diff50 0.545  0.545  0.545  0.545  0.545
condition1:diff75 0.545  0.545  0.545  0.545  0.545  0.545
condition2:diff75 0.545  0.545  0.545  0.545  0.545  0.545  0.545
condition3:diff75 0.545  0.545  0.545  0.545  0.545  0.545  0.545  0.545

Standardized Within-Group Residuals:
       Min          Q1         Med          Q3         Max
-6.15651930 -0.55808827 -0.02570532  0.52282057  5.06724039

Number of Observations: 783
Number of Groups: 29

On Thu, May 20, 2010 at 2:01 AM, ONKELINX, Thierry
<Thierry.ONKELINX at inbo.be> wrote:
> 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 at 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 at r-project.org
>> [mailto:r-help-bounces at r-project.org] Namens Dave Deriso
>> Verzonden: donderdag 20 mei 2010 9:27
>> Aan: David Atkins
>> CC: r-help at 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 at 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 at 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 at 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 at 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