srh.posthoc: Dunn post hoc in a symmetric matrix form (one specified...

View source: R/srh.posthoc.R

srh.posthocR Documentation

Dunn post hoc in a symmetric matrix form (one specified effect)

Description

Computes Dunn's rank-based pairwise comparisons for the effect implied by formula and returns symmetric matrices for Z, unadjusted p-values, and adjusted p-values. Cells on one triangle (or both) can be blanked for compact reporting. For multi-factor RHS, factors are combined into a single grouping via interaction() (e.g., "A:B" cells).

Usage

srh.posthoc(
  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 ~ factor or y ~ A + B (the latter is treated as one combined grouping via interaction).

data

A data.frame containing variables in formula.

method

P-value adjustment method passed to FSA::dunnTest(). Default "bonferroni". See p.adjust.methods for options.

digits

Number of digits for rounding in the returned matrices when numeric = FALSE. Default 3.

triangular

Which triangle to show ("lower", "upper", or "full"). Default "lower".

numeric

Logical; if TRUE, return numeric matrices/data frames with NA 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 (default TRUE).

sep

Separator used in interaction() when combining factors. Default ".".

Details

The function subsets to complete cases on y and RHS factors, optionally coerces factors, builds a single grouping variable (._grp) and calls FSA::dunnTest(y ~ ._grp, data = ..., method = ...). The pairwise results are placed into symmetric matrices Z, P.unadj, and P.adj. By default only the lower triangle (excluding diagonal) is shown for compactness.

Value

A list with three data.frames:

  • Z – Z statistics,

  • P.unadj – unadjusted p-values,

  • P.adj – adjusted p-values (per method).

The original call is attached as attribute "call".

Examples

data(mimicry, package = "factorH")

# One factor
ph1 <- srh.posthoc(liking ~ condition, data = mimicry)
ph1$`P.adj`    # gotowa macierz p po korekcji

# Two factors combined (all A:B cells vs all A:B cells)
ph2 <- srh.posthoc(liking ~ gender + condition, data = mimicry)
ph2$`P.adj`

# Upper triangle, numeric frames
ph3 <- srh.posthoc(liking ~ condition, data = mimicry,
                   triangular = "upper", numeric = TRUE)
ph3$Z


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