Learn R Programming

factorH (version 0.5.0)

srh.kway: K-way SRH on ranks with tie-corrected p-values and rank-based effect sizes

Description

Generalizes the Scheirer–Ray–Hare (SRH) approach to k-factor designs by using sums of squares from a linear model on ranks, with a standard tie correction \(D\) applied to p-values. The function returns H, tie-corrected H (Hadj), \(p\)-values and rank-based effect sizes (eta2H, eps2H) for each main effect and interaction up to the full order (i.e., (A + B + ...)^k).

Usage

srh.kway(formula, data, clamp0 = TRUE, force_factors = TRUE, type = 2, ...)

Value

A data.frame with class c("srh_kway","anova","data.frame")

containing columns: Effect, Df, Sum Sq, H, Hadj, p.chisq, k, n, eta2H, eps2H. The original call is attached as an attribute and can be retrieved with getCall().

Arguments

formula

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

data

A data.frame with the variables in formula.

clamp0

Logical; if TRUE (default), negative eta2H is truncated to 0 and eps2H truncated to the interval \([0, 1]\).

force_factors

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

type

Integer; the SS type to use in car::Anova. Defaults to 2 (Type II). Set type = 3 for Type III (internally uses sum-to-zero contrasts for factors in the model fit; global options are not modified).

...

Passed to stats::lm() if applicable.

Details

Ranks are computed globally on y with ties.method = "average". Sums of squares are obtained from car::Anova() on the rank model R ~ (A + B + ...)^k. Tie correction: $$D = 1 - \frac{\sum (t^3 - t)}{n^3 - n},$$ where \(t\) are tie block sizes and \(n\) is the number of complete cases. We report Hadj = H / D and \(p = P(\chi^2_{df} \ge Hadj)\).

Rank-based effect sizes are computed from the uncorrected H (classical SRH convention): eta2H = (H - k + 1) / (n - k) and eps2H = H * (n + 1) / (n^2 - 1), where k is the number of non-empty groups compared by the term.

For type = 3, the model is fitted with sum-to-zero contrasts (stats::contr.sum) for RHS factors having at least 2 levels, so that Type III tests have the standard interpretation. Global contrast options are not altered.

See Also

Examples

Run this code
if (FALSE) {
data(mimicry, package = "factorH")
# One factor (KW-style check)
srh.kway(liking ~ condition, data = mimicry)

# Two factors (Type II by default)
srh.kway(liking ~ gender + condition, data = mimicry)

# Three factors
srh.kway(liking ~ gender + condition + age_cat, data = mimicry)

# Type III SS (with sum-to-zero contrasts set locally)
srh.kway(liking ~ gender + condition, data = mimicry, type = 3)
}

Run the code above in your browser using DataLab