Skip to contents

Performs classical (Tukey HSD, Fisher's LSD, Duncan, Scheffe, Bonferroni) and modern (emmeans with Kenward-Roger degrees of freedom) pairwise comparisons for single-factor, 2-way factorial, and 3-way factorial models. Supports simple effects decomposition via the `by` argument when factorial interactions are significant.

Usage

agri_posthoc(
  fit,
  trt = NULL,
  by = NULL,
  method = c("tukey", "lsd", "duncan", "scheffe", "bonferroni", "dunn"),
  alpha = 0.05,
  adjust = NULL,
  ...
)

Arguments

fit

An object of class `"agri_fitted_model"` returned by fit_experiment.

trt

Optional character string or vector of treatment factor names to compare. If `NULL`, defaults to the primary treatment factor.

by

Optional character string or vector specifying conditioning/slicing factor(s) for simple effects analysis (e.g., `by = "temperature"` to compare genotypes within each temperature level).

method

Character string specifying the post-hoc method: `"tukey"` (Tukey's Honestly Significant Difference), `"lsd"` (Fisher's Least Significant Difference), `"duncan"` (Duncan's Multiple Range Test), `"scheffe"` (Scheffe's test), `"bonferroni"` (Bonferroni adjustment), or `"dunn"` (for non-parametric rank comparisons).

alpha

Significance level for letter grouping (default = 0.05).

adjust

P-value adjustment method for pairwise tests (e.g. `"tukey"`, `"bonferroni"`, `"holm"`, `"none"`).

...

Additional arguments passed to emmeans::emmeans or agricolae.

Value

An S3 object of class `"agri_posthoc"` containing:

means_table

Data frame containing treatment levels, estimated marginal means (or medians), SE, df, CI, and grouping letters.

contrasts_table

Data frame of all pairwise comparisons with differences, standard errors, test statistics, and adjusted p-values.

method

Name of the multiple comparison method used.

alpha

Significance threshold used.

factor_name

Treatment factor evaluated.

by_factor

Conditioning/slicing factor(s) if simple effects were evaluated.

Examples

data(wheat_splitplot, package = "agriDesignR")
fit <- fit_experiment(
  data = wheat_splitplot,
  response = "grain_yield",
  main_plot = "temperature",
  sub_plot = "genotype",
  block = "block"
)
#> Registered S3 method overwritten by 'car':
#>   method           from
#>   na.action.merMod lme4
# Simple effects: compare genotypes within each temperature level
post_simple <- agri_posthoc(fit, trt = "genotype", by = "temperature", method = "tukey")
#> Note: adjust = "tukey" was changed to "sidak"
#> because "tukey" is only appropriate for one set of pairwise comparisons
print(post_simple)
#> 
#> ======================================================================
#>   agriDesignR: Post-Hoc Multiple Comparisons (emmeans (tukey, adjust = 'tukey'))
#> ======================================================================
#>   Factor Evaluated: genotype
#>   Simple Effects  : Sliced by 'temperature'
#>   P-value Adjustment: tukey
#>   Estimand         : estimated marginal means
#>   Significance (alpha): 0.05
#> 
#> 
#> Estimated Treatment Means & Significance Groups
#> ----------------------------------------------------------------------
#> temperature = Control_22C:
#>  genotype  emmean       SE   df lower.CL upper.CL Group
#>  G1       57.7625 2.273493 6.91 52.37172 63.15328 ab   
#>  G2       62.6475 2.273493 6.91 57.25672 68.03828 cd   
#>  G3       53.9975 2.273493 6.91 48.60672 59.38828 a    
#>  G4       65.7100 2.273493 6.91 60.31922 71.10078 c    
#>  G5       58.8800 2.273493 6.91 53.48922 64.27078 bd   
#> 
#> temperature = Heat_36C:
#>  genotype  emmean       SE   df lower.CL upper.CL Group
#>  G1       39.6300 2.273493 6.91 34.23922 45.02078 a    
#>  G2       44.3300 2.273493 6.91 38.93922 49.72078 b    
#>  G3       30.1300 2.273493 6.91 24.73922 35.52078 c    
#>  G4       56.9850 2.273493 6.91 51.59422 62.37578 d    
#>  G5       42.7325 2.273493 6.91 37.34172 48.12328 ab   
#> 
#> Degrees-of-freedom method: kenward-roger 
#> Confidence level used: 0.95 
#> 
#> Pairwise Contrasts & Differences
#> ----------------------------------------------------------------------
#>  contrast temperature estimate       SE df t.ratio p.value
#>  G1 - G2  Control_22C  -4.8850 1.545519 24  -3.161  0.0312
#>  G1 - G3  Control_22C   3.7650 1.545519 24   2.436  0.1400
#>  G1 - G4  Control_22C  -7.9475 1.545519 24  -5.142  0.0003
#>  G1 - G5  Control_22C  -1.1175 1.545519 24  -0.723  0.9491
#>  G2 - G3  Control_22C   8.6500 1.545519 24   5.597 <0.0001
#>  G2 - G4  Control_22C  -3.0625 1.545519 24  -1.982  0.3047
#>  G2 - G5  Control_22C   3.7675 1.545519 24   2.438  0.1395
#>  G3 - G4  Control_22C -11.7125 1.545519 24  -7.578 <0.0001
#>  G3 - G5  Control_22C  -4.8825 1.545519 24  -3.159  0.0314
#>  G4 - G5  Control_22C   6.8300 1.545519 24   4.419  0.0016
#>  G1 - G2  Heat_36C     -4.7000 1.545519 24  -3.041  0.0407
#>  G1 - G3  Heat_36C      9.5000 1.545519 24   6.147 <0.0001
#>  G1 - G4  Heat_36C    -17.3550 1.545519 24 -11.229 <0.0001
#>  G1 - G5  Heat_36C     -3.1025 1.545519 24  -2.007  0.2927
#>  G2 - G3  Heat_36C     14.2000 1.545519 24   9.188 <0.0001
#> 
#> Degrees-of-freedom method: kenward-roger 
#> P value adjustment: tukey method for comparing a family of 5 estimates 
#>   ... [Showing 15 of 20 comparisons]
#> 
#> ======================================================================
#>