How to do Dunnett test on R?
Supposing I performed the ANOVA test in my data and gave significantly different, I would like to perform the Dunnett test just to compare my treatments with the control group. Should I use some specific package or in the R standard itself already have?
To do the Dunnet test, you can use the function
How there is no data in the question I will use the base
Immediately before running the test one must initialize the random number generator because apparently the distribution calculations t multivariate call the random number generator. With
set.seed()or results are reproducible.
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)
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)
The idea of calling
set.seedcomes from the answers to a question on Cross Validated, https://stats.stackexchange.com/questions/83116/dunnetts-test-in-r-returning-different-values-each-time#83125 in English.