I am doing a 2x2 repeated measures in R, within-subjects. I organized the data in long, so I have the same subject in 4 columns, having a score for each level of the 2 factors. I followed a very helpful tutorial: https://datascienceplus.com/two-way-anova-with-repeated-measures/

The issue is the degrees of freedom, I have 20 subjects with 4 observations each, but the df returns 72, as if it is counting each row as a new participant. Also, the analysis is not considering the 2 factors for the df. How do I fix it?

I am unsure how your data are structured. It sounds to me like you are not meeting the condition stated in the tutorial:

"So we see that we have one row per observation per participant."

Can you please show how your data are arranged and the command you use to generate the anova?

Thank you so much. You're absolutely right, I don't have a row per observation per participant. Each participant has several rows. My data is as follows:

sub condition experiment Q1

1 ci A -2

2 ci A 2

3 ci A 2

...

1 cc A -3

2 cc A -3

3 cc A -3

...

1 ci B 0.5

2 ci B 3

3 ci B 3

...

1 ci B 0.5

2 ci B 3

3 ci B 3

And I used this command:

my_data <- read.csv(file.choose())

my_data.mean <- aggregate(my_data$Q1, by = list(my_data$subject, my_data$condition, my_data$experiment), FUN = 'mean')

colnames(my_data.mean) <- c('subject', 'condition', 'experiment', 'Q1')

my_data.mean <- my_data.mean[order(my_data.mean$subject), ]

head(my_data.mean)

Q1.aov <- with(my_data.mean, aov(Q1 ~ condition * experiment + Error(subject / (condition * experiment) )) )

summary(Q1.aov)

Thank you for your help!!

Are you sure that you should include the experiment in the *by* argument of the aggregate function? If you do that, each combination of subject, condition and experiment only appears once in the data set and the aggregate function does nothing. Notice in the tutorial that you linked that each PID appears 20 times and there are four combinations of image and music, so each unique condition is measured five times.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.