srh.posthocs: Dunn post hoc tables (p.adj only) for all effects in a...

View source: R/srh.posthocs.R

srh.posthocsR Documentation

Dunn post hoc tables (p.adj only) for all effects in a factorial design

Description

For a given y ~ A (+ B + ...) formula, runs srh.posthoc for every main effect and interaction implied by the RHS (all non-empty combinations of factors) and returns a named list of adjusted p-value matrices (P.adj) for each effect.

Usage

srh.posthocs(
  formula,
  data,
  method = "bonferroni",
  digits = 3,
  triangular = c("lower", "upper", "full"),
  numeric = FALSE,
  force_factors = TRUE,
  sep = "."
)

Arguments

formula

A formula of the form y ~ A (+ B + ...).

data

A data.frame containing variables in formula.

method

P-value adjustment method passed to FSA::dunnTest() via srh.posthoc. Default "bonferroni".

digits

Rounding used inside srh.posthoc when numeric = FALSE. Default 3.

triangular

Which triangle to show in each matrix ("lower", "upper", "full"). Default "lower".

numeric

Logical; if TRUE, return numeric data frames with NAs on the masked triangle/diagonal; if FALSE (default), return character data frames with masked cells as empty strings.

force_factors

Logical; coerce grouping variables to factor before analysis (default TRUE).

sep

Separator for combined factor labels when needed (passed through to srh.posthoc). Default ".".

Details

The function enumerates all non-empty subsets of RHS factors (mains, 2-way, ..., k-way) and calls srh.posthoc on each corresponding sub-formula. If a subset has fewer than 2 observed levels (e.g., due to missing data after subsetting to complete cases), that effect is skipped.

Value

A named list where each element is a data.frame of adjusted p-values (P.adj) for an effect. Names use "A", "B", "A:B", ..., matching the effect structure. The original call is attached as attribute "call".

Examples

data(mimicry, package = "factorH")

# Two-factor design: p.adj for 'gender', 'condition', and 'gender:condition'
L2 <- srh.posthocs(liking ~ gender + condition, data = mimicry)
names(L2)
L2$gender
L2$condition
L2$`gender:condition`

# Three-factor design: includes mains, all 2-ways, and the 3-way effect
L3 <- srh.posthocs(liking ~ gender + condition + age_cat, data = mimicry)
names(L3)


factorH documentation built on Sept. 11, 2025, 9:09 a.m.