0
$\begingroup$

I'm trying to understand how aov relates to lm, and this question and its answer have been very helpful. However, I'm finding some differences between the F values and p values between the aov and anova calls:

    set.seed(1)
    DF <- data.frame(participant=factor(1:5), A.1=rnorm(5, 50, 
        20), A.2=rnorm(5, 100, 20), B.1=rnorm(5, 20, 20), 
        B.2=rnorm(5, 50, 20))
    
    conditions <- names(DF)[ names(DF) != "participant" ]
    
    dfL <- reshape(DF, direction="long", varying=conditions, 
          v.names="value", idvar="participant", times=conditions, 
          timevar="group")
    
    dfL$factor1 <- factor( rep(c("A", "B"), each=10) )
dfL$factor2 <- factor( rep(c(1, 2), each=5) )
    
    names(dfL) <- c("id", "group", "DV", "IV1", "IV2") 

aov output:

    my.aov <- aov(DV ~ IV1*IV2 + Error(id / (IV1*IV2)), dfL)
    summary(my.aov)
        Error: id:IV1
                  Df Sum Sq Mean Sq F value Pr(>F)  
        IV1        1   7094    7094   11.79 0.0264 *
        Residuals  4   2406     602

anova output:

    anova(lm(DV ~ id, dfL), lm(DV ~ id+IV1, dfL))
    
    Model 1: DV ~ id
    Model 2: DV ~ id + IV1
      Res.Df   RSS Df Sum of Sq      F  Pr(>F)  
    1     15 23011                              
    2     14 15917  1    7094.1 6.2397 0.02557 *

How can I extract the same information (F values, p values) that aov outputs from lm?

$\endgroup$
3
  • $\begingroup$ The model described in the aov isn't the same as that in the lm. ... Because your design is balanced, the following will return the same results: my.aov <- aov(DV ~ IV1*IV2, dfL); summary(my.aov); model = lm(DV ~ IV1*IV2, dfL); anova(model). For unbalanced designs, and for additional options with an lm object, you might use car::Anova. $\endgroup$ Nov 29, 2021 at 14:46
  • $\begingroup$ Thanks for your comment @SalMangiafico. If I understood the answer I linked to in my question, I think the anova(lm) is equivalent to the aov at least in terms of how the sum of squares are calculated (and are actually identical as I show for effect IV1 in my question). What I'm asking is how can I get the same F and p values as well? Your suggestion model = lm(DV ~ IV1*IV2, dfL); anova(model) still gives different F and p values (eg, for IV1 aov gives me F=11.79 but anova(model) gives me F=18.50) $\endgroup$
    – locus
    Nov 29, 2021 at 18:57
  • $\begingroup$ Well, since you've specified a error term to use in your aov(), it won't translate to a default anova with lm(). Probably, you would formulate a mixed-effects model with lmer or lme, but I don't know offhand what model would be equivalent to what you are trying to do with your aov. There might be a way to specify error terms to be used in the anova table in anova or car::Anova, but I don't know. $\endgroup$ Dec 1, 2021 at 12:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.