12 Mixed-Factorial ANOVA
In this example we’ll use the
ezANOVA()
function for fitting a Mixed-Factorial ANOVA model with one crossed (within-subject) factor, and one nested (between-subjects) factor, which will take the following form:
\[y_i=\beta_0+\beta_1\left(X1\right)+\beta_2\left(X2\right)+\beta_3\left(X1\cdot X2\right)+U_i+\epsilon_{ij}\]
The code in this chapter only works if you’re following along with the Github folder for this book (which you can download here), you’ve correctly set your working directory to the data folder (which you can learn how to do in Chapter 4), and run the code in the order it appears in this chapter.
Importing
We’ll be using the flexbility_power.csv file for this example.
Viewing
In this dataset, male and female subjects performed a countermovement vertical jump under three conditions: Baseline
, Post_run
, and Post_stretch
, where the Post_run
and Post_stretch
conditions consisted of running and stretching (lower body) for 10 minutes, respectively, just prior to the vertical jump. Half of the students completed the Post_run
first and vice versa. The subjects were instructed to try to jump as high as possible under each condition. Vertical jump peak power was then calculated as a function of jump height and body mass.
ID Sex Baseline Post_run Post_stretch
1 1 M 2586.75 2638.65 2560.80
2 2 M 3246.45 3428.10 3454.05
3 3 M 5701.35 5701.35 5779.20
4 4 M 2365.20 2417.10 2417.10
5 5 M 3023.85 3257.40 3101.70
6 6 M 2055.30 2185.05 2107.20
The data reported under the Baseline
, Post_run
, and Post_stretch
columns is vertical jump peak power, in watts.
More examples of viewing data can be found in Chapter 5
Formatting
The data should be converted to long format to make it compatible with the ezANOVA()
function. We can use the pivot_longer()
function from the tidyverse
package. Make sure you have that package loaded before using this function.
data <- pivot_longer(data = data,
cols = c("Baseline", "Post_run", "Post_stretch"),
names_to = "Condition",
values_to = "Power_Watts")
More examples of formatting data can be found in Chapter 6
Modeling
The ezANOVA()
Function
ezANOVA(
data
, dv
, wid
, within = NULL
, within_full = NULL
, within_covariates = NULL
, between = NULL
, between_covariates = NULL
, observed = NULL
, diff = NULL
, reverse_diff = FALSE
, type = 2
, white.adjust = FALSE
, detailed = FALSE
, return_aov = FALSE
)
The ezANOVA()
function is used for ANOVA models. There are many arguments for this function, but not all of them need to be specified. The ones that do need to be specified will depend on the exact ANOVA that you’re performing. If you’d like to learn more about functions and arguments, Chapter 2 covers basic programming concepts, including functions and arguments.
Model
In this example we need to specify the data
, dv
, wid
, within
and between
arguments. The data
argument is set equal to the entire dataset, the dv
argument, which is short for dependent variable, is set equal to the column of the dependent variable. The wid
argument is set equal to the column that contains the variable specifying the case/Ss identifier; usually the subID
column, or equivalent. The within
and between
arguments are set equal to the within-subject and between-subjects factor(s).
$ANOVA
Effect DFn DFd F p p<.05 ges
2 Sex 1 19 3.627466 7.208602e-02 0.1596944133
3 Condition 2 38 11.885433 9.794858e-05 * 0.0028620916
4 Sex:Condition 2 38 1.091126 3.461285e-01 0.0002634351
$`Mauchly's Test for Sphericity`
Effect W p p<.05
3 Condition 0.763975 0.08865681
4 Sex:Condition 0.763975 0.08865681
$`Sphericity Corrections`
Effect GGe p[GG] p[GG]<.05 HFe p[HF]
3 Condition 0.8090451 0.0003445542 * 0.8733736 0.0002253116
4 Sex:Condition 0.8090451 0.3365253953 0.8733736 0.3401654081
p[HF]<.05
3 *
4
Notice the formatting in the code above. When using the between
and within
arguments, you need to use a period and parentheses, .()
when listing the column. You can list additional columns for both of these arguments by separating each column with a comma: within = .(Condition, Column2)
.