0

Two-Way repeated-measure ANOVA using not all possible values of one categorical variable.

Dear community, I have a data frame, that looks something like this (This is only an example data set, so there can be no useful results been found in this data set. ):

ID condition side value
01 B left 13
01 C left 20
01 A left 9
01 C right 23
01 A right 11
01 B right 17
02 C left 18
02 A left 7
02 B left 12
02 A right 11
02 B right 15
02 C right 20

ID is the participant number. There are two factors that define the condition of this repeated measure design (condition, side). They are the categorical variables. Value is the depended variable. So I ran a two-Way repeated-meausre ANOVA like this:

library(dplyr)

is.factor(data$condition) #FALSE
is.factor(data$side) #FALSE
Copy_data_factor <- data %>%
    convert_as_factor(condition, side)
is.factor(Copy_data_factor$condition) #TRUE
is.factor(Copy_data_factor$side) #TRUE

#Two-Way repeated-measure ANOVA
res.aov <- anova_test(
    data = Copy_data_factor, dv = value_1, wid = ID, within = c(condition, side)
     )
get_anova_table(res.aov)

#Output: Mauchly’s test of sphericity
res.aov

I guess I can calculate the analysis this way.

Now, I would like to run a two-way repeated ANOVA again but not with condition A, B and C. Instead only conditions B and C should be considered during this analysis. Has anyone an idea, how I can accomplish this?

John
  • 19
  • 4

1 Answers1

0

You could just reduce the dataframe to only keep rows with the desired conditions, and then run the ANOVA over this new dataframe:

Copy_data_new <- Copy_data_factor[which(Copy_data_factor[["condition"]] %in% c("b", "c")),]
Patrick F
  • 144
  • 4
  • This code doesn't work. I always receive a data frame with 0 observations. – John Jun 22 '23 at 00:16
  • It works for me given your example above. There might be an issue with missing values. I have adapted the code above to account for that, try if that works for you – Patrick F Jun 26 '23 at 07:12