Search code examples
rdplyrt-test

Matrix of t-test across vectors stored in one column of data.frame


I have a data.frame with two columns. One specifying a type, the other the performance associated with that type.

DF <- data.frame(type = c(rep("A",25), rep("B",25),rep("C",25), rep("D",25)),
                 performance = runif(100))

I want to use a two sample t-test to compare the performance of each type with one another.

The outcome I hope for is a matrix that gives me the p value of the comparison of the performance of each type with one another.

I planned to use multi.ttest which would give me the output I seek but could not get the data in the right format. I also considered using dplyr to split DF into groups according to types (i.e., group_by = type), but did not know how to then run t-test across all the groups.

Your help would be greatly appreciated.


Solution

  • Hope I got you correct, you can use pairwise.t.test from the stats(it comes with R installation):

    PWT = pairwise.t.test(DF$performance,DF$type,p.adjust.method = "none")
    PWT$p.value