Skip to content

fix(cohens_f): pass generalized argument to underlying effect size call - #726

Open
soodoku wants to merge 1 commit into
easystats:mainfrom
finite-sample:fix/cohens-f-generalized
Open

soodoku wants to merge 1 commit into
easystats:mainfrom
finite-sample:fix/cohens-f-generalized

Conversation

@soodoku

@soodoku soodoku commented Nov 25, 2026

Copy link
Copy Markdown

Description

In cohens_f() (R/eta_squared-main.R:340-355), generalized = generalized is currently placed inside switch(method, ...) instead of in the f(...) call:

  f <- switch(
    method,
    eta = eta_squared,
    generalized = generalized,
    omega = omega_squared,
    epsilon = epsilon_squared
  )

  res <- f(
    model,
    partial = partial,
    ci = ci,
    alternative = alternative,
    verbose = verbose,
    ...
  )

Because method is matched against c("eta", "omega", "epsilon"), the generalized branch of switch() is unreachable and generalized is silently dropped. Both cohens_f(..., generalized = ...) and cohens_f_squared(..., generalized = ...) therefore return partial Cohen's f / f² instead of generalized Cohen's f / f².

Proposed Changes

  • R/eta_squared-main.R: move generalized = generalized out of switch(method, ...) into the f(...) call in cohens_f().
  • tests/testthat/test-eta_squared.R: add a regression test verifying that cohens_f(mod, generalized = "cyl_f") and cohens_f_squared(mod, generalized = "cyl_f") match eta2_to_f() / eta2_to_f2() applied to eta_squared(mod, generalized = "cyl_f") (both estimates and CI bounds).

Minimal Reproducible Example

df <- mtcars
df$am_f <- factor(df$am)
df$cyl_f <- factor(df$cyl)
mod <- aov(mpg ~ am_f * cyl_f, data = df)

cohens_f(mod, generalized = "cyl_f")
eta2_to_f(eta_squared(mod, generalized = "cyl_f")$Eta2_generalized)
  • Before (main):
    • cohens_f(mod, generalized = "cyl_f") returns Cohen's f (partial): c(1.30, 1.38, 0.33) (ignores generalized = "cyl_f").
  • After (this PR):
    • cohens_f(mod, generalized = "cyl_f") returns generalized Cohen's f: c(0.75, 1.31, 0.19), matching eta2_to_f(eta_squared(mod, generalized = "cyl_f")$Eta2_generalized) (0.7497, 1.3136, 0.1912).

Verification

  • testthat::test_file("tests/testthat/test-eta_squared.R"): all non-skipped tests passed (14 skipped due to skip_on_cran() / optional suggested packages {afex}, {lmerTest}), plus verified cohens_f(mod, method = "omega") and method = "epsilon" continue to work.
  • Revert check (reverting only R/eta_squared-main.R): 4 failures in test-eta_squared.R; restoring R/eta_squared-main.R returns to 0 failures.
  • Formatted with air style and checked with lintr (0 lints in touched lines).

This PR was assisted by Gemini 4 Neon via Antigravity CLI; I have reviewed and verified the change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant