Skip to contents

Compares treatment means after an analysis of variance and returns compact letter displays (means sharing a letter do not differ). Fisher's LSD, Duncan's multiple range test (DMRT), Tukey's HSD, Student-Newman-Keuls, Scheffe and Bonferroni are computed inside the package, so no extra package is needed. Dunnett's test against a control uses multcomp when it is installed.

Usage

perform_posthoc(
  model,
  data,
  response,
  treatment,
  mse = NULL,
  df_error = NULL,
  posthoc = "lsd",
  alpha = 0.05,
  control = NULL,
  verbose = TRUE
)

Arguments

model

A fitted aov or lm model containing the treatment factor.

data

Data frame used to fit the model. Kept for compatibility; the model frame is used for the calculations.

response

Name of the response variable (used to label output).

treatment

Name of the treatment factor in the model.

mse

Error mean square. Default NULL takes it from the model. Supply it to compare means against a different error term (for example the main-plot error of a split-plot design).

df_error

Error degrees of freedom matching mse. Default NULL takes it from the model.

posthoc

Method(s): "lsd", "duncan", "tukey", "snk", "scheffe", "bonferroni", "dunnett", a vector of these, or "all".

alpha

Significance level. Default 0.05.

control

Control level for Dunnett's test. Default NULL uses the first level of the treatment factor.

verbose

Logical. If TRUE (default), prints the results.

Value

A list with one element per method. Each element contains groups (means and letters, ordered from highest to lowest, with treatments as row names), table (level, mean, SE, letter, replications), comparisons (all pairwise differences with their SE, p-value and significance), critical_range and statistics. The Dunnett element is a data frame of comparisons with the control.

Details

Means are least-squares means of the treatment factor averaged over the other factors in the model. With complete, balanced data they equal the arithmetic means. With missing plots or unequal replication every pair is tested with its own standard error of difference, so the letters stay exact (Tukey-Kramer form for the range tests).

Duncan's and the Student-Newman-Keuls tests use the studentized range for the number of means spanned by each pair, with the protection level \(1 - (1 - \alpha)^{p - 1}\) for Duncan's test, and apply the closure rule: two means are declared different only if every range of means containing them is also significant (Duncan, 1955). The p-value reported for a pair is the largest p-value of the ranges containing it, so it agrees with the letters.

Least-squares means that cannot be estimated (for example a level whose cells are all empty in a model with interactions) are left out with a warning. Dunnett's test averages differences over interacting factors and uses mse and df_error when they are supplied.

Letters are assigned with the insert-and-absorb algorithm of Piepho (2004), which gives a valid display for any pattern of significant pairs. The group containing the highest mean gets the letter "a".

References

Duncan, D.B. (1955). Multiple range and multiple F tests. Biometrics, 11(1), 1-42. doi:10.2307/3001478

Piepho, H.-P. (2004). An algorithm for a letter-based representation of all-pairwise comparisons. Journal of Computational and Graphical Statistics, 13(2), 456-466. doi:10.1198/1061860043515

Kramer, C.Y. (1956). Extension of multiple range tests to group means with unequal numbers of replications. Biometrics, 12(3), 307-310. doi:10.2307/3001469

See also

compare_means for summary statistics, anova_rbd.

Examples

data(mothbean_rbd)
fit <- aov(seed_yield ~ block + treatment, data = mothbean_rbd)
ph <- perform_posthoc(fit, mothbean_rbd, response = "seed_yield",
                      treatment = "treatment", posthoc = c("lsd", "duncan"))
#> 
#> ======================================================================
#>  POST-HOC COMPARISONS
#> ======================================================================
#> 
#> Fisher's LSD (alpha = 0.05, error df = 21)
#> Critical difference: 45.884
#>                 level   mean     SE group n
#>  T5 RDF+Rhizobium+PSB 705.00 15.601     a 4
#>        T6 75% RDF+FYM 662.75 15.601    ab 4
#>      T3 RDF+Rhizobium 650.75 15.601    bc 4
#>            T8 RDF+Zn5 639.75 15.601   bcd 4
#>            T4 RDF+PSB 632.25 15.601   bcd 4
#>            T7 RDF+S20 610.75 15.601    cd 4
#>                T2 RDF 604.75 15.601     d 4
#>            T1 Control 516.25 15.601     e 4
#> 
#> Duncan's MRT (alpha = 0.05, error df = 21)
#> Critical ranges: p=2 45.884, p=3 48.171, p=4 49.629, p=5 50.651, p=6 51.407, p=7 51.986, p=8 52.441
#>                 level   mean     SE group n
#>  T5 RDF+Rhizobium+PSB 705.00 15.601     a 4
#>        T6 75% RDF+FYM 662.75 15.601    ab 4
#>      T3 RDF+Rhizobium 650.75 15.601    bc 4
#>            T8 RDF+Zn5 639.75 15.601    bc 4
#>            T4 RDF+PSB 632.25 15.601    bc 4
#>            T7 RDF+S20 610.75 15.601     c 4
#>                T2 RDF 604.75 15.601     c 4
#>            T1 Control 516.25 15.601     d 4
#> 
#> Means sharing a letter do not differ significantly.
ph$duncan$groups
#>                      seed_yield groups
#> T5 RDF+Rhizobium+PSB     705.00      a
#> T6 75% RDF+FYM           662.75     ab
#> T3 RDF+Rhizobium         650.75     bc
#> T8 RDF+Zn5               639.75     bc
#> T4 RDF+PSB               632.25     bc
#> T7 RDF+S20               610.75      c
#> T2 RDF                   604.75      c
#> T1 Control               516.25      d