简体   繁体   中英

repeated measure anova using regression models (LM, LMER)

I would like to run repeated measure anova in R using regression models instead an 'Analysis of Variance' ( AOV ) function.

Here is an example of my AOV code for 3 within-subject factors:

m.aov<-aov(measure~(task*region*actiontype) + Error(subject/(task*region*actiontype)),data)  

Can someone give me the exact syntax to run the same analysis using regression models? I want to make sure to respect the independence of residuals, ie use specific error terms as with AOV.

In a previous post I read an answer of the type:

lmer(DV ~ 1 + IV1*IV2*IV3 + (IV1*IV2*IV3|Subject), dataset))

I am really not sure about this solution since it still treats variables as between subjects, and I don't understand how adding random factors would change this.

Does someone know how to run repeated measure anova with lm/lmer taking into account residual independence?

Many thanks, Solene

If your aov example is right (maybe you don't want to nest things) you want this:

lmer(measure~(task*region*actiontype) + 1(1|subject/(task:region:actiontype))

If residual independence means intercept and slope independently calculated you need to specify them separately:

+(1|yourfactors)+(0+variable|yourfactors)

or use the symbol:

+(1||yourfactors)

Anyway if you read the help files you can find that lme4 can't deal with the most general problems.

I have some worked examples with more detail here: https://keithlohse.github.io/mixed_effects_models/lohse_MER_chapter_02.html

But if you want to get a mixed model that is homologous to your ANOVA, you can include random intercepts for your each subject:factor with your within-subject factors. Eg,

aov(DV~W1*W2*W3 + Error(SUBJECT/(W1*W2*W3)),data)

has a mixed-model equivalent of:

lmer(speed ~ 
    # Fixed Effects
    W1*W2*W3 + 
    # Random Effects
    (1|SUBJECT) + (1|W1:SUBJECT) + (1|W2:SUBJECT) + (1|W3:SUBJECT),
    data = DATA,
    REML = TRUE)

With REML set to TRUE and a balanced design, you should get degrees of freedom and f-values that are identical to your ANOVA. ML tends to underestimate variance components, so if you are comparing nested models and need to use ML your results will not match precisely. If you are not comparing nested models and can use REML, then the ANOVA and mixed-model should match (again, in a balanced design).

To @skan's earlier answer and other ideas people might have, I am not saying this is THE random-effects structure (as it might be more appropriate to include random slopes for W1 compared to random-intercepts), but if you have one observation per subject:condition, then these random-effects produce an equivalent result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM