# COMPARISON BETWEEN THERAPY = 0 (No Therapy) VS THERAPY = 1 (Therapy) # Ensure necessary packages are loaded library(dplyr) # 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) # Function to check normality and apply the appropriate test for THERAPY groups compare_therapy <- function(data, var) { # Filter data by therapy data_therapy0 <- data %>% filter(THERAPY == 0, SOCIAL_ISOLATION == 0) data_therapy1 <- data %>% filter(THERAPY == 1, SOCIAL_ISOLATION == 0) # Check normality for each group shapiro_therapy0 <- shapiro.test(data_therapy0[[var]])$p.value shapiro_therapy1 <- shapiro.test(data_therapy1[[var]])$p.value # Print normality test results cat("Shapiro-Wilk normality test for", var, "(THERAPY = 0): p-value =", shapiro_therapy0, "\n") cat("Shapiro-Wilk normality test for", var, "(THERAPY = 1): p-value =", shapiro_therapy1, "\n") if (shapiro_therapy0 > 0.05 & shapiro_therapy1 > 0.05) { # If both groups are normal, use Student's t-test t_test <- t.test(data_therapy0[[var]], data_therapy1[[var]], var.equal = TRUE) cat("t-test for", var, ": p-value =", t_test$p.value, "\n") } else { # Otherwise, use Mann-Whitney test wilcox_test <- wilcox.test(data_therapy0[[var]], data_therapy1[[var]]) cat("Mann-Whitney test for", var, ": p-value =", wilcox_test$p.value, "\n") } } # Apply the function for each variable and condition cat("\nComparison for CONDITION = 1:\n") compare_therapy(data_condition1, "SPECIFIC_SCENARIOS") compare_therapy(data_condition1, "SCREEN_TIME") compare_therapy(data_condition1, "TOTAL_SCORE") cat("\nComparison for CONDITION = 2:\n") compare_therapy(data_condition2, "SPECIFIC_SCENARIOS") compare_therapy(data_condition2, "SCREEN_TIME") compare_therapy(data_condition2, "TOTAL_SCORE") cat("\nComparison for CONDITION = 3:\n") compare_therapy(data_condition3, "SPECIFIC_SCENARIOS") compare_therapy(data_condition3, "SCREEN_TIME") compare_therapy(data_condition3, "TOTAL_SCORE")