Home > Enterprise >  standard deviation in TukeyHSD test in R?
standard deviation in TukeyHSD test in R?

Time:07-28

I have made an experiment where I measured the height of a plant with different genotypes (A,B or C). I ran a one-way ANOVA and I performed TukeyHSD as posthoc test. However, I would like to obtain the standard deviation of the difference in each comparison:

Here is my code:

#Create my dataset
genotype<-c("A","A","A","B","B","B","C","C","C")
height<-c(4,5,6,10,10,11,10,11,12)
data<-data.frame(genotype,height)

#I run the ANOVA and TukeyHSD
model<-aov(height~genotype,data=data)
TukeyHSD(model)
#It returns the difference of each comparison, but not the standard deviation. Although it can be obtain in SPSS, I would like to do it in R software.

Does anyone know if a specific R command exist? Or should I try to build my own formula creating a loop on my dataset?

Thank you in adavance. King regard.

CodePudding user response:

You can use the emmeans package to make the pairwise comparisons.

library("emmeans")

genotype <- c("A", "A", "A", "B", "B", "B", "C", "C", "C")
height <- c(4, 5, 6, 10, 10, 11, 10, 11, 12)
data <- data.frame(genotype, height)

model <- aov(height ~ genotype, data = data)

TukeyHSD(model)
#>   Tukey multiple comparisons of means
#>     95% family-wise confidence level
#> 
#> Fit: aov(formula = height ~ genotype, data = data)
#> 
#> $genotype
#>          diff       lwr      upr     p adj
#> B-A 5.3333333  3.123923 7.542743 0.0007609
#> C-A 6.0000000  3.790590 8.209410 0.0003980
#> C-B 0.6666667 -1.542743 2.876077 0.6453214

pairs(
  emmeans(model, ~genotype),
  adjust = "tukey"
)
#>  contrast estimate   SE df t.ratio p.value
#>  A - B      -5.333 0.72  6  -7.407  0.0008
#>  A - C      -6.000 0.72  6  -8.332  0.0004
#>  B - C      -0.667 0.72  6  -0.926  0.6453
#> 
#> P value adjustment: tukey method for comparing a family of 3 estimates

Created on 2022-07-27 by the reprex package (v2.0.1)

  •  Tags:  
  • r
  • Related