0

I have run a series of ANOVAs that examine the link between group membership and a range of dependent variables, with a dataframe generated containing the results of each ANOVA model (one row = one ANOVA model). I would now like to run a series of post-hoc tests based on a list I've generated of dependent variable-independent variable combinations that survived multiple comparison corrections. I've tried to write a a function that submits each of these DV-IV combinations to pairwise.t.test although my code is currently not working as expected. Please see an extract of this code with simulated data below:

# simulated data
df = data.frame(ID = c(1001, 1002, 1003, 1004, 1005, 1006,1007, 1008, 1009,   1010, 1011),
                    Group = as.numeric(c('0','1','2','0','2','1','0','2','0','1','0')),
                    testscore_1 = as.numeric(c('23','28','30','15','7','18','29','27','14','22','24')),
                    testscore_2 = as.numeric(c('1','3','2','5','8','2','5','6','7','8','2')),
                    testscore_3 = as.numeric(c('18','20','19','15','20','23','19','25','10','14','12')))

# df containing combination of IV and DV that survived multiple comparison correction 
df_results = data.frame(Independent_variable = c("Group", "Group"), Dependent_variable=c("testscore_1", "testscore_2"))

dvs_ivs <- paste0("x = df$", df_results$Group, "g = df$", df_results$Dependent_variable)

posthoc_t_test_results <- lapply(dvs_ivs, function(x) {
    pairwise.t.test(print.noquote(x), p.adjust.method = "none")
})

Error message :  Error in factor(g) : argument "g" is missing, with no default "

Any suggestions?

M_Oxford
  • 361
  • 4
  • 11

1 Answers1

1

You may try to use Map -

Map(function(x, y) pairwise.t.test(df[[x]], df[[y]], p.adjust.method = "none"),
  df_results$Dependent_variable, df_results$Independent_variable)

#$testscore_1

#   Pairwise comparisons using t tests with pooled SD 

#data:  df[[x]] and df[[y]] 

#     0    1   
#1 0.79 -   
#2 0.96 0.85

#P value adjustment method: none 

#$testscore_2
#
#   Pairwise comparisons using t tests with pooled SD 

#data:  df[[x]] and df[[y]] 

#     0    1   
#1 0.88 -   
#2 0.53 0.67

#P value adjustment method: none 
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213