How to take Dunnett’s test on R?

Asked

Viewed 1,856 times

4

Assuming that I performed the ANOVA test on my data and gave significantly different, I would like to perform the Dunnett test precisely to compare my treatments with the control group. I should use some specific package or in the R pattern itself already has ?

1 answer

8


To take the Dunnet test, you can use the function glht package multcomp.

As there is no data in the question I will use the base iris.

Immediately before running the test the random number generator should be initialized because apparently the distribution calculations t multivariate call the random number generator. With set.seed() or results are reproducible.

library(multcomp)

data(iris)

fit <- aov(Sepal.Length ~ Species, data = iris)

set.seed(204)    # Torna os resultados reprodutíveis
summary(glht(fit, linfct = mcp(Species = "Dunnett")))
#
#Simultaneous Tests for General Linear Hypotheses
#
#Multiple Comparisons of Means: Dunnett Contrasts
#
#
#Fit: aov(formula = Sepal.Length ~ Species, data = iris)
#
#Linear Hypotheses:
#                         Estimate Std. Error t value Pr(>|t|)    
#versicolor - setosa == 0    0.930      0.103   9.033   <1e-10 ***
#virginica - setosa == 0     1.582      0.103  15.366   <1e-10 ***
#---
#Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#(Adjusted p values reported -- single-step method)

Note.

The idea of calling set.seed comes from the answers to a question in Cross Validated, Why does Dunnett’s test give different values every time he runs in English.

  • Thank you so much for your help. Now one last question I got. You put 204 on set.Seed for some reason, or it was completely random ?

  • 1

    @Gus It was completely random. To choose the value of the set.seed I usually run something like sample(1e4, 1). Either that or 1234 :).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.