Skip to content

Factorial ANOVA, three to six factors

stats_factorial_anova

Builds the full factorial ANOVA table for three to six crossed factors with every cell filled.

Runs
On the server
Level
Checked against a reference: statsmodels 0.15.0 anova_lm, a second implementation in Python and exact rational arithmetic
Ask your assistant

What it is

Returns the full factorial ANOVA table, Type II or Type III, for three to six crossed factors with every cell filled. Use when three or more factors are crossed and every combination of levels has at least two measurements. Not for two factors: use `stats_two_way_anova`, which defaults to Type III and adds simple effects. Here sumsOfSquares is required, with no default: say 'type-ii' or 'type-iii'. F and p need replicates 'independent'; the table's 2^k − 1 F tests are not corrected for multiplicity, and no post-hoc tests are given; up to 128 cells and 1,000 observations. A measurement's unit is required, never assumed: any unit of the kit's table, returned in its canonical spelling; a unit group takes one unit, never converted.

Field: Statistics and design.

What it does

You give

  • factors (required): The crossed factors, 3 to 6, each with its level names (at least 2). For two factors use stats_two_way_anova; for one, stats_compare_groups.
  • observations (required): Every observation, at least two in each combination of levels.
  • replicates (required): What one value is: 'independent' (independent biological replicates; opens F and p), 'technical' (technical replicates) or 'unspecified'. Required: never inferred from the data.
  • sumsOfSquares (required): 'type-ii' (each term adjusted for the terms that do not contain it) or 'type-iii' (each effect compares marginal means weighted equally over the other factors' levels). Required, no default: unlike stats_two_way_anova, nothing is assumed when it is left out.

No request is recorded for this tool.

Limits

  • Research statistics and experimental-design arithmetic on the data, margins, prevalence and settings you supply.
  • Not for diagnosis or treatment decisions and not a regulatory analysis.
  • It does not choose a design, a margin, a cut-off or a sample size for you.
  • Full factorial only, every cell with at least two values; F and p for independent replicates only.
  • Type II or III is yours to choose, and neither is recommended.
  • The 2^k − 1 tests are not corrected for multiplicity, no post-hoc tests are given, and a non-small p does not show that groups are equal.
  • 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

  • more than 128 combinations of levels (Drybench ruling, 10 November 2026, caps, item 1; with at most 1000 observations, 32 levels per factor and level names of 16 characters, enforced as list and text limits).
  • a combination of levels with no observation, including a declared level with no rows: Type III then differs from the restricted-minus-full SS (LaMotte, p. 11).
  • a cell with one observation: every cell needs at least two.
Every input, with its units4 inputs
  • factors (required): The crossed factors, 3 to 6, each with its level names (at least 2). For two factors use stats_two_way_anova; for one, stats_compare_groups.
  • observations (required): Every observation, at least two in each combination of levels.
  • replicates (required): What one value is: 'independent' (independent biological replicates; opens F and p), 'technical' (technical replicates) or 'unspecified'. Required: never inferred from the data.
  • sumsOfSquares (required): 'type-ii' (each term adjusted for the terms that do not contain it) or 'type-iii' (each effect compares marginal means weighted equally over the other factors' levels). Required, no default: unlike stats_two_way_anova, nothing is assumed when it is left out.
Every refusal, with its code3 refusals
CodeWhen
OUT_OF_RANGEmore than 128 combinations of levels (Drybench ruling, 10 November 2026, caps, item 1; with at most 1000 observations, 32 levels per factor and level names of 16 characters, enforced as list and text limits).
EMPTY_CELLa combination of levels with no observation, including a declared level with no rows: Type III then differs from the restricted-minus-full SS (LaMotte, p. 11).
CELL_N_TOO_SMALLa cell with one observation: every cell needs at least two.

The calculation

The method's equations, constants and worked example.

Full-factorial ANOVA for three to six crossed factors, Type II or Type III sums of squaresstats-factorial-anova@1.0.1

Equation 1

SS_III(T) = RSS(full model without T's sum-contrast columns) − RSS(full model)

with every cell filled and the full factorial this is LaMotte's Type III, y′(P_X − P_(X0, X2*))y, and tests equal-weight marginal means H_T η = 0 (Drybench ruling, 10 November 2026, k-factor derivation, design Q1). That column deletion equals Type III for k factors with every cell filled is Drybench's derivation, not reviewed by a person

a second agent re-derived it for filled cells through an invertible saturated sum-contrast design (14 November 2026)

SymbolMeaning
Ta main effect or interaction
RSSresidual sum of squares (in the caller's unit squared), as-given^2
sum contrastsa factor of L levels, in the order given, has L − 1 columns: level l (counted from 0, l < L − 1) is 1 in column l and 0 in the others, the last level −1 in every column; an interaction's columns are the products of its factors' columns; terms in the order main effects, then two-factor interactions, … in factor order

Source 1.

Equation 2

SS_II(T) = RSS(X0) − RSS(X0, T), X0 = the intercept and every term not containing T

SymbolMeaning
X0the terms not containing T

Source 1.

Equation 3

MS(T) = SS(T)/df(T), df(T) = Π_{f ∈ T}(levels_f − 1)

residual: SS = RSS(full), df = N − Π levels, MS = SS/df

F(T) = MS(T)/MS(residual)

p = P(F_{df(T), N − Π levels} ≥ F)

corrected total SS = Σ(y − ȳ)² on N − 1 df. Balanced (every cell holds the same number n of values): Types II and III agree, and SS(A) = n·(Π levels/L_A)·Σ_a(ȳ_a − ȳ)², SS(AB) = n·(Π levels/(L_A·L_B))·Σ_ab(ȳ_ab − ȳ_a − ȳ_b + ȳ)², and so on by inclusion and exclusion of the marginal means. The table is withheld (ZERO_VARIANCE_GROUP) when no cell spreads beyond rounding: in every cell max − min ≤ 2·n_c·ε·M, n_c the cell's size, M its largest |y| and ε = 2^−52. df, MS, F, p, the corrected total and the balanced closed forms are standard definitions, not in LaMotte

SymbolMeaning
Nobservations
levels_f, L_Alevels of factor f, of factor A
ȳ_a, ȳ_ab, ȳmarginal means of level a, of the cell ab, and the grand mean (in the caller's unit), as-given
n_cvalues in a cell
Mlargest absolute value in a cell (in the caller's unit), as-given
εdouble-precision machine epsilon
FF statistic
pp-value

Source 1.

Conventions

  • sumsOfSquares = type-iii: Each effect compares marginal means weighted equally over the other factors' levels.
  • sumsOfSquares = type-ii: Each term is adjusted for the terms that do not contain it, not for those that do; with unequal cell counts the hypothesis tested for a lower-order term depends on those counts.

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

Worked example

Worked example: one case of stats-factorial-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

  • factors[0].name = temperature
  • factors[0].levels[0] = te1
  • factors[0].levels[1] = te2
  • factors[1].name = pH
  • factors[1].levels[0] = pH1
  • factors[1].levels[1] = pH2
  • factors[2].name = feed
  • factors[2].levels[0] = fe1
  • factors[2].levels[1] = fe2
  • observations[0].levels[0] = te1
  • observations[0].levels[1] = pH1
  • observations[0].levels[2] = fe1
  • observations[0].value = -1.19 g
  • observations[1].levels[0] = te1
  • observations[1].levels[1] = pH1
  • observations[1].levels[2] = fe1
  • observations[1].value = -0.98 g
  • observations[2].levels[0] = te1
  • observations[2].levels[1] = pH1
  • observations[2].levels[2] = fe2
  • observations[2].value = -1.17 g
  • observations[3].levels[0] = te1
  • observations[3].levels[1] = pH1
  • observations[3].levels[2] = fe2
  • observations[3].value = 1.96 g
  • observations[4].levels[0] = te1
  • observations[4].levels[1] = pH2
  • observations[4].levels[2] = fe1
  • observations[4].value = 0.57 g
  • observations[5].levels[0] = te1
  • observations[5].levels[1] = pH2
  • observations[5].levels[2] = fe1
  • observations[5].value = 0.26 g
  • observations[6].levels[0] = te1
  • observations[6].levels[1] = pH2
  • observations[6].levels[2] = fe2
  • observations[6].value = 1.13 g
  • observations[7].levels[0] = te1
  • observations[7].levels[1] = pH2
  • observations[7].levels[2] = fe2
  • observations[7].value = 1.12 g
  • observations[8].levels[0] = te2
  • observations[8].levels[1] = pH1
  • observations[8].levels[2] = fe1
  • observations[8].value = -1.07 g
  • observations[9].levels[0] = te2
  • observations[9].levels[1] = pH1
  • observations[9].levels[2] = fe1
  • observations[9].value = -0.11 g
  • observations[10].levels[0] = te2
  • observations[10].levels[1] = pH1
  • observations[10].levels[2] = fe2
  • observations[10].value = 1.89 g
  • observations[11].levels[0] = te2
  • observations[11].levels[1] = pH1
  • observations[11].levels[2] = fe2
  • observations[11].value = 0.07 g
  • observations[12].levels[0] = te2
  • observations[12].levels[1] = pH2
  • observations[12].levels[2] = fe1
  • observations[12].value = 1.42 g
  • observations[13].levels[0] = te2
  • observations[13].levels[1] = pH2
  • observations[13].levels[2] = fe1
  • observations[13].value = -0.65 g
  • observations[14].levels[0] = te2
  • observations[14].levels[1] = pH2
  • observations[14].levels[2] = fe2
  • observations[14].value = 2.47 g
  • observations[15].levels[0] = te2
  • observations[15].levels[1] = pH2
  • observations[15].levels[2] = fe2
  • observations[15].value = 1.4 g
  • replicates = technical
  • sumsOfSquares = type-iii

Steps

  1. mean-te1 = 0.2125 g, from observations; by equation 1.
  2. mean-te2 = 0.6775 g, from observations; by equation 1.
  3. ss-temperature = 0.8649 g², from mean-te1, mean-te2; by equation 1; gives terms[0].ss.
  4. ss-residual = 9.8005 g², from observations; by equation 1; gives residual.ss.
  5. ms-residual = 1.2250625 g², from ss-residual; by equation 3; gives residual.ms.

The working, as the case writes it:

for a 2-level term, H_T ȳ at each cell is ± (the contrast of cell means)/2^k summed over the 2^k cells

SS_T = n · Σ_cells (H_T ȳ)² = (n·2^k/4^|T|)·(Σ ± ȳ)²/2^(k-|T|)…

computed here by inclusion-exclusion over the marginal means in fractions

Answer

terms[0].ss = 0.8649 g²

residual.ss = 9.8005 g²

residual.ms = 1.2250625 g²

Where these values came from: an outside program, Python fractions 3.13.18; exact rational arithmetic: SS_T = n·||H_T ȳ||² over the cell means (balanced: every type agrees).

At build the tool returned this answer within the tolerance the file states: SS and MS relative 1e-12 or 1e-12·Σ(y − ȳ)² absolute, whichever is larger (Drybench ruling, 10 November 2026, G3 floor); df, counts, names, statuses and codes exact.

Sources

  1. LaMotte LR. A formula for Type III sums of squares. arXiv:1804.00545v1 [stat.ME], 29 March 2018

    Used for: Full-factorial ANOVA for three to six crossed factors, Type II or Type III sums of squares. At: section section 2, p. 5 (P3 = P_X − P_(X0, X2*), from the SPSS definition quoted on p. 3); section 3, pp. 7–11 (two factors: Type III = restricted-minus-full SS); p. 2 (column deletion is correct only in some cases); section p. 6: Type II has sp(X0, X1) as the full model and sp(X0) as the restricted model; section p. 1 and p. 6: the sums of squares an effect's F statistic tests, against the full model's residual (Type II's full and restricted models, p. 6); df, MS, F, p and the balanced closed forms are standard definitions, not in LaMotte.

    Read in full, 10 November 2026

How it is checked

Level

Checked against a reference.

Checked against

An outside program, LaMotte's Type III formula (in-house, numpy); SciPy; statsmodels, numpy 2.5.4; scipy 1.18.1; statsmodels 0.15.0; an outside program, Python fractions, 3.13.18; a reference program this project wrote itself, second implementation (Python 3.13; NumPy, SciPy distribution functions and mpmath only), 2026-11-14, exact rationals for every sum of squares, mean square and F; p from mpmath 1.4.1's regularised incomplete beta at 50 digits; not an outside program.

Cases

No case set is linked to this version.

Not checked

Post-hoc tests, simple effects and marginal-mean comparisons (held: the comparison family in k factors needs its own ruling); empty cells and fractional or incomplete designs; random and mixed effects, covariates and blocking; Type I sums of squares; a published unbalanced k-way table (none found).

Changes to its methods0 changes

No change is logged for these method versions.