I am attempting to generalise some repeated measures ANOVA code for a string input of outcome variable and grouping variable as shown below:
outcome_var<-"outcome_varnam1"
grouping_var <- "grouping_varnam1"
Therefore in dplyr i can call the appropriate dataframe columns using
!!as.name(outcome_var)
this works for most functions but throws up an error on grouped pairwise t-test functions
Error: Strings must match column names. Unknown columns: !!as.name(grouping_var)
I am wondering how to call the variables as column names in this function without explicitly using the column object names, as the full ANOVA anlysis code is long and i wish to repeat this for dozens of different outcome variables and group factors. Using get() or sym() does not work for me. Below is the full sample code. I hope the given data snippet gives enough info.
temp<-data.frame(Subj.ID = c("a", "a", "a", "a", "a", "a"),
timepoint = c("101", "102", "103", "104", "105", "106"),
grouping_varnam1 = c("Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo"),
outcome_varnam1 = c(12.6, 9.6, 16.4, NA, 43.1, NA))
attach(temp)
outcome_var<-"outcome_varnam1"
grouping_var<-"grouping_varnam1"
#these lines for testing assumptions of anova work fine using the format:
temp %>% group_by(!!as.name(grouping_var)) %>% get_summary_stats(!!as.name(outcome_var), type = "mean_sd")
temp %>% group_by(!!as.name(grouping_var)) %>% identify_outliers(!!as.name(outcome_var))
temp %>% group_by(!!as.name(grouping_var)) %>% shapiro_test(!!as.name(outcome_var))
#this line for a pairwise t-test grouped by timepoint does not work:
temp %>%
group_by(timepoint) %>%
pairwise_t_test(!!as.name(outcome_var) ~ !!as.name(grouping_var), paired = FALSE, p.adjust.method = "holm")
Error: Strings must match column names. Unknown columns: !!as.name(grouping_var)