#### Example 1: one-way ANOVA ####
outcome <- c( 1.4,2.1,3.0,2.1,3.2,4.7,3.5,4.5,5.4 ) # data
treatment1 <- factor( c( 1,1,1,2,2,2,3,3,3 )) # grouping variable
anova1 <- aov( outcome ~ treatment1 ) # run the ANOVA
summary( anova1 ) # print the ANOVA table
#
# Df Sum Sq Mean Sq F value Pr(>F)
# treatment1 2 7.9356 3.9678 3.6626 0.09129 .
# Residuals 6 6.5000 1.0833
#
etaSquared( anova1 ) # effect size
#
# eta.sq partial.eta.sq
# treatment1 0.5 0.5
#
#### Example 2: two-way ANOVA ####
treatment2 <- factor( c( 1,2,3,1,2,3,1,2,3 )) # second grouping variable
anova2 <- aov( outcome ~ treatment1 + treatment2 ) # run the ANOVA
summary( anova2 ) # print the ANOVA table
#
# Df Sum Sq Mean Sq F value Pr(>F)
# treatment1 2 7.9356 3.9678 55.797 0.001197 **
# treatment2 2 6.2156 3.1078 43.703 0.001915 **
# Residuals 4 0.2844 0.0711
#
etaSquared( anova2 ) # effect size
#
# eta.sq partial.eta.sq
# treatment1 0.5497229 0.9653961
# treatment2 0.4305727 0.9562393
#
Run the code above in your browser using DataLab