The correctedWS package calculates corrected
Welch–Satterthwaite effective degrees of freedom for weighted sums of
independent variance components. It also provides
corrected_t_test(), a t-test interface whose default
unequal-variance two-sample calculation uses the corrected degrees of
freedom.
The package is deliberately separate from
stats::t.test(). Existing base R code therefore keeps its
established behavior, while users can explicitly choose the corrected
method through this package. The classical calculation is retained as an
opt-in comparison method.
The correction and its derivation are described by von Davier (2026), A Corrected Welch Satterthwaite Equation.
Suppose that
\[ S^2 = \sum_{k=1}^{K} w_k S_k^2, \]
where the variance components are independent, the weights satisfy \(w_k > 0\), and
\[ \frac{\nu_k S_k^2}{\sigma_k^2} \sim \chi^2_{\nu_k}. \]
The corrected estimator is
\[ \nu^*_{vD} = \frac{\left(\sum_{k=1}^{K} w_k S_k^2\right)^2} {\sum_{k=1}^{K} w_k^2 \left(S_k^2\right)^2/(\nu_k+2)} - 2. \]
In R, the vector form is:
s2 <- c(2, 3)
nu <- c(10, 20)
w <- c(1, 2)
num <- sum(w * s2)
den <- sum(w^2 * s2^2 / (nu + 2))
num^2 / den - 2
#> [1] 30.49231
cws(s2, nu, w)
#> [1] 30.49231The two results are identical. The arguments s2 are
variance components, not standard deviations. If standard deviations are
available, square them before calling cws().
cws() accepts vectors of variance components, component
degrees of freedom, and positive weights. Equal weights are used when
w is omitted.
cws(c(2, 3), c(10, 20))
#> [1] 31.67347
cws(c(2, 3), c(10, 20), w = c(1, 2))
#> [1] 30.49231
cws(c(1, 2, 3), c(5, 10, 15), w = c(1, 2, 3))
#> [1] 29.40575Multiplying every weight by the same positive constant does not change the result, because the common factor cancels between numerator and denominator:
cws2() is a convenience wrapper for the two-component
case:
The default weights are one and one.
The functions require:
s2, nu, and w to have the
same length;s2 values;nu values;w values; andIf the denominator is zero, as when every variance component is zero,
the functions return NA_real_.
The classical estimator is
\[ \nu^*_{WS} = \frac{\left(\sum_{k=1}^{K} w_k S_k^2\right)^2} {\sum_{k=1}^{K} w_k^2 \left(S_k^2\right)^2/\nu_k}. \]
It uses \(\nu_k\) rather than \(\nu_k+2\) and does not subtract 2. The
package keeps this calculation available through
ws_classical():
The corrected and classical methods are close when the component degrees of freedom are large, but can differ substantially for small component degrees of freedom.
For an independent unequal-variance two-sample test, let
\[ S_1^2 = \frac{s_1^2}{n_1},\qquad S_2^2 = \frac{s_2^2}{n_2},\qquad \nu_1 = n_1-1,\qquad \nu_2 = n_2-1. \]
The standard error is \(\sqrt{S_1^2+S_2^2}\).
corrected_t_test() uses the corrected estimator for the
denominator degrees of freedom by default:
set.seed(20261103)
x <- rnorm(20, mean = 0, sd = 1)
y <- rnorm(12, mean = 0.4, sd = 2)
corrected <- corrected_t_test(x, y)
classical <- corrected_t_test(x, y, method = "classical")
corrected
#>
#> Corrected Welch t-test
#>
#> data: x and y
#> t = 0.40742, df = 19.698, p-value = 0.6881
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#> -0.8331318 1.2370842
#> sample estimates:
#> mean of x mean of y
#> -0.2432571 -0.4452333
classical
#>
#> Classical Welch t-test
#>
#> data: x and y
#> t = 0.40742, df = 18.438, p-value = 0.6884
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#> -0.8377592 1.2417116
#> sample estimates:
#> mean of x mean of y
#> -0.2432571 -0.4452333The statistic and standard error are the same in both tests. The degrees of freedom, confidence interval, and p-value can differ because the corrected and classical approximations use different degrees of freedom.
For comparison, the base-R result continues to be available independently:
stats::t.test(x, y)
#>
#> Welch Two Sample t-test
#>
#> data: x and y
#> t = 0.40742, df = 18.438, p-value = 0.6884
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#> -0.8377592 1.2417116
#> sample estimates:
#> mean of x mean of y
#> -0.2432571 -0.4452333corrected_t_test() also supports one-sample, paired, and
pooled two-sample tests. The corrected effective-degrees-of-freedom
change concerns the independent unequal-variance two-sample case;
one-sample, paired, and pooled tests use their usual degrees of
freedom.
The following compact simulation uses the same data-generating mechanism as the repository simulation scripts. Each variance component is generated as
\[ S_k^2 = \frac{\chi^2_{\nu}}{\nu}, \]
so its expected value is one and the target effective degrees of freedom is \(K\nu\). This is an illustration for the vignette, not a replacement for a full simulation study.
simulate_cell <- function(K, nu, nsim = 1000L) {
draws <- matrix(rchisq(nsim * K, df = nu), nrow = nsim, ncol = K)
s2 <- draws / nu
estimates <- apply(
s2, 1L,
function(row) cws(row, nu = rep(nu, K))
)
target <- K * nu
data.frame(
K = K,
nu = nu,
target_df = target,
mean_df = mean(estimates),
bias = mean(estimates) - target,
relative_bias = (mean(estimates) - target) / target,
rmse = sqrt(mean((estimates - target)^2))
)
}
set.seed(20261103)
simulation <- do.call(
rbind,
lapply(c(1, 3, 10), function(nu) {
do.call(rbind, lapply(c(2, 10, 40), simulate_cell,
nu = nu, nsim = 1000L))
})
)
simulationK nu target_df mean_df bias relative_bias rmse 1 2 1 2 2.257521 0.25752075 1.287604e-01 1.097835 2 10 1 10 10.901941 0.90194082 9.019408e-02 3.598044 3 40 1 40 41.843406 1.84340560 4.608514e-02 8.830758 4 2 3 6 6.189914 0.18991443 3.165241e-02 1.494978 5 10 3 30 31.131134 1.13113379 3.770446e-02 5.411814 6 40 3 120 120.956881 0.95688074 7.974006e-03 12.486571 7 2 10 20 20.100907 0.10090664 5.045332e-03 2.021519 8 10 10 100 100.537928 0.53792791 5.379279e-03 6.952908 9 40 10 400 400.001879 0.00187893 4.697325e-06 15.744102
The usual pattern is that relative bias is more visible for small
nu and becomes smaller as the component degrees of freedom
increase. Monte Carlo results will vary with the random seed and number
of replications.
Base R’s stats::t.test() uses the classical
Welch–Satterthwaite approximation for its default unequal-variance
two-sample test. Packages such as lmerTest and
pbkrtest implement Satterthwaite-related methods for linear
mixed models. correctedWS does not override those
functions. It provides a separate, explicit corrected implementation so
that analyses can be reproduced and compared without changing the
behavior of existing R software.
This package is a proposed standalone CRAN package. Before
submission, the package should be checked with current R release,
R-patched, and preferably R-devel, including platform checks such as
win-builder. The source package should then be submitted through the CRAN submission form.
See the repository-level cran-comments.md for additional
submission notes.
von Davier, M. (2026). A Corrected Welch Satterthwaite Equation. And: What You Always Wanted to Know About Kish’s Effective Sample but Were Afraid to Ask. arXiv:2602.20912. https://arxiv.org/abs/2602.20912