Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I classify post-hoc test results in R?

Tags:

r

anova

posthoc

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?

like image 957
Carolin Avatar asked Nov 02 '11 15:11

Carolin


People also ask

How do you know if a post-hoc test is significant?

Post hoc tests are an integral part of ANOVA. When you use ANOVA to test the equality of at least three group means, statistically significant results indicate that not all of the group means are equal.

How do I report post hoc ANOVA results?

When reporting the results of a one-way ANOVA, we always use the following general structure: A brief description of the independent and dependent variable. The overall F-value of the ANOVA and the corresponding p-value. The results of the post-hoc comparisons (if the p-value was statistically significant).

What does Tukey HSD tell us in R?

The TukeyHSD() function is available in base R and takes a fitted aov object. The output gives the difference in means, confidence levels and the adjusted p-values for all possible pairs. The confidence levels and p-values show the only significant between-group difference is for treatments 1 and 2.

What is a post-hoc test when is it appropriate to examine this output?

A post hoc test is used only after we find a statistically significant result and need to determine where our differences truly came from. The term “post hoc” comes from the Latin for “after the event”. There are many different post hoc tests that have been developed, and most of them will give us similar answers.


2 Answers

I think the OP wants the letters to get a view of the comparisons.

library(multcompView)
multcompLetters(extract_p(TukeyHSD(uni2.anova)))

That will get you the letters.

You can also use the multcomp package

library(multcomp)
cld(glht(uni2.anova, linct = mcp(Micro = "Tukey")))

I hope this is what you need.

like image 145
Luciano Selzer Avatar answered Oct 10 '22 16:10

Luciano Selzer


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 result

hsd <- TukeyHSD(uni2.anova)

If you look at str(hsd) you can that you can then get at bits...

hsd$Micro[,1]

That will give you the column of your differences. You should be able to extract what you want now.

like image 2
John Avatar answered Oct 10 '22 17:10

John