R for loop stopping at 27 of 67 variables(columns) in for-loop Dunn Test

58 views Asked by At

I've been doing Dunns tests as post-hoc and corrections for my thesis data and I've run into an issue. I have 67 variables and 3 groupings that I'm running through, so loops just easily solve the tons of data analysis.

ind1 var1(6) var... var67(73)
a value value value
b value value value
c value value value

I've done a normal kruskal.test for all my variables and groups with no issue, but "dunnTest" and dunn_test" both stop at 27 variables

library(FSA)

Dunn_df = list()
for(i in names(df[,6:73])){  
  Dunn_df[[i]] <- dunnTest(formula(paste(i, "~ ind1")), data = df, method = "bonferroni")
  
}

and

library(rstatix)  

Dunn_df = list()
for(i in names(df[,6:73])){  
  Dunn_df[[i]] <- dunn_test(formula(paste(i, "~ ind1")), data = df, p.adjust.method="BH")
  
}

both output a nested list that I've able to read with print(Dunn_df), but only do the dunn test on columns 6:32.

1

There are 1 answers

0
Julian On

Without any reproducible example it is very difficult to help you. Using the example data mtcars, the function works just fine on a large number of variables, e.g.

library(rstatix)
library(purrr)
rep(colnames(mtcars),10)  |> 
  purrr::map(
  ~dunn_test(formula(paste(.x, "~mpg")), data = mtcars, p.adjust.method="BH")
  )