BCompare groups · robust.trimmed_anova
Trimmed-means ANOVA (Welch-type, robust)
Do three or more independent groups differ in their trimmed means when tails are heavy or spreads differ?
Wilcox's heteroscedastic one-way ANOVA on 20% trimmed means (WRS2 t1way): resists outliers and heavy tails and does not assume equal variances. Reports the explanatory effect size ξ, an optional bootstrap-t p-value, and pairwise Yuen–Welch comparisons with adjusted p and simultaneous intervals.
A real result
Example “Guide”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
F_t(2, 21.34) = 7.29, p = .004, ξ = .55
- F_t
- 7.289
- df1
- 2
- df2
- 21.342
- p
- .004
Effect size
- ξ (explanatory) 0.5498
Plots
View data
| group | value |
|---|---|
| A | 0.5206 |
| A | −1.080 |
| A | 0.1392 |
| A | −0.0847 |
| A | −0.6666 |
| A | −2.516 |
| A | −0.7351 |
| A | −1.020 |
| A | 0.1136 |
| A | −0.4738 |
| A | −0.4082 |
| A | −0.7304 |
| A | −0.2214 |
| A | −0.2258 |
| A | −2.547 |
| A | 1.347 |
| A | 0.6164 |
| A | 0.2176 |
| A | −0.8047 |
| A | 0.6897 |
| B | 0.0713 |
| B | 0.2353 |
| B | −0.9920 |
| B | 1.866 |
| B | 0.4482 |
| B | 2.308 |
| B | 2.131 |
| B | 0.4581 |
| B | 1.045 |
| B | 2.126 |
| B | −0.1290 |
| B | 0.5664 |
| B | 0.1453 |
| B | 0.7328 |
| B | 0.5824 |
| B | 1.565 |
| B | 0.9935 |
| B | −0.4918 |
| B | 0.9773 |
| B | −0.4249 |
| C | −0.3573 |
| C | 1.578 |
| C | −0.4042 |
| C | 1.107 |
| C | −0.0337 |
| C | 2.218 |
| C | 1.512 |
| C | 0.3975 |
| C | 1.599 |
| C | 1.226 |
| C | −0.3699 |
| C | 0.5938 |
| C | −0.1306 |
| C | 1.249 |
| C | 0.1552 |
| C | 0.5686 |
| C | −0.4364 |
| C | −0.1610 |
| C | 0.9340 |
| C | −0.1991 |
View data
| Difference in value | CI high | Comparison | CI low |
|---|---|---|---|
| 0.9751 | 1.703 | B-A | 0.2476 |
| 0.7990 | 1.561 | C-A | 0.0368 |
| −0.1761 | 0.6760 | C-B | −1.028 |
Assumptions
- Enough values after trimming — 12 to 12 values per group remain after trimming 20% from each tail.
- Independent groups — Each row belongs to one group; use a repeated-measures method for paired data.
Descriptives (20% trimming)
| group | n | Retained | Trimmed mean | Mean | Winsorized SD |
|---|---|---|---|---|---|
| A | 20 | 12 | −0.3234 | −0.3935 | 0.4343 |
| B | 20 | 12 | 0.6517 | 0.7107 | 0.5924 |
| C | 20 | 12 | 0.4756 | 0.5523 | 0.6323 |
Pairwise trimmed-mean comparisons (Holm-adjusted p)
| Comparison | Difference | t | df | 95% simultaneous CI low | 95% simultaneous CI high | p (adjusted) |
|---|---|---|---|---|---|---|
| B-A | 0.9751 | 3.499 | 20.174 | 0.2476 | 1.703 | .007 |
| C-A | 0.7990 | 2.745 | 19.488 | 0.0368 | 1.561 | .025 |
| C-B | −0.1761 | −0.5357 | 21.907 | −1.028 | 0.6760 | .598 |
- 20% trimmed from each tail; Welch-type heteroscedastic F (Wilcox 2017, §7.4.1). Pairwise comparisons are later − earlier level (Yuen–Welch tests with Bonferroni simultaneous intervals).
F_t(2, 21.34) = 7.29, p = .004, ξ = .55
- F_t
- 7.289
- df1
- 2
- df2
- 21.342
- p
- .004
Effect size
- ξ (explanatory) 0.5498
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Enough values after trimming — 12 to 12 values per group remain after trimming 20% from each tail.
- Independent groups — Each row belongs to one group; use a repeated-measures method for paired data.
Descriptives (20% trimming)
| group | n | Retained | Trimmed mean | Mean | Winsorized SD |
|---|---|---|---|---|---|
| A | 20 | 12 | −0.3234 | −0.3935 | 0.4343 |
| B | 20 | 12 | 0.6517 | 0.7107 | 0.5924 |
| C | 20 | 12 | 0.4756 | 0.5523 | 0.6323 |
Pairwise trimmed-mean comparisons (Holm-adjusted p)
| Comparison | Difference | t | df | 95% simultaneous CI low | 95% simultaneous CI high | p (adjusted) |
|---|---|---|---|---|---|---|
| B-A | 0.9751 | 3.499 | 20.174 | 0.2476 | 1.703 | .007 |
| C-A | 0.7990 | 2.745 | 19.488 | 0.0368 | 1.561 | .025 |
| C-B | −0.1761 | −0.5357 | 21.907 | −1.028 | 0.6760 | .598 |
- 20% trimmed from each tail; Welch-type heteroscedastic F (Wilcox 2017, §7.4.1). Pairwise comparisons are later − earlier level (Yuen–Welch tests with Bonferroni simultaneous intervals).
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
- Guidea_hetero3 · group: group · outcome: value
- Unequal bootstrapa_hetero3_unequal · group: group · outcome: value
- Chickwts 10pctchickwts · group: feed · outcome: weight
- Missing valuesairquality · group: month_f · outcome: Ozone
- Degenerate constanta_hetero3 · group: group · outcome: value
- Degenerate single levela_hetero3 · group: group · outcome: value
In the guides
Tests from the statistics guide this method runs
Where it sits in the decision guides
- More than two independent groups: one-way ANOVA, Kruskal–Wallis · Statistics Guide · B — Compare groups
- Robust, permutation and exact methods · Statistics Guide · Step 3 — If assumptions are violated
- Non-parametric alternatives · Statistics Guide · Additional considerations
What you need
- Outcomenumeric · 1 column
- The numeric variable whose trimmed means are compared.
- Groupscategorical / boolean · 1 column · 2–30 levels
- Two or more independent groups (with two groups this is Yuen's test, F = t²).
Choices you make
options
- Trimming proportion (each tail)default 0.2
0.2 (20%) is the usual choice; 0 gives Welch's ANOVA. Choose it before seeing the data.
- Bootstrap-t p-valuedefault off
Also report Wilcox's bootstrap-t p (t1waybt): resamples each group centered on its trimmed mean; better with small groups.
- Bootstrap resamplesdefault 599
599 is Wilcox's default; more resamples give a steadier p.
hypothesis
- Confidence leveldefault 0.95
How sure the intervals should be: 0.95 gives 95% confidence intervals. Higher confidence means wider intervals.
posthoc
- Pairwise comparisonsdefault on
Yuen–Welch tests for every pair of groups (Wilcox's lincon statistics).
- Adjust pairwise p-valuesdefault holm
How p-values are corrected for making several comparisons. Holm limits any false alarm; BH limits the share of false discoveries.
- Holm(default) — Step-down; controls the familywise error rate and is never less powerful than Bonferroni.
- Hochberg — Step-up; a little more powerful than Holm under independence or positive dependence.
- Bonferroni — Multiplies each p by the number of comparisons; the simplest, most conservative.
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.
Enough values after trimming
Each group needs at least two values left after trimming; five or more is better.
Independent groups
Each row belongs to one group.
What it reports
- Tests: Differences among trimmed means
- f
- 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.
- k
- How many groups, studies or clusters the analysis used. Many methods are less reliable when k is small.
- n
- How many independent units the analysis used; it sets precision and power.
- trim
- The mean after dropping a fixed share of the smallest and largest values (often 20% each side).
- xi
- A robust effect size for trimmed means: how much of the outcome's spread the groups account for.
- p_boot
- How surprising your data would be if the null hypothesis were true, as a probability.
- n_boot
- How many independent units the analysis used; it sets precision and power.
- missing_share
- Values that were not recorded; how they went missing decides which fixes are safe.
Per group, level or term: tm[<level>], diff[<later>-<earlier>], p_adj[…], ci_low[…], ci_high[…]
Python and R
Python and R agree to 10 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.
Default traps between the two languages
- Twin of WRS2 t1way (codesplash.stats.means.t1way ↔ cs_t1way); equals statsmodels anova_oneway(use_var='unequal', trim_frac=).
- With unequal group sizes ξ is the median over 100 equal-size subsamples drawn on the shared Wichmann–Hill stream; WRS2 draws them with R's generator (set.seed(2)), so it agrees only approximately there.
- Pairwise intervals are Bonferroni simultaneous Yuen–Welch intervals; WRS2 lincon uses studentized-maximum-modulus critical values (slightly narrower).
The exact script CodeSplash ran for example “Guide” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Trimmed-means ANOVA (Welch-type, robust)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method robust.trimmed_anova 1.0.1 · spec 63b17819fe380143
# Dataset: a_hetero3 (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 means as csm
from codesplash.stats.robust import trim_mean, winsorize
# %% Data
df = pd.read_parquet("tests/parity/fixtures/a_hetero3.parquet", columns=["value", "group"])
n_input = len(df)
df["group"] = pd.Categorical(df["group"], categories=["A", "B", "C"]) # stored level order
df = df.dropna(subset=["value", "group"]) # listwise deletion over the analysis columns
df["group"] = df["group"].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, ["value", "group"]) # infinite values stop the run (registry/errors.yaml)
# %% Test
y, g = "value", "group"
levels = [str(lv) for lv in df[g].cat.categories]
k = len(levels)
if k < 2:
cs.cs_error("CS_E_TOO_FEW_GROUPS", column=g, min=2, k=k)
groups = [df.loc[df[g] == lv, y].to_numpy(dtype=float) for lv in df[g].cat.categories]
ns = [len(x) for x in groups]
N = int(sum(ns))
trim = 0.2 # proportion trimmed from each tail
if len(np.unique(df[y].to_numpy(dtype=float))) < 2: # no variation: every trimmed-mean variance is 0
cs.cs_error("CS_E_CONSTANT", column=y)
for lv, x in zip(levels, groups):
if len(x) < 2:
cs.cs_error("CS_E_SMALL_GROUP", min=2, group=f"{g} = {lv}", n=len(x))
if len(x) - 2 * int(np.floor(trim * len(x))) < 2:
cs.cs_error("CS_E_UNDEFINED", what="The trimmed-means ANOVA", reason="each group needs at least two values left after trimming")
if np.ptp(winsorize(x, trim)) == 0: # its standard error would be 0
cs.cs_error("CS_E_UNDEFINED", what="The trimmed-means ANOVA", reason=f"{g} = {lv} has no spread left after Winsorizing")
conf = 0.95
seed = 42 # portable Wichmann–Hill stream: R draws the same resamples for this seed
res = csm.t1way(groups, trim) # Wilcox's Welch-type ANOVA on trimmed means (WRS2::t1way)
f, df1, df2, p = res["f"], res["df1"], res["df2"], res["p"]
xi = csm.xi_effect(groups, trim, 100, seed) # explanatory measure of effect size (Wilcox & Tian 2011)
boot = None
if False:
boot = csm.t1way_boot(groups, trim, 599, seed) # bootstrap-t (Wilcox t1waybt)
# %% Post hoc
pairs = []
p_adjust = "holm"
adjust_label = {"holm": "Holm", "hochberg": "Hochberg", "bonferroni": "Bonferroni"}[p_adjust]
if True and k > 2:
pairs = csm.pairwise_yuen(groups, levels, trim, conf, p_adjust) # Yuen–Welch per pair (lincon statistics)
# %% Assumptions
h = res["h"]
assumptions = [
{"key": "sample_size", "label": "Enough values after trimming", "status": "warn" if min(h) < 5 else "pass",
"detail": f"{min(h)} to {max(h)} values per group remain after trimming {trim:.0%} from each tail."},
{"key": "independence", "label": "Independent groups", "status": "info",
"detail": "Each row belongs to one group; use a repeated-measures method for paired data."},
]
if len(set(ns)) > 1:
warnings.append("Groups differ in size: the effect size is the median over 100 equal-size subsamples (shared random stream).")
# %% Result
alpha = 1 - conf
test_p = boot["p_boot"] if boot else p
significance = (
f"The {trim:.0%} trimmed means differ significantly ({cs.fmt_p(test_p)})." if test_p < alpha
else f"The data are compatible with equal trimmed means ({cs.fmt_p(test_p)})."
)
summary = (
f"{trim:.0%} trimmed means of {y} across {k} groups of {g} ranged from {min(res['trimmed_means']):.2f} to "
f"{max(res['trimmed_means']):.2f}. {significance} The explanatory effect size is ξ = {xi:.2f}."
)
if pairs:
summary += f" {sum(r['p_adj'] < alpha for r in pairs)} of {len(pairs)} pairwise differences are significant."
values = {"f": f, "df1": df1, "df2": df2, "p": p, "k": k, "n": N, "trim": trim, "xi": xi,
"p_boot": None if boot is None else boot["p_boot"], "n_boot": None if boot is None else boot["n_boot"]}
for lv, tm in zip(levels, res["trimmed_means"]):
values[f"tm[{lv}]"] = tm
for r in pairs:
values.update({f"{key}[{r['pair']}]": r[key] for key in ("diff", "p_adj", "ci_low", "ci_high")})
values["missing_share"] = n_dropped / n_input if n_input else 0.0 # consult-a-statistician input
tables = [{
"key": "descriptives", "title": f"Descriptives ({trim:.0%} trimming)",
"columns": [{"key": "group", "label": g, "type": "string"}, {"key": "n", "label": "n", "type": "integer"},
{"key": "retained", "label": "Retained", "type": "integer"},
{"key": "trimmed_mean", "label": "Trimmed mean", "type": "number"}, {"key": "mean", "label": "Mean", "type": "number"},
{"key": "win_sd", "label": "Winsorized SD", "type": "number"}],
"rows": [{"group": lv, "n": int(len(x)), "retained": int(hh), "trimmed_mean": float(tm), "mean": float(x.mean()),
"win_sd": float(np.std(winsorize(x, trim), ddof=1))}
for lv, x, hh, tm in zip(levels, groups, h, res["trimmed_means"])],
}]
if pairs:
m = len(pairs)
tables.append({
"key": "posthoc", "title": f"Pairwise trimmed-mean comparisons ({adjust_label}-adjusted p)",
"columns": [{"key": "pair", "label": "Comparison", "type": "string"}, {"key": "diff", "label": "Difference", "type": "number"},
{"key": "t", "label": "t", "type": "number"}, {"key": "df", "label": "df", "type": "number"},
{"key": "ci_low", "label": f"{conf:.0%} simultaneous CI low", "type": "number"},
{"key": "ci_high", "label": f"{conf:.0%} simultaneous CI high", "type": "number"},
{"key": "p_adj", "label": "p (adjusted)", "type": "pvalue"}],
"rows": pairs,
})
chart_rows = np.unique(np.round(np.linspace(0, len(df) - 1, min(len(df), 5000))).astype(int))
cs.publish({
"method": "robust.trimmed_anova",
"methodVersion": "1.0.1",
"title": "Trimmed-means ANOVA (Welch-type)",
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": N,
"summary": summary,
"apa": f"F_t({df1:.0f}, {df2:.2f}) = {cs.fmt_num(f)}, {cs.fmt_p(p)}, ξ = {cs.fmt_num(xi, leading_zero=False)}",
"statistics": [{"key": "f", "label": "F_t", "value": f}, {"key": "df1", "label": "df1", "value": df1},
{"key": "df2", "label": "df2", "value": df2}, {"key": "p", "label": "p", "value": p, "format": "p"}]
+ ([{"key": "p_boot", "label": f"Bootstrap-t p ({boot['n_boot']} resamples)", "value": boot["p_boot"], "format": "p"}] if boot else []),
"tables": tables,
"effectSizes": [{"key": "xi", "label": "ξ (explanatory)", "value": xi, "method": "√(variance of trimmed means / Winsorized variance rescaled to normal)",
"ruleSet": "Wilcox & Tian (2011): .10 small, .30 medium, .50 large"}],
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"{trim:.0%} trimmed from each tail; Welch-type heteroscedastic F (Wilcox 2017, §7.4.1). Pairwise comparisons are later − earlier level (Yuen–Welch tests with Bonferroni simultaneous intervals)."],
"values": values,
"charts": [cs.chart("distribution", "raincloud", f"{y} by {g}", {
"y": cs.col(y, df[y].to_numpy(dtype=float)[chart_rows]),
"group": cs.col(g, df[g].astype(str).to_numpy()[chart_rows], levels=levels)})]
+ ([cs.chart("differences", "forest", f"Differences in {trim:.0%} trimmed means ({conf:.0%} simultaneous CI)", {
"label": cs.col("Comparison", [x["pair"] for x in pairs], "categorical"),
"estimate": cs.col(f"Difference in {y}", [x["diff"] for x in pairs], "numeric"),
"low": cs.col("CI low", [x["ci_low"] for x in pairs], "numeric"),
"high": cs.col("CI high", [x["ci_high"] for x in pairs], "numeric")}, controls={"reference": 0})] if pairs else []),
})
The exact script CodeSplash ran for example “Guide” · R version 4.5.1 (2025-06-13)
# Trimmed-means ANOVA (Welch-type, robust)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method robust.trimmed_anova 1.0.1 · spec 63b17819fe380143
# Dataset: a_hetero3 (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/a_hetero3.parquet", col_select = c("value", "group")))
n_input <- nrow(df)
df[["group"]] <- factor(df[["group"]], levels = c("A", "B", "C")) # stored level order
df <- df[stats::complete.cases(df[c("value", "group")]), , 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("value", "group")) # infinite values stop the run (registry/errors.yaml)
# %% Test
y <- "value"
g <- "group"
d <- data.frame(y = df[[y]], g = df[[g]])
levels_g <- levels(d$g)
k <- length(levels_g)
if (k < 2) cs_error("CS_E_TOO_FEW_GROUPS", column = g, min = 2, k = k)
groups <- split(d$y, d$g)
ns <- vapply(groups, length, 0)
N <- sum(ns)
trim <- 0.2 # proportion trimmed from each tail
if (length(unique(d$y)) < 2) cs_error("CS_E_CONSTANT", column = y) # no variation: every trimmed-mean variance is 0
for (lv in levels_g) {
x <- groups[[lv]]
if (length(x) < 2) cs_error("CS_E_SMALL_GROUP", min = 2, group = paste0(g, " = ", lv), n = length(x))
if (length(x) - 2 * floor(trim * length(x)) < 2) {
cs_error("CS_E_UNDEFINED", what = "The trimmed-means ANOVA", reason = "each group needs at least two values left after trimming")
}
if (diff(range(cs_winsorize(x, trim))) == 0) { # its standard error would be 0
cs_error("CS_E_UNDEFINED", what = "The trimmed-means ANOVA", reason = sprintf("%s = %s has no spread left after Winsorizing", g, lv))
}
}
conf <- 0.95
seed <- 42 # portable Wichmann-Hill stream: Python draws the same resamples for this seed
res <- cs_t1way(groups, trim) # Wilcox's Welch-type ANOVA on trimmed means (WRS2::t1way)
f <- res$f
df1 <- res$df1
df2 <- res$df2
p <- res$p
xi <- cs_xi_effect(groups, trim, 100, seed) # explanatory measure of effect size (Wilcox & Tian 2011)
boot <- NULL
if (FALSE) boot <- cs_t1way_boot(groups, trim, 599, seed) # bootstrap-t (Wilcox t1waybt)
# %% Post hoc
pairs <- list()
p_adjust <- "holm"
adjust_label <- c(holm = "Holm", hochberg = "Hochberg", bonferroni = "Bonferroni")[[p_adjust]]
if (TRUE && k > 2) pairs <- cs_pairwise_yuen(groups, levels_g, trim, conf, p_adjust) # Yuen-Welch per pair (lincon statistics)
# %% Assumptions
h <- res$h
assumptions <- list(
list(key = "sample_size", label = "Enough values after trimming", status = if (min(h) < 5) "warn" else "pass",
detail = sprintf("%d to %d values per group remain after trimming %.0f%% from each tail.", min(h), max(h), trim * 100)),
list(key = "independence", label = "Independent groups", status = "info",
detail = "Each row belongs to one group; use a repeated-measures method for paired data.")
)
if (length(unique(ns)) > 1) warnings <- c(warnings, "Groups differ in size: the effect size is the median over 100 equal-size subsamples (shared random stream).")
# %% Result
alpha <- 1 - conf
test_p <- if (!is.null(boot)) boot$p_boot else p
significance <- if (test_p < alpha) {
sprintf("The %.0f%% trimmed means differ significantly (%s).", trim * 100, cs_fmt_p(test_p))
} else {
sprintf("The data are compatible with equal trimmed means (%s).", cs_fmt_p(test_p))
}
summary <- sprintf("%.0f%% trimmed means of %s across %d groups of %s ranged from %.2f to %.2f. %s The explanatory effect size is ξ = %.2f.",
trim * 100, y, k, g, min(res$trimmed_means), max(res$trimmed_means), significance, xi)
if (length(pairs)) {
n_sig <- sum(vapply(pairs, function(r) r$p_adj < alpha, logical(1)))
summary <- paste(summary, sprintf("%d of %d pairwise differences are significant.", n_sig, length(pairs)))
}
values <- list(f = f, df1 = df1, df2 = df2, p = p, k = k, n = N, trim = trim, xi = xi,
p_boot = if (is.null(boot)) NULL else boot$p_boot, n_boot = if (is.null(boot)) NULL else boot$n_boot)
for (i in seq_len(k)) values[[sprintf("tm[%s]", levels_g[i])]] <- res$trimmed_means[i]
for (r in pairs) {
for (key in c("diff", "p_adj", "ci_low", "ci_high")) values[[sprintf("%s[%s]", key, r$pair)]] <- r[[key]]
}
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0 # consult-a-statistician input
pct <- sprintf("%.0f%%", conf * 100)
tables <- list(list(
key = "descriptives", title = sprintf("Descriptives (%.0f%% trimming)", trim * 100),
columns = list(list(key = "group", label = g, type = "string"), list(key = "n", label = "n", type = "integer"),
list(key = "retained", label = "Retained", type = "integer"),
list(key = "trimmed_mean", label = "Trimmed mean", type = "number"), list(key = "mean", label = "Mean", type = "number"),
list(key = "win_sd", label = "Winsorized SD", type = "number")),
rows = data.frame(group = levels_g, n = as.integer(ns), retained = as.integer(h), trimmed_mean = res$trimmed_means,
mean = vapply(groups, mean, 0), win_sd = vapply(groups, function(x) sd(cs_winsorize(x, trim)), 0),
stringsAsFactors = FALSE, row.names = NULL)
))
if (length(pairs)) {
tables[[2]] <- list(
key = "posthoc", title = sprintf("Pairwise trimmed-mean comparisons (%s-adjusted p)", adjust_label),
columns = list(list(key = "pair", label = "Comparison", type = "string"), list(key = "diff", label = "Difference", type = "number"),
list(key = "t", label = "t", type = "number"), list(key = "df", label = "df", type = "number"),
list(key = "ci_low", label = paste(pct, "simultaneous CI low"), type = "number"),
list(key = "ci_high", label = paste(pct, "simultaneous CI high"), type = "number"),
list(key = "p_adj", label = "p (adjusted)", type = "pvalue")),
rows = pairs
)
}
chart_rows <- unique(round(seq(1, nrow(df), length.out = min(nrow(df), 5000))))
cs_publish(list(
method = "robust.trimmed_anova",
methodVersion = "1.0.1",
title = "Trimmed-means ANOVA (Welch-type)",
engine = cs_engine_info("stats", "nanoparquet"),
n = N,
summary = summary,
apa = sprintf("F_t(%.0f, %.2f) = %s, %s, ξ = %s", df1, df2, cs_fmt_num(f), cs_fmt_p(p), cs_fmt_num(xi, leading_zero = FALSE)),
statistics = c(list(list(key = "f", label = "F_t", value = f), list(key = "df1", label = "df1", value = df1),
list(key = "df2", label = "df2", value = df2), list(key = "p", label = "p", value = p, format = "p")),
if (!is.null(boot)) list(list(key = "p_boot", label = sprintf("Bootstrap-t p (%d resamples)", boot$n_boot), value = boot$p_boot, format = "p")) else list()),
tables = tables,
effectSizes = list(list(key = "xi", label = "ξ (explanatory)", value = xi, method = "√(variance of trimmed means / Winsorized variance rescaled to normal)",
ruleSet = "Wilcox & Tian (2011): .10 small, .30 medium, .50 large")),
assumptions = assumptions,
warnings = warnings,
notes = list(sprintf("%.0f%% trimmed from each tail; Welch-type heteroscedastic F (Wilcox 2017, §7.4.1). Pairwise comparisons are later − earlier level (Yuen–Welch tests with Bonferroni simultaneous intervals).", trim * 100)),
values = values,
charts = c(list(cs_chart("distribution", "raincloud", sprintf("%s by %s", y, g),
list(y = cs_col(y, df[[y]][chart_rows]), group = cs_col(g, as.character(df[[g]][chart_rows]), levels = levels_g)))),
if (length(pairs)) list(cs_chart("differences", "forest", sprintf("Differences in %.0f%% trimmed means (%.0f%% simultaneous CI)", trim * 100, conf * 100), list(
label = cs_col("Comparison", vapply(pairs, function(x) x$pair, ""), "categorical"),
estimate = cs_col(sprintf("Difference in %s", y), vapply(pairs, function(x) x$diff, 0), "numeric"),
low = cs_col("CI low", vapply(pairs, function(x) x$ci_low, 0), "numeric"),
high = cs_col("CI high", vapply(pairs, function(x) x$ci_high, 0), "numeric")), controls = list(reference = 0))) else list())
))
Sources
- Wilcox, R. R. (2017). Introduction to robust estimation and hypothesis testing (4th ed., §7.4). Academic Press.
- Wilcox, R. R., & Tian, T. S. (2011). Measuring effect size: A robust heteroscedastic approach for two or more groups. Journal of Applied Statistics, 38, 1359–1368.
- Mair, P., & Wilcox, R. (2020). Robust statistical methods in R using the WRS2 package. Behavior Research Methods, 52, 464–488.
From the CodeSplash method registry · robust.trimmed_anova v1.0.1.