I am trying to understand how to work with ANOVAs and post-hoc tests in R. So far, I have used aov() and TukeyHSD() to analyse my data. Example:
uni2.anova <- aov(Sum_Uni ~ Micro, data= uni2)
uni2.anova
Call:
aov(formula = Sum_Uni ~ Micro, data = uni2)
Terms:
Micro Residuals
Sum of Squares 0.04917262 0.00602925
Deg. of Freedom 15 48
Residual standard error: 0.01120756
Estimated effects may be unbalanced
My problem is, now I have a huge list of pairwise comparisons but cannot do anything with it:
TukeyHSD(uni2.anova)
Tukey multiple comparisons of means
95% family-wise confidence level
Fit: aov(formula = Sum_Uni ~ Micro, data = uni2)
$Micro
diff lwr upr p adj
Act_Glu2-Act_Ala2 -0.0180017863 -0.046632157 0.0106285840 0.6448524
Ana_Ala2-Act_Ala2 -0.0250134285 -0.053643799 0.0036169417 0.1493629
NegI_Ala2-Act_Ala2 0.0702274527 0.041597082 0.0988578230 0.0000000
This dataset has 40 rows... Idealy, I would like to get a dataset that looks something like this:
- Act_Glu2 : a
- Act_Ala2 : a
- NegI_Ala2: b...
I hope you get the point. So far, I have found nothing comparable online... I also tried to select only significant pairs in the file resulting from TukeyHSD, but the file does not "acknowlegde" that it is made up of rows & columns, making selecting impossible...
Maybe there is something fundamentally wrong with my approach?
The results from the TukeyHSD are a list. Use
str
to look at the structure. In your case you'll see that it's a list of one item and that item is basically a matrix. So, to extract the first column you'll want to save the TukeyHSD resultIf you look at
str(hsd)
you can that you can then get at bits...That will give you the column of your differences. You should be able to extract what you want now.
Hard to tell without example data, but assuming
Micro
is just a factor with 4 levels anduni2
looks something likethen I think what you're actually trying to get at is the basic multiple regression output:
You can access the numbers in any of these tables like, for example,
To see the list of what is stored in each object, use
names()
:In addition to the
TukeyHSD()
function you found, there are many other options for looking at the pairwise tests further, and correcting the p-values if desired. These includepairwise.table()
,estimable()
ingmodels
, theresampling
andboot
packages, and others...I think the OP wants the letters to get a view of the comparisons.
That will get you the letters.
You can also use the multcomp package
I hope this is what you need.