Helper function to perform Tukey post-hoc tests. It is used in gafem.
Arguments
- model
an object of class
aov
orlm
.- ...
other arguments passed to the function
stats::TukeyHSD()
. These include:which: A character vector listing terms in the fitted model for which the intervals should be calculated. Defaults to all the terms.
ordered: A logical value indicating if the levels of the factor should be ordered according to increasing average in the sample before taking differences. If ordered is true then the calculated differences in the means will all be positive. The significant differences will be those for which the lwr end point is positive.
- out
The format of outputs. If
out = "long"
a 'long' format (tibble) is returned. Ifout = "wide"
, a matrix with the adjusted p-values for each term is returned.
Value
A tibble data frame containing the results of the pairwise
comparisons (if out = "long"
) or a "list-columns" with p-values for
each term (if out = "wide"
).
Examples
# \donttest{
library(metan)
mod <- lm(PH ~ GEN + REP, data = data_g)
tukey_hsd(mod)
#> # A tibble: 81 × 8
#> term group1 group2 estimate conf.low conf.high p.adj sign
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 GEN H1 H10 -0.159 -0.700 0.382 0.995 ns
#> 2 GEN H1 H11 -0.0960 -0.637 0.445 1.00 ns
#> 3 GEN H1 H12 0.233 -0.308 0.774 0.921 ns
#> 4 GEN H1 H13 0.401 -0.140 0.942 0.303 ns
#> 5 GEN H1 H2 -0.0433 -0.584 0.498 1.00 ns
#> 6 GEN H1 H3 -0.154 -0.695 0.387 0.997 ns
#> 7 GEN H1 H4 -0.148 -0.689 0.393 0.998 ns
#> 8 GEN H1 H5 -0.103 -0.644 0.438 1.00 ns
#> 9 GEN H1 H6 -0.0440 -0.585 0.497 1.00 ns
#> 10 GEN H1 H7 -0.0200 -0.561 0.521 1 ns
#> # … with 71 more rows
tukey_hsd(mod, out = "wide")
#> # A tibble: 14 × 15
#> term H10 H11 H12 H13 H2 H3 H4 H5 H6
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 GEN 0.995 1.00 0.921 0.303 1.00 0.997 0.998 1.00 1.00
#> 2 GEN NA 1.00 0.334 0.0375 1.00 1 1 1.00 1.00
#> 3 GEN NA NA 0.585 0.0928 1.00 1.00 1.00 1 1.00
#> 4 GEN NA NA NA 0.993 0.797 0.352 0.374 0.556 0.795
#> 5 GEN NA NA NA NA 0.184 0.0406 0.0443 0.0847 0.182
#> 6 GEN NA NA NA NA NA 1.00 1.00 1.00 1
#> 7 GEN NA NA NA NA NA NA 1 1.00 1.00
#> 8 GEN NA NA NA NA NA NA NA 1.00 1.00
#> 9 GEN NA NA NA NA NA NA NA NA 1.00
#> 10 GEN NA NA NA NA NA NA NA NA NA
#> 11 GEN NA NA NA NA NA NA NA NA NA
#> 12 GEN NA NA NA NA NA NA NA NA NA
#> 13 REP NA NA NA NA NA NA NA NA NA
#> 14 REP NA NA NA NA NA NA NA NA NA
#> # … with 5 more variables: H7 <dbl>, H8 <dbl>, H9 <dbl>, `2` <dbl>, `3` <dbl>
# }