# FOUR-WAY ANOVA # Load necessary packages library(car) # Prompt the user to select a file (LongHFScores.csv <- available in the Supplementary Materials) selected_file <- file.choose() # Load the dataframe file (LongHFScores.csv <- available in the Supplementary Materials) data <- read.csv(selected_file) # Prepare data for the four-way ANOVA data$CONDITION <- factor(data$CONDITION, labels = c("ADHD", "ASD", "ADHD&ASD")) data$SOCIAL_ISOLATION <- factor(data$SOCIAL_ISOLATION, labels = c("Before", "During")) data$THERAPY <- factor(data$THERAPY, labels = c("No Therapy", "Therapy")) data$DIAGNOSIS <- factor(data$DIAGNOSIS, labels = c("No Diagnosis", "Formal Diagnosis")) # Conduct the four-way ANOVA on TOTAL_SCORE anova_result <- aov(TOTAL_SCORE ~ CONDITION * SOCIAL_ISOLATION * THERAPY * DIAGNOSIS, data = data) # Display the ANOVA summary summary(anova_result) # Optional: Test assumptions (e.g., homogeneity of variances) leveneTest(TOTAL_SCORE ~ CONDITION * SOCIAL_ISOLATION * THERAPY * DIAGNOSIS, data = data) # Optional: Visualise interactions if needed interaction.plot(data$SOCIAL_ISOLATION, data$CONDITION, data$TOTAL_SCORE, col = c("red", "blue", "green"), lty = 1, main = "Interaction Plot - Social Isolation and Condition", xlab = "Social Isolation", ylab = "Total Hyperfocus Score") interaction.plot(data$THERAPY, data$CONDITION, data$TOTAL_SCORE, col = c("purple", "orange", "green"), lty = 1, main = "Interaction Plot - Therapy and Condition", xlab = "Therapy", ylab = "Total Hyperfocus Score")