Two-Way Nested ANOVA
Includes: Two-way nested ANOVA, Balanced design check, Satterthwaite approximation (unbalanced designs).
Purpose: Analyze hierarchical (nested) designs such as subjects nested within centers, with appropriate variance decomposition.
Overview
A two-way nested ANOVA is used when one factor is nested inside another factor (the nested levels exist only within a parent level).
Example:
- Group factor \(A\): Laboratory (Lab 1, Lab 2, Lab 3)
- Nested factor \(B(A)\): Technician within laboratory (Tech 1 in Lab 1, Tech 2 in Lab 1, …)
- Response \(Y\): numeric outcome (e.g., yield, measurement error)
BESHStatNG reports:
- An ANOVA table with sources:
- Between Groups (factor \(A\))
- Subgroups within Groups (factor \(B(A)\))
- Within Subgroups (residual error)
- A balanced design indicator
- Variance component estimates (method-of-moments) and their percentage contributions
- A Satterthwaite approximation table for the Between Groups test when the design is unbalanced and the approximation is applicable
Example dataset
The screenshots use this long-format dataset (three columns):
group– Group factor \(A\)subgourp– Nested factor \(B(A)\) (note: spelling follows the CSV)result– Numeric response
Download:
Screenshots
Input tab

Results

When to use it
Use Two-Way Nested ANOVA when:
- The response is continuous.
- You have a hierarchical structure where a “subgroup” factor is only meaningful within a parent group.
- Observations are independent within each subgroup (conditional on the subgroup mean), and errors are approximately normal with constant variance.
Nesting requirement (important)
The nested factor must be truly nested:
- Each nested level (e.g., subgroup code) must appear in only one group level.
If the same nested label appears under multiple groups, the design is not nested and the add-in will stop with an error.
Inputs in Excel
This test uses long format inputs (three ranges of equal length):
- Group Factor: categorical values for \(A\)
- Nested Factor: categorical values for \(B(A)\)
- Data: numeric response values
Output
Choose one: - Output Range - New Worksheet - New Workbook
Output and interpretation
Main ANOVA table
BESHStatNG reports:
- SS – sum of squares
- df – degrees of freedom
- MS – mean square
- F – test statistic
- P-value – right-tail F p-value
- Variance Component % – estimated percentage contribution of each random component (method-of-moments)
F-tests (nested design):
Between Groups (A) is tested using:
Subgroups within Groups (B(A)) is tested using:
Satterthwaite approximation (unbalanced designs)
For a nested design with Group \(A\) and Subgroup \(B(A)\), the classical fixed-effects nested ANOVA uses:
Test for Groups \(A\):
Test for Subgroups within Groups \(B(A)\):
When the design is unbalanced, \(MS_{B(A)}\) can be a noisy denominator for testing \(A\).
BESHStatNG optionally computes a Satterthwaite-adjusted denominator as a linear combination of \(MS_E\) and \(MS_{B(A)}\) (Gaylor & Hopper, 1969) and assigns it an effective (fractional) degrees of freedom using Satterthwaite’s formula.
Design constants \(n_0\) and \(n_0'\)
Let \(n_{ij}\) be the number of observations in subgroup \(j\) nested in group \(i\).
Let \(n_i = \sum_j n_{ij}\) be the total in group \(i\), and \(N=\sum_i n_i\) the grand total.
Define:
Let
(where \(a\) is the number of groups and \(b_i\) the number of subgroups in group \(i\)).
BESHStatNG computes:
Weights and Satterthwaite denominator
Weights are:
The adjusted denominator mean square is:
The associated Satterthwaite degrees of freedom are computed using the standard linear-combination formula:
The adjusted test for Groups is then:
Gaylor–Hopper “safe region” check (definitions of \(r\) and \(c\))
BESHStatNG applies the adjustment only if a conservative “safe region” criterion is satisfied.
First compute the usual variance-ratio:
Then define:
and the threshold:
where \(F^{-1}(p;\nu_1,\nu_2)\) is the \(p\)-quantile of an \(F(\nu_1,\nu_2)\) distribution.
Condition: the add-in uses the Satterthwaite adjustment only when:
Why this check is used: in highly unbalanced cases the weighted denominator (and its df) can become unstable or overly optimistic.
The Gaylor–Hopper criterion is a practical guardrail intended to apply the approximation only in a region where it is expected to behave well.
When the Satterthwaite table is shown
BESHStatNG shows the Satterthwaite-adjusted table only under a set of conservative conditions intended for certain unbalanced nested designs:
- \(df_{B(A)} \le 100\) and \(df_{B(A)} < 2\,df_E\)
- the Gaylor–Hopper “safe region” check is satisfied (\(r>c\))
- and the design constants used for the weighted denominator are non-degenerate (\(n_0' \ne n_0\))
These checks help avoid unstable or anti-conservative results that can occur when the residual degrees of freedom are too small, the design is highly unbalanced, or the weighting becomes extreme. If the conditions are not met, BESHStatNG reports the standard nested ANOVA table without the Satterthwaite adjustment.
Variance Component %
BESHStatNG estimates variance components by method-of-moments and reports their relative contributions (in %). Negative estimates are truncated to 0 before computing percentages.
Statistical details
Model
A common nested model is:
where:
- \(i = 1,\dots,a\) indexes groups
- \(j = 1,\dots,b_i\) indexes subgroups within group \(i\)
- \(k = 1,\dots,n_{ij}\) indexes replicates within subgroup \(j(i)\)
Sums of squares
Let \(\bar{Y}\) be the grand mean, \(\bar{Y}_{i\cdot\cdot}\) the mean in group \(i\), and \(\bar{Y}_{ij\cdot}\) the mean in subgroup \(j(i)\).
with:
Degrees of freedom
Let \(N\) be the total number of observations and \(m\) the total number of subgroups.
Mean squares and tests
Satterthwaite approximation (unbalanced designs)
For some unbalanced designs, BESHStatNG computes a modified denominator for the Between Groups test using a weighted combination of \(MS_E\) and \(MS_{B(A)}\):
and an approximate denominator df:
The adjusted F-statistic is:
Note: This is intended as a practical adjustment for certain unbalanced nested designs; it is not always applicable, and BESHStatNG may omit it when conditions are not met.
Variance components (method-of-moments)
BESHStatNG reports method-of-moments variance components for a nested random-effects decomposition:
- \(\sigma^2_A\): between groups
- \(\sigma^2_{B(A)}\): between subgroups within groups
- \(\sigma^2_E\): residual (within subgroup)
The residual component is:
For unbalanced designs, effective sample-size quantities are used (computed from the subgroup cell counts \(n_{ij}\)):
Then:
An estimate for \(\sigma^2_A\) is also computed; negative estimates are truncated to 0 before computing the Variance Component % totals.
R code (reference)
1) Reproduce the same ANOVA mean-square tests (base R)
dat <- read.csv("017twowaynestedanova.csv")
dat$group <- factor(dat$group)
dat$subgourp <- factor(dat$subgourp)
# Nested ANOVA: subgroup nested within group
fit <- aov(result ~ group + Error(group:subgourp), data = dat)
summary(fit)
This approach reproduces the nested mean-square F-tests (Between Groups tested against Subgroups-within-Groups) using base R.
2) Mixed-model alternative (lme4 / lmerTest)
# install.packages(c("lme4", "lmerTest"))
library(lme4)
library(lmerTest)
dat <- read.csv("017twowaynestedanova.csv")
dat$group <- factor(dat$group)
dat$subgourp <- factor(dat$subgourp)
# Random subgroups nested within groups; group as fixed
m <- lmer(result ~ group + (1 | group:subgourp), data = dat, REML = TRUE)
anova(m) # lmerTest provides Satterthwaite-style df for fixed effects
VarCorr(m) # variance components (REML), may differ from method-of-moments
Why R may differ slightly from BESHStatNG
- BESHStatNG’s main table uses classical ANOVA mean-square calculations for SS/MS/F and method-of-moments variance components.
- Mixed-model functions (e.g.,
lmer) estimate variance components using (RE)ML, which can produce different component estimates and therefore different percentages. lmerTestcomputes Satterthwaite degrees of freedom for fixed-effect tests in a fitted mixed-effects model (typically fit by REML/ML vialme4::lmer()), using the estimated covariance of fixed effects and the uncertainty in variance-component estimates. BESHStatNG’s Satterthwaite table, in contrast, is an ANOVA mean-squares adjustment for certain unbalanced nested designs: it forms a weighted denominator mean square (a linear combination of \(MS_{B(A)}\) and \(MS_E\)) and applies a Satterthwaite df to that constructed denominator. Because these approaches use different underlying models and variance estimators, the reported degrees of freedom and p-values may not match exactly.
Notes
- Missing values: rows containing missing entries in any of the three input columns should be removed (or will be treated as invalid).
- Balanced design: BESHStatNG flags the design as balanced only when group counts, subgroup counts, and all subgroup-within-group cell counts are equal.
References
- Satterthwaite, F. E. (1946). An approximate distribution of estimates of variance components. Biometrics Bulletin, 2(6), 110–114.
- Gaylor, D. W., & Hopper, F. N. (1969). Estimating the Degrees of Freedom for Linear Combinations of Mean Squares by Satterthwaite’s Formula. Technometrics, 11(4), 691–706.