I need to do statistical tests in r for several combinations in a dataset. The end result needs to be published and I cant have to many tables. My workflow right now looks like this: I calculate t.tests with the pairwise.t.test function, then write the result to a csv table and combine later several of these csv tables in LO calc (or to an xls file if you want).
ttestC30.class<- pairwise.t.test(LD$C30,LD$class)
write.table(ttestC30.class$p.value, 'ttestC30.class.csv')
ttestC100.class<- pairwise.t.test(LD$C100,LD$class)
write.table(ttestC100.class$p.value, 'ttestC100.class.csv')
ttestN30.class<- pairwise.t.test(LD$N30,LD$class)
write.table(ttestN30.class$p.value, 'ttestN30.class.csv')
Each of the tables gives me an output like this:
class1 class2 class3
class1 C30
class2 C30 C30
class3 C30 C30 C30
In the end I would like to export it to my text document in something like the following format:
class1 class2 class3
class1 C30 / C100 / N30
class2 C30 / C100 / ... … / … / ...
class3 C30 / C100 / ... 0.608 / 0.057 / 0.632 0.165 / 0.667 / 0.002
There must be a more convenient way to do this, no? A solution that is more generic than using pairwise.t.test would also be great, then I could repeat the same with other tests.
Edit: Reproducible example
attach(airquality)
a<- pairwise.t.test(Ozone, Month)
b<- pairwise.t.test(Temp, Month)
This is for example the output of a
round(a$p.value,3)
May Jun Jul Aug
Jun 1 NA NA NA
Jul 0 0.051 NA NA
Aug 0 0.050 1.000 NA
Sep 1 1.000 0.005 0.004
And this is the output I would like, showing a and b combined:
May Jun Jul Aug
Jun 1/0 NA/NA NA/NA NA/NA
Jul 0/0 0.051/0.020 NA/NA NA/NA
Aug 0/0 0.050/0.020 1.000/0.97 NA/NA
Sep 1/0 1.000/0.405 0.005/0.00 0.004/0