Two-way ANOVA
stats_two_way_anova
Runs a two-way ANOVA for two crossed factors with replicates in each cell.
- Runs
- Built, not hosted
- Level
- Checked against a reference: R 4.4.3
What it is
Required: unit (independent, technical, unspecified); type (2, 3). Two-way ANOVA for two crossed factors with replicates per cell: Type III or Type II sums of squares for A, B, and A:B, with optional simple effects of B within each level of A. Inference opens only for independent units.
Field: Statistics. It is the same calculation as Drybench Assay, called by an AI assistant through the server.
What it does
You give
factorA(required): Level names of factor A (rows).factorB(required): Level names of factor B (columns).cells(required): cells[i][j]: replicate numbers for factor A level i and factor B level j.unit(required): Experimental unit: 'independent' (opens inference), 'technical', or 'unspecified'.type(required): Sums of squares convention: 3 (Type III) or 2 (Type II).postHoc: Simple effects of B within each level of A, or 'none' (default).
and 2 more, listed below
No request is recorded for this tool.
Limits
- Independent errors with one common variance, normally distributed, for the F tests.
- Every cell holds at least two values.
- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.
It will not answer when
- Fewer than two levels of a factor (withheld).
- A cell with no value (withheld).
- A cell with one value (withheld).
- No cell spreads beyond rounding: the residual is rounding only (withheld).
Every input, with its units8 inputs
factorA(required): Level names of factor A (rows).factorB(required): Level names of factor B (columns).cells(required): cells[i][j]: replicate numbers for factor A level i and factor B level j.unit(required): Experimental unit: 'independent' (opens inference), 'technical', or 'unspecified'.type(required): Sums of squares convention: 3 (Type III) or 2 (Type II).postHoc: Simple effects of B within each level of A, or 'none' (default).control: 0-based index of B's control level (required when postHoc is 'dunnett').level: Confidence coverage level for intervals (0.9, 0.95 default, or 0.99).
Every refusal, with its code8 refusals
| Code | When |
|---|---|
GROUPS_TOO_FEW | Fewer than two levels of a factor (withheld). |
EMPTY_CELL | A cell with no value (withheld). |
CELL_N_TOO_SMALL | A cell with one value (withheld). |
ZERO_VARIANCE_GROUP | No cell spreads beyond rounding: the residual is rounding only (withheld). |
SINGULAR_DESIGN | The design is rank-deficient, or leaves no residual degree of freedom (withheld). |
BEYOND_DOUBLE_RANGE | A sum of squares or mean square in the data's unit is beyond the double range (above about 1.8e308, or nonzero and below about 2.2e-308): the table is withheld; simple effects whose values are representable are given (1.0.1). |
UNIT_NOT_INDEPENDENT | The replicates are not stated to be independent units: inference is withheld. |
MISSING_ARGUMENT | Dunnett comparisons asked without a control level of B. |
The calculation
The method's equations, constants and worked example.
Equation 1
Type III (the default), with sum-to-zero contrasts: SS_A = SSE(μ, β, γ) − SSE(μ, α, β, γ)
SS_A×B = SSE(μ, α, β) − SSE(μ, α, β, γ). These are the source's Table 7, R(α̇ | μ, β̇, γ̇), R(β̇ | μ, α̇, γ̇) and R(γ̇ | μ, α̇, β̇), with its R(α | μ) = SSE(μ) − SSE(μ, α)
the dots mark sigma-restricted (sum-to-zero) coding, which the source says these comparisons require.
| Symbol | Meaning |
|---|---|
SSE(…) | sum of squared errors of the least-squares fit of the model holding the terms named, 1 |
μ, α, β, γ | the constant, the effects of factor A and of factor B, and their interaction, 1 |
Source 1.
Equation 2
Type II: SS_A = SSE(μ, β) − SSE(μ, α, β)
SS_A×B = SSE(μ, α, β) − SSE(μ, α, β, γ). These are the source's Table 5: R(α | μ, β), R(β | μ, α) and R(γ | μ, α, β).
| Symbol | Meaning |
|---|---|
SSE(…) | sum of squared errors of the least-squares fit of the model holding the terms named, 1 |
μ, α, β, γ | the constant, the effects of factor A and of factor B, and their interaction, 1 |
Source 1.
Equation 3
F = (SS/df)/σ̂², σ̂² = SSE(μ, α, β, γ)/(n − cells), the full model's mean squared error for every term
p is the upper tail of F on df and n − cells degrees of freedom. The source's F = R/(r·σ̂²), r the degrees of freedom of the hypothesis.
| Symbol | Meaning |
|---|---|
df | levels of A less one, levels of B less one, or their product, 1 |
n − cells | residual degrees of freedom: observations less the number of cells, 1 |
Source 1.
Kind of method: not recorded.
Worked example
Worked example: one case of two-way-anova@1.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.
Inputs
- factorA[0] = Male
- factorA[1] = Female
- factorB[0] = Vehicle
- factorB[1] = Low
- factorB[2] = High
- cells[0][0][0] = 10.2
- cells[0][0][1] = 11.1
- cells[0][1][0] = 12.4
- cells[0][1][1] = 13
- cells[0][1][2] = 12.1
- cells[0][1][3] = 12.8
- cells[0][1][4] = 13.3
- cells[0][2][0] = 11
- cells[0][2][1] = 10.4
- cells[0][2][2] = 11.6
- cells[1][0][0] = 13.1
- cells[1][0][1] = 12.6
- cells[1][0][2] = 13.8
- cells[1][0][3] = 12.9
- cells[1][0][4] = 13.5
- cells[1][0][5] = 12.2
- cells[1][1][0] = 15.2
- cells[1][1][1] = 14.6
- cells[1][1][2] = 15.9
- cells[1][2][0] = 12
- cells[1][2][1] = 12.8
- cells[1][2][2] = 11.7
- cells[1][2][3] = 12.4
- unit = independent
- type = 3
Steps
- cells: cell sizes and means = Male Vehicle: n 2, mean 10.65000; Male Low: n 5, mean 12.72000; Male High: n 3, mean 11.00000; Female Vehicle: n 6, mean 13.01667; Female Low: n 3, mean 15.23333; Female High: n 4, mean 12.22500, from A = Male, Female, B = Vehicle, Low, High.
- sse-full: SSE(μ, α, β, γ) = Σ (y − cell mean)² = 5.27550000.
- ms-error: σ̂² = SSE(μ, α, β, γ)/(n − cells) = 0.310323529, from n = 23, cells = 6.
- sse-a: SSE(μ, α): one-way by A = 30.3859231.
- sse-b: SSE(μ, β): one-way by B = 28.0937500.
- sse-additive: SSE(μ, α, β): the additive model, by its normal equations = 6.99424561.
- type2-A: R(α | μ, β) = SSE(μ, β) − SSE(μ, α, β) = 21.0995044, gives type2.A.
- type2-B: R(β | μ, α) = SSE(μ, α) − SSE(μ, α, β) = 23.3916775, gives type2.B.
- interaction: R(γ | μ, α, β) = SSE(μ, α, β) − SSE(μ, α, β, γ), the same in both types = 1.71874561, gives type2.A:B, type3.A:B.
- type3-A-contrast: Lμ̂ = mean of A1's cell means − mean of A2's = -2.03500000.
- type3-A: Q = (Lμ̂)²/Σ c²/n over the six cells, c = ±1/3; equal to R(α̇ | μ, β̇, γ̇) = 20.8996402, gives type3.A.
- type3-B-contrasts: Lμ̂: column means of the cell means, B1 − B3 and B2 − B3 = 0.220833333, 2.36416667.
- type3-B-variance: L·D·L′, D the diagonal of 1/n: [[v11, v12], [v12, v22]] = v11 0.312500000, v22 0.279166667, v12 0.145833333.
- type3-B: Q = (Lμ̂)′(L·D·L′)⁻¹(Lμ̂); equal to R(β̇ | μ, α̇, γ̇) = 24.3737456, gives type3.B.
- F-type2-A: F = (SS/1)/σ̂², on 1 and 17 degrees of freedom = 67.9919580.
- F-type2-B: F = (SS/2)/σ̂², on 2 and 17 degrees of freedom = 37.6891780.
- F-type2-AxB: F = (SS/2)/σ̂², on 2 and 17 degrees of freedom = 2.76928020.
- F-type3-A: F = (SS/1)/σ̂², on 1 and 17 degrees of freedom = 67.3479070.
- F-type3-B: F = (SS/2)/σ̂², on 2 and 17 degrees of freedom = 39.2715075.
- F-type3-AxB: F = (SS/2)/σ̂², on 2 and 17 degrees of freedom = 2.76928020.
The working, as the case writes it:
R(α | μ) = SSE(μ) − SSE(μ, α). Type II: A = R(α | μ, β), B = R(β | μ, α), A×B = R(γ | μ, α, β). Type III, sigma-restricted coding: A = R(α̇ | μ, β̇, γ̇), B = R(β̇ | μ, α̇, γ̇), A×B = R(γ̇ | μ, α̇, β̇). F = R/(r·σ̂²).
Answer
type2.A = 21.0995044
type2.B = 23.3916775
type2.A:B = 1.71874561
type3.A = 20.8996402
type3.B = 24.3737456
type3.A:B = 1.71874561
Where these values came from: an outside program, R stats, car, multcomp, nlme (groups.R) as recorded in stored reference values; McFarquhar M. Testable Hypotheses for Unbalanced Neuroimaging Data. Front Neurosci 2016;10:270, Tables 5 and 7 and the equations for R(), Q and F; R's values as recorded in the oracle set.
The build has not run this example through the tool.
Sources
McFarquhar M. Testable Hypotheses for Unbalanced Neuroimaging Data. Front Neurosci 2016;10:270.
Used for: Two-way ANOVA with interaction (Type III default, Type II) and simple effects. At: table 7, section 2.6, 3.3; table 5, section 2.6, 3.2; section 2 (σ̂² from the residuals), 2.5 and 2.6 (F).
Read in full, 12 November 2026
How it is checked
- Level
Checked against a reference.
- Checked against
R 4.4.3 on 22 cases of the 0.11.0 fixture (car 3.1-5 Anova, Type III with sum contrasts and Type II): sums of squares and F within 1e-9 relative; simple effects as the post-hoc methods (2026-10-13). R only; SciPy not run.
- Cases
No case set is linked to this version.
- Worked example
Published worked example, run through the tool: NIST/SEMATECH e-Handbook 7.4.3.8 and 3.2.3.2.1, every printed SS, df, MS, F and p, Type III and Type II.
- Hostile inputs
Sent 169 malformed, extreme and misspelt calls. None broke it, and every call with an undeclared argument, or with text in place of a number or a true/false value, was declined with a reason.
Run 2026-11-12-2 of 12 November 2026, server 0.11.0.
- Same answer
Called twice and with its arguments in another order, it gave the same result.
Run 2026-11-12-2 of 12 November 2026, server 0.11.0.
- Not checked
The simple effects (Tukey, Dunnett, Holm, Šidák and Bonferroni comparisons of B within each level of A) are part of this method and are not anchored on a source read here, nor worked by hand. The source's supplementary material, which defines the sigma-restricted coding, was not read; the engine's sum-to-zero contrasts are taken to be that coding, and the hand case confirms it numerically: Type III by model comparison in sum-to-zero coding equals the source's Q on equally weighted cell means exactly, and both equal R's values.
What was not checked, in fullfrom the method records
- The simple effects (Tukey, Dunnett, Holm, Šidák and Bonferroni comparisons of B within each level of A) are part of this method and are not anchored on a source read here, nor worked by hand.
- The source's supplementary material, which defines the sigma-restricted coding, was not read; the engine's sum-to-zero contrasts are taken to be that coding, and the hand case confirms it numerically: Type III by model comparison in sum-to-zero coding equals the source's Q on equally weighted cell means exactly, and both equal R's values.
- The source read is a tutorial; the first sources of the Type II and Type III sums of squares (it cites Searle 1987 and Yates 1934 among others) were not read.
- The p values are not worked by hand.
- Every case is synthetic: values generated by this project from the model itself with a recorded noise vector.
- No measured data set from another party is among the cases.
- No published case set names two-way-anova@1.0.1 by its exact key.
- No case runs this method through the served tool on its production runtime.
What this project's records still lack2 things
- A run of the worked example through the tool for two-way-anova@1.0.1.
- A case set linked to this version for two-way-anova@1.0.1.
Cite a number from this toolthe cite line
Every reply carries a cite line naming the tool, the server version, each method with its version and level, and the receipt. Quote it with any number taken from the reply.
stats_two_way_anova, server 1.0.0; status invalid-input, nothing ran; no method record; receipt <input hash, 12 characters>/<output hash, 12 characters>; methods https://www.drybench.com/methods/assay; page https://www.drybench.com/methods/tools/stats-two-way-anova. There is no result to quote; this line identifies the call and its receipt.Changes to its methods1 change
- 21 November 2026, two-way-anova@1.0.1: In 1.0.1: Data whose largest absolute value lies within 2^±100 are computed as given, as in 1.0.0; beyond that range the table and the simple effects are computed on the data multiplied by the one power of two that brings the largest value just inside it, and reported multiplied back (a sum of squares and the mean square by the square; a difference, SE and bound by the power). F, the statistics and p are unchanged by a positive scale. A table whose sums of squares cannot be reported in the data's unit is withheld as BEYOND_DOUBLE_RANGE: at 1e±160 and 1e±200 the ANOVA table is withheld so (its sums of squares are about 1e±320 and 1e±400) and the simple effects give the unscaled statistics and p. In a seeded scan of 1,000 calls of the tool at magnitudes from 1e-300 to 1e300, every call whose data share one magnitude and whose reply changed now gives the reply 1.0.0 gives on the same data brought near 1 by a power of two, or withholds as BEYOND_DOUBLE_RANGE; calls mixing magnitudes more than 2^500 apart have no such reference and were not judged.