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 ?
– Gus
@Gus It was completely random. To choose the value of the
set.seed
I usually run something likesample(1e4, 1)
. Either that or1234
:).– Rui Barradas