CAssociation · association.eta
Correlation ratio η and point-biserial r
How strongly is a numeric variable associated with a categorical one?
The correlation ratio η (and η², ω², ε² with a noncentral-F interval for η²) measuring how much of a numeric variable's variance lies between the groups of a categorical one, with the F test; for two groups also the point-biserial correlation (signed: positive when the second group is higher).
A real result
Example “Iris three groups”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
η² = .62, 95% CI [.52, .68], F(2, 147) = 119.26, p < .001
- η
- 0.7866
- η²
- 0.6187
- F
- 119.26
- p
- < .001
Effect size
- η² 0.6187 95% CI [0.5203, 0.6844]
- ω² 0.6119
- η 0.7866
Plots
View data
| Species | Sepal.Length |
|---|---|
| setosa | 5.100 |
| setosa | 4.900 |
| setosa | 4.700 |
| setosa | 4.600 |
| setosa | 5 |
| setosa | 5.400 |
| setosa | 4.600 |
| setosa | 5 |
| setosa | 4.400 |
| setosa | 4.900 |
| setosa | 5.400 |
| setosa | 4.800 |
| setosa | 4.800 |
| setosa | 4.300 |
| setosa | 5.800 |
| setosa | 5.700 |
| setosa | 5.400 |
| setosa | 5.100 |
| setosa | 5.700 |
| setosa | 5.100 |
| setosa | 5.400 |
| setosa | 5.100 |
| setosa | 4.600 |
| setosa | 5.100 |
| setosa | 4.800 |
| setosa | 5 |
| setosa | 5 |
| setosa | 5.200 |
| setosa | 5.200 |
| setosa | 4.700 |
| setosa | 4.800 |
| setosa | 5.400 |
| setosa | 5.200 |
| setosa | 5.500 |
| setosa | 4.900 |
| setosa | 5 |
| setosa | 5.500 |
| setosa | 4.900 |
| setosa | 4.400 |
| setosa | 5.100 |
| setosa | 5 |
| setosa | 4.500 |
| setosa | 4.400 |
| setosa | 5 |
| setosa | 5.100 |
| setosa | 4.800 |
| setosa | 5.100 |
| setosa | 4.600 |
| setosa | 5.300 |
| setosa | 5 |
| versicolor | 7 |
| versicolor | 6.400 |
| versicolor | 6.900 |
| versicolor | 5.500 |
| versicolor | 6.500 |
| versicolor | 5.700 |
| versicolor | 6.300 |
| versicolor | 4.900 |
| versicolor | 6.600 |
| versicolor | 5.200 |
First 60 of 150 rows.
Assumptions
- Normality within groups — Shapiro–Wilk p ≥ .05 in every group (groups with fewer than 3 values are not tested).
- Equal variances — Brown–Forsythe F = 6.35, p = .002.
Descriptives
| Species | n | Mean | SD |
|---|---|---|---|
| setosa | 50 | 5.006 | 0.3525 |
| versicolor | 50 | 5.936 | 0.5162 |
| virginica | 50 | 6.588 | 0.6359 |
- η² = SSbetween / SStotal (3 groups); ε² and ω² correct its upward bias; the η² interval is two-sided.
η² = .62, 95% CI [.52, .68], F(2, 147) = 119.26, p < .001
- η
- 0.7866
- η²
- 0.6187
- F
- 119.26
- p
- < .001
Effect size
- η² 0.6187 95% CI [0.5203, 0.6844]
- ω² 0.6119
- η 0.7866
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Normality within groups — Shapiro–Wilk p ≥ .05 in every group (groups with fewer than 3 values are not tested).
- Equal variances — Brown–Forsythe F = 6.35, p = .002.
Descriptives
| Species | n | Mean | SD |
|---|---|---|---|
| setosa | 50 | 5.006 | 0.3525 |
| versicolor | 50 | 5.936 | 0.5162 |
| virginica | 50 | 6.588 | 0.6359 |
- η² = SSbetween / SStotal (3 groups); ε² and ω² correct its upward bias; the η² interval is two-sided.
Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.
Worked examples in the app
- Iris three groupsiris · group: Species · outcome: Sepal.Length
- Two groups booleanmtcars · group: manual · outcome: mpg
- Missing valuesairquality · group: month_f · outcome: Ozone
- Weak effectwarpbreaks · group: wool · outcome: breaks
- Degenerate constantiris · group: Species · outcome: Sepal.Length
- Degenerate single leveliris · group: Species · outcome: Sepal.Length
In the guides
Where it sits in the decision guides
- Continuous–categorical: point-biserial, η · Statistics Guide · C — Test association
- EDA (correlation, distributions) · DS & ML Decision Guide · Describe — summarize and visualize
- Correlation analysis (Pearson, Spearman) · DS & ML Decision Guide · Explain — why is it happening?
What you need
- Numeric variablenumeric · 1 column
- The numeric variable whose spread is explained by the categories.
- Categorical variablecategorical / boolean · 1 column · 2–50 levels
- The categorical variable.
Choices you make
hypothesis
- Confidence leveldefault 0.95
How sure the intervals should be: 0.95 gives 95% confidence intervals. Higher confidence means wider intervals.
Checks and remedies
CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.
Normality within groups
Needed only for the F test's p-value and the η² interval; η itself is descriptive.
- If violated → Kruskal–Wallis test — Rank-based test of the same association that does not assume normal groups. Changes the question: Tests whether one group tends to have larger values (ranks), not whether means differ.
Equal variances (Brown–Forsythe)
What it reports
- Tests: Association (F test)
- eta
- How strongly a numeric outcome depends on a categorical variable, allowing any pattern across its levels.
- eta2
- The share of total variance explained by an effect in ANOVA; biased upward in small samples.
- eta2_ci_low
- A range of effect values compatible with your data at the chosen confidence level.
- eta2_ci_high
- A range of effect values compatible with your data at the chosen confidence level.
- omega2
- A less biased version of η²; preferred for reporting how much variance an effect explains.
- epsilon2
- A bias-adjusted variance-explained measure; for Kruskal–Wallis it is computed from the ranks.
- cohens_f
- The ratio of explained to unexplained variance, used by ANOVA and regression tests.
- f_stat
- The ratio of explained to unexplained variance, used by ANOVA and regression tests.
- df1
- How much independent information is left to estimate variability after fitting the model.
- df2
- How much independent information is left to estimate variability after fitting the model.
- p
- How surprising your data would be if the null hypothesis were true, as a probability.
- n
- How many independent units the analysis used; it sets precision and power.
- k
- How many groups, studies or clusters the analysis used. Many methods are less reliable when k is small.
- bf_p
- How surprising your data would be if the null hypothesis were true, as a probability.
- missing_share
- Values that were not recorded; how they went missing decides which fixes are safe.
Per group, level or term: r_pb, r_pb_ci_low, r_pb_ci_high, level_1, level_2
Python and R
Python and R agree to 6 decimals (relative tolerance 1e-9). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.
Default traps between the two languages
- The η² interval inverts the noncentral F: scipy (Boost) and R's pnbeta agree to ~1e-8, so the bounds agree to ~1e-7.
The exact script CodeSplash ran for example “Iris three groups” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Correlation ratio η and point-biserial r
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method association.eta 1.0.1 · spec ddbaec91382d309b
# Dataset: iris (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
from scipy import stats
import codesplash as cs
from codesplash.stats import correlation as cscor
# %% Data
df = pd.read_parquet("tests/parity/fixtures/iris.parquet", columns=["Sepal.Length", "Species"])
n_input = len(df)
df["Species"] = pd.Categorical(df["Species"], categories=["setosa", "versicolor", "virginica"]) # stored level order
df = df.dropna(subset=["Sepal.Length", "Species"]) # listwise deletion over the analysis columns
df["Species"] = df["Species"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["Sepal.Length", "Species"]) # infinite values stop the run (registry/errors.yaml)
# %% Correlation ratio
y, g = "Sepal.Length", "Species"
conf = 0.95
levels = list(df[g].cat.categories)
k = len(levels)
if k < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=g, min=2, k=k)
values_y = df[y].to_numpy(dtype=float)
groups = [df.loc[df[g] == lv, y].to_numpy(dtype=float) for lv in levels]
n = len(values_y)
if n <= k: # no residual degrees of freedom
cs.cs_error("CS_E_TOO_FEW_ROWS", what="The correlation ratio", min=k + 1, n=n)
if len(np.unique(values_y)) < 2: # η² = between / total sum of squares is 0 / 0
cs.cs_error("CS_E_CONSTANT", column=y)
grand = values_y.mean()
ss_total = float(np.sum((values_y - grand) ** 2))
ss_between = float(sum(len(x) * (x.mean() - grand) ** 2 for x in groups))
ss_within = ss_total - ss_between
df1, df2 = k - 1, n - k
ms_within = ss_within / df2
f_stat = (ss_between / df1) / ms_within
p = float(stats.f.sf(f_stat, df1, df2))
eta2 = ss_between / ss_total
eta = float(np.sqrt(eta2))
omega2 = (ss_between - df1 * ms_within) / (ss_total + ms_within)
epsilon2 = (ss_between - df1 * ms_within) / ss_total
cohens_f = float(np.sqrt(eta2 / (1 - eta2)))
lam_low, lam_high = cscor.noncentral_f_ci(f_stat, df1, df2, conf) # η² = λ / (λ + N) (Steiger 2004)
eta2_low, eta2_high = lam_low / (lam_low + n), lam_high / (lam_high + n)
values = {}
if k == 2:
# point-biserial: Pearson r between the values and membership of the second group
ind = (df[g] == levels[1]).to_numpy(dtype=float)
pb = stats.pearsonr(values_y, ind)
ci = pb.confidence_interval(confidence_level=conf)
values.update({"r_pb": float(pb.statistic), "r_pb_ci_low": float(ci.low), "r_pb_ci_high": float(ci.high),
"level_1": str(levels[0]), "level_2": str(levels[1])})
# %% Assumptions
assumptions = []
sw = [stats.shapiro(x) if 3 <= len(x) <= 5000 else None for x in groups]
bad = [str(lv) for lv, s in zip(levels, sw) if s is not None and s.pvalue < 0.05]
small = min(len(x) for x in groups) < 30
status = "warn" if bad and small else ("info" if bad or any(s is None for s in sw) else "pass")
assumptions.append({"key": "normality", "label": "Normality within groups", "status": status,
"detail": (f"Shapiro–Wilk p < .05 in {', '.join(bad)}" + (" with fewer than 30 values: the F test's p-value may be off." if small else "; with 30 or more values per group the F test is robust."))
if bad else "Shapiro–Wilk p ≥ .05 in every group (groups with fewer than 3 values are not tested)."})
bf = stats.levene(*groups, center="median") # Brown–Forsythe
assumptions.append({"key": "equal_variance", "label": "Equal variances", "status": "warn" if bf.pvalue < 0.05 else "pass",
"statistic": float(bf.statistic), "p": float(bf.pvalue),
"detail": f"Brown–Forsythe F = {bf.statistic:.2f}, {cs.fmt_p(bf.pvalue)}."})
# %% Result
summary = (
f"{g} accounts for {eta2:.1%} of the variance in {y} (η² = {eta2:.3f}, {conf:.0%} CI [{eta2_low:.3f}, {eta2_high:.3f}]); "
f"F({df1}, {df2}) = {f_stat:.2f}, {cs.fmt_p(p)}."
)
descriptives = [{"group": str(lv), "n": len(x), "mean": float(x.mean()), "sd": float(x.std(ddof=1)) if len(x) > 1 else None} for lv, x in zip(levels, groups)]
chart_rows = np.unique(np.round(np.linspace(0, n - 1, min(n, 5000))).astype(int))
effect_sizes = [
{"key": "eta2", "label": "η²", "value": eta2, "ciLow": eta2_low, "ciHigh": eta2_high, "ciLevel": conf, "method": "SSbetween / SStotal; noncentral-F interval"},
{"key": "omega2", "label": "ω²", "value": float(omega2), "method": "less biased population estimate"},
{"key": "eta", "label": "η", "value": eta, "method": "√η²"},
]
if k == 2:
effect_sizes.append({"key": "r_pb", "label": "Point-biserial r", "value": values["r_pb"], "ciLow": values["r_pb_ci_low"],
"ciHigh": values["r_pb_ci_high"], "ciLevel": conf, "method": f"{levels[1]} vs {levels[0]}, Fisher z interval"})
values.update({"eta": eta, "eta2": eta2, "eta2_ci_low": eta2_low, "eta2_ci_high": eta2_high, "omega2": float(omega2),
"epsilon2": float(epsilon2), "cohens_f": cohens_f, "f_stat": float(f_stat), "df1": float(df1), "df2": float(df2),
"p": p, "n": n, "k": k, "bf_p": float(bf.pvalue), "missing_share": n_dropped / n_input if n_input else 0.0})
cs.publish({
"method": "association.eta",
"methodVersion": "1.0.1",
"title": "Correlation ratio (η)",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n,
"summary": summary,
"apa": f"η² = {cs.fmt_num(eta2, leading_zero=False)}, {conf:.0%} CI [{cs.fmt_num(eta2_low, leading_zero=False)}, {cs.fmt_num(eta2_high, leading_zero=False)}], F({df1}, {df2}) = {cs.fmt_num(f_stat)}, {cs.fmt_p(p)}",
"statistics": [{"key": "eta", "label": "η", "value": eta}, {"key": "eta2", "label": "η²", "value": eta2},
{"key": "f_stat", "label": "F", "value": float(f_stat)}, {"key": "p", "label": "p", "value": p, "format": "p"}],
"tables": [{"key": "descriptives", "title": "Descriptives", "columns": [
{"key": "group", "label": g, "type": "string"}, {"key": "n", "label": "n", "type": "integer"},
{"key": "mean", "label": "Mean", "type": "number"}, {"key": "sd", "label": "SD", "type": "number"}], "rows": descriptives}],
"effectSizes": effect_sizes,
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"η² = SSbetween / SStotal ({k} groups); ε² and ω² correct its upward bias; the η² interval is two-sided."],
"charts": [cs.chart("distribution", "raincloud", f"{y} by {g}", {
"y": cs.col(y, values_y[chart_rows]), "group": cs.col(g, df[g].astype(str).to_numpy()[chart_rows], levels=[str(x) for x in levels])})],
"values": values,
})
The exact script CodeSplash ran for example “Iris three groups” · R version 4.5.1 (2025-06-13)
# Correlation ratio η and point-biserial r
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method association.eta 1.0.1 · spec ddbaec91382d309b
# Dataset: iris (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/iris.parquet", col_select = c("Sepal.Length", "Species")))
n_input <- nrow(df)
df[["Species"]] <- factor(df[["Species"]], levels = c("setosa", "versicolor", "virginica")) # stored level order
df <- df[stats::complete.cases(df[c("Sepal.Length", "Species")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("Sepal.Length", "Species")) # infinite values stop the run (registry/errors.yaml)
# %% Correlation ratio
y <- "Sepal.Length"
g <- "Species"
conf <- 0.95
levels_g <- levels(df[[g]])
k <- length(levels_g)
if (k < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = g, min = 2, k = k)
values_y <- df[[y]]
groups <- lapply(levels_g, function(lv) df[[y]][df[[g]] == lv])
n <- length(values_y)
if (n <= k) cs_error("CS_E_TOO_FEW_ROWS", what = "The correlation ratio", min = k + 1, n = n) # no residual degrees of freedom
if (length(unique(values_y)) < 2) cs_error("CS_E_CONSTANT", column = y) # eta^2 = between / total sum of squares is 0 / 0
grand <- mean(values_y)
ss_total <- sum((values_y - grand)^2)
ss_between <- sum(vapply(groups, function(x) length(x) * (mean(x) - grand)^2, 0))
ss_within <- ss_total - ss_between
df1 <- k - 1
df2 <- n - k
ms_within <- ss_within / df2
f_stat <- (ss_between / df1) / ms_within
p <- pf(f_stat, df1, df2, lower.tail = FALSE)
eta2 <- ss_between / ss_total
eta <- sqrt(eta2)
omega2 <- (ss_between - df1 * ms_within) / (ss_total + ms_within)
epsilon2 <- (ss_between - df1 * ms_within) / ss_total
cohens_f <- sqrt(eta2 / (1 - eta2))
lam <- cs_noncentral_f_ci(f_stat, df1, df2, conf) # eta^2 = lambda / (lambda + N) (Steiger 2004)
eta2_low <- lam[1] / (lam[1] + n)
eta2_high <- lam[2] / (lam[2] + n)
values <- list()
if (k == 2) {
# point-biserial: Pearson r between the values and membership of the second group
pb <- cor.test(values_y, as.numeric(df[[g]] == levels_g[2]), conf.level = conf)
values <- list(r_pb = unname(pb$estimate), r_pb_ci_low = pb$conf.int[1], r_pb_ci_high = pb$conf.int[2],
level_1 = levels_g[1], level_2 = levels_g[2])
}
# %% Assumptions
assumptions <- list()
sw <- lapply(groups, function(x) if (length(x) >= 3 && length(x) <= 5000) shapiro.test(x) else NULL)
bad <- levels_g[vapply(sw, function(s) !is.null(s) && s$p.value < 0.05, logical(1))]
small <- min(lengths(groups)) < 30
status <- if (length(bad) && small) "warn" else if (length(bad) || any(vapply(sw, is.null, logical(1)))) "info" else "pass"
assumptions[[1]] <- list(key = "normality", label = "Normality within groups", status = status,
detail = if (length(bad)) paste0(sprintf("Shapiro–Wilk p < .05 in %s", paste(bad, collapse = ", ")),
if (small) " with fewer than 30 values: the F test's p-value may be off." else "; with 30 or more values per group the F test is robust.")
else "Shapiro–Wilk p ≥ .05 in every group (groups with fewer than 3 values are not tested).")
# Brown-Forsythe: one-way ANOVA on absolute deviations from the group medians
dev <- unlist(lapply(groups, function(x) abs(x - median(x))))
grp <- factor(rep(seq_along(groups), lengths(groups)))
bf_tab <- anova(lm(dev ~ grp))
bf_f <- bf_tab[["F value"]][1]
bf_p <- bf_tab[["Pr(>F)"]][1]
assumptions[[2]] <- list(key = "equal_variance", label = "Equal variances", status = if (bf_p < 0.05) "warn" else "pass",
statistic = bf_f, p = bf_p, detail = sprintf("Brown–Forsythe F = %.2f, %s.", bf_f, cs_fmt_p(bf_p)))
# %% Result
pct <- sprintf("%.0f%%", conf * 100)
summary <- sprintf("%s accounts for %.1f%% of the variance in %s (η² = %.3f, %s CI [%.3f, %.3f]); F(%d, %d) = %.2f, %s.",
g, eta2 * 100, y, eta2, pct, eta2_low, eta2_high, df1, df2, f_stat, cs_fmt_p(p))
descriptives <- lapply(seq_along(levels_g), function(i) {
x <- groups[[i]]
list(group = levels_g[i], n = length(x), mean = mean(x), sd = if (length(x) > 1) sd(x) else NULL)
})
chart_rows <- unique(round(seq(1, n, length.out = min(n, 5000))))
effect_sizes <- list(
list(key = "eta2", label = "η²", value = eta2, ciLow = eta2_low, ciHigh = eta2_high, ciLevel = conf, method = "SSbetween / SStotal; noncentral-F interval"),
list(key = "omega2", label = "ω²", value = omega2, method = "less biased population estimate"),
list(key = "eta", label = "η", value = eta, method = "√η²")
)
if (k == 2) {
effect_sizes[[4]] <- list(key = "r_pb", label = "Point-biserial r", value = values$r_pb, ciLow = values$r_pb_ci_low,
ciHigh = values$r_pb_ci_high, ciLevel = conf, method = sprintf("%s vs %s, Fisher z interval", levels_g[2], levels_g[1]))
}
values <- c(values, list(eta = eta, eta2 = eta2, eta2_ci_low = eta2_low, eta2_ci_high = eta2_high, omega2 = omega2,
epsilon2 = epsilon2, cohens_f = cohens_f, f_stat = f_stat, df1 = df1, df2 = df2, p = p, n = n, k = k, bf_p = bf_p, missing_share = if (n_input > 0) n_dropped / n_input else 0))
cs_publish(list(
method = "association.eta",
methodVersion = "1.0.1",
title = "Correlation ratio (η)",
engine = cs_engine_info("stats", "nanoparquet"),
n = n,
summary = summary,
apa = sprintf("η² = %s, %s CI [%s, %s], F(%d, %d) = %s, %s", cs_fmt_num(eta2, leading_zero = FALSE), pct, cs_fmt_num(eta2_low, leading_zero = FALSE),
cs_fmt_num(eta2_high, leading_zero = FALSE), df1, df2, cs_fmt_num(f_stat), cs_fmt_p(p)),
statistics = list(list(key = "eta", label = "η", value = eta), list(key = "eta2", label = "η²", value = eta2),
list(key = "f_stat", label = "F", value = f_stat), list(key = "p", label = "p", value = p, format = "p")),
tables = list(list(key = "descriptives", title = "Descriptives", columns = list(
list(key = "group", label = g, type = "string"), list(key = "n", label = "n", type = "integer"),
list(key = "mean", label = "Mean", type = "number"), list(key = "sd", label = "SD", type = "number")), rows = descriptives)),
effectSizes = effect_sizes,
assumptions = assumptions,
warnings = warnings,
notes = list(sprintf("η² = SSbetween / SStotal (%d groups); ε² and ω² correct its upward bias; the η² interval is two-sided.", k)),
charts = list(cs_chart("distribution", "raincloud", sprintf("%s by %s", y, g), list(
y = cs_col(y, values_y[chart_rows]), group = cs_col(g, as.character(df[[g]][chart_rows]), levels = levels_g)))),
values = values
))
Sources
- Steiger, J. H. (2004). Beyond the F test: Effect size confidence intervals and tests of close fit in the analysis of variance and contrast analysis. Psychological Methods, 9, 164–182.
- Olejnik, S., & Algina, J. (2003). Generalized eta and omega squared statistics. Psychological Methods, 8, 434–447.
From the CodeSplash method registry · association.eta v1.0.1.