I am trying to run a 2x2x2 mixed-design ANOVA in R, but I cannot figure out how to take four of my six variable columns, which are populated with reaction times
- Animal seen face predicted (ASFP)
- Face seen animal predicted (FSAP)
- Face predicted face seen (FPFS)
- Animal seen animal predicted (ASAP)
And use them to create 2 factors (prediction and target) with two levels each (animal and face) in order to run my mixed-designs ANOVA. I know how to do this in SPSS, which I would do by sorting my variables as below:
Within-Subjects Variables
(Prediction, Target)
FPAS (1,1)
FPFS (1,2)
APFS (2,1)
APAS (2,2)
However, I haven't been able to replicate this in R.
Below is an example of my dataset, and in this case, as I don't know how to do this with two factors, I have created a single factor (condition) with 4 levels and then run the ANOVA.
# Set seed for reproducibility of the data
set.seed(10)
# Create a dataset of reaction times for participants after seeing an image of either an Animal or face based on whether they predicted seeing an animal or face
# Group the participants into one of two groups, group one, face experts, and group two, non-face experts
data_set <- data.frame(
ID = seq(1, 100, by = 1),
FPAS = rnorm(100, sd = 5, mean = 30),
APFS = rnorm(100, sd = 15, mean = 100),
FPFS = rnorm(100, sd = 5, mean = 30),
APAS = rnorm(100, sd = 15, mean = 100),
Group = sample(c(1, 2), size = 100, replace = TRUE))
#Gather the data into a single factor with four levels
df_long <- gather(data_set, "Condition", "ReactionTime", ASFP, FSAP, FPFS, ASAP)
# Run a Mixed-design ANOVA
res <- anova_test(data = df_long, dv=ReactionTime, wid = ID, between = Group, within = c(Condition),detailed=T,effect.size="pes")
#output the findings
get_anova_table(res, correction="auto")