Skip to content

Home / Shared Math Details / MSA / Expected Mean Squares

Expected Mean Squares

This page defines the expected mean squares method: how the analysis of variance table becomes a set of equations in the variance components, how those equations are solved, and how each term is tested. It is the method the Automatic setting chooses for balanced data, and the one whose answers match a classical analysis of variance.

It is available for every study type. The components it produces are then handled exactly as Variance Components describes.

Notation

Term Description
\(T, B\) model terms. \(T\) indexes the row of the expected mean square system, \(B\) the column
\(MS_T\) the observed mean square of term \(T\)
\(\nu_T\) the degrees of freedom of term \(T\)
\(c_{TB}\) the coefficient of term \(B\)'s variance component in term \(T\)'s expected mean square
\(\sigma^2_B\) the variance component of term \(B\)
\(\sigma^2_{\text{repeat}}\) repeatability, the residual variance
\(N\) the number of observations used
\(L_f\) the number of levels of factor \(f\)
\(\mathbf{X}\) the model matrix
\(\mathbf{G}\) a generalized inverse of \(\mathbf{X}^{\top}\mathbf{X}\)
\(\mathbf{L}\) the selector for the columns of one term
\(\mathbf{P}_T\) the projector onto term \(T\)'s own space
\(\mathbf{Z}_B\) the zero-or-one incidence matrix of term \(B\)
\(a_i\) the weight of mean square \(i\) in a synthesized denominator
\(F_T\) the F statistic of term \(T\)

What the method does

The expected mean squares method builds the analysis of variance table, works out what each mean square is expected to be in terms of the variance components, and then solves that system for the components.

Its name is what it does. Every mean square in the table estimates some combination of the variance components; writing down those combinations gives a set of equations, and the components are what solves them.

On balanced data this is the classical analysis of variance estimate, which is what the option label means by "Equivalent to ANOVA when balanced".

The expected mean square system

For each term \(T\) in the model, the mean square \(MS_T\) has an expected value that is a weighted sum of the variance components plus the residual variance:

\[ E[MS_T] = \sigma^2_{\text{repeat}} + \sum_{B} c_{TB}\,\sigma^2_B \]

\(B\) runs over the random terms of the model and \(c_{TB}\) is the coefficient of term \(B\)'s component in term \(T\)'s expected mean square. Collecting these for every term gives a triangular system of equations in the unknown components.

A fixed term's column is left empty. A fixed effect has no variance component, so no coefficient is computed for it and it takes no part in the solve.

Coefficients on balanced data

When the data are balanced the coefficients have a closed form. The coefficient of \(B\) in \(T\)'s expected mean square is the total number of observations divided by the product of the level counts of the factors in \(B\):

\[ c_{TB} = \frac{N}{\prod_{f \in B} L_f} \]

\(N\) is the number of observations used and \(L_f\) the number of levels of factor \(f\). The coefficient is non-zero only when term \(B\) contains term \(T\).

Read plainly: a component's coefficient is the number of observations that share each of its levels. In a crossed study with \(p\) parts, \(o\) operators and \(r\) replicates, the part component appears in the part mean square with coefficient \(o\,r\), because each part was measured \(o\,r\) times.

The closed form is used only when the data are genuinely balanced, and that is checked rather than assumed.

Coefficients on unbalanced data

When the data are not balanced the closed form is wrong, and the coefficients are computed from the model matrices instead. For term \(T\) the projector onto that term's own space is formed,

\[ \mathbf{P}_T = \mathbf{X}\mathbf{G}\mathbf{L}^{\top}\left(\mathbf{L}\mathbf{G}\mathbf{L}^{\top}\right)^{-1}\mathbf{L}\mathbf{G}\mathbf{X}^{\top} \]

where \(\mathbf{X}\) is the model matrix, \(\mathbf{G}\) a generalized inverse of \(\mathbf{X}^{\top}\mathbf{X}\), and \(\mathbf{L}\) selects the columns belonging to \(T\). Each coefficient is then a trace against the other term's own incidence matrix, divided by the term's degrees of freedom:

\[ c_{TB} = \frac{\operatorname{trace}\!\left(\mathbf{P}_T \mathbf{Z}_B \mathbf{Z}_B^{\top}\right)}{\nu_T} \]

\(\mathbf{Z}_B\) is the zero-or-one incidence matrix of term \(B\) and \(\nu_T\) the degrees of freedom of term \(T\).

This is the same construction whatever the design: crossed, nested, or any Extended shape. There is one algorithm, and the balanced closed form above is a shortcut into it rather than a separate method.

The construction carries its own check. If the projector's trace disagrees with the degrees of freedom the analysis of variance reports for that same term, the analysis is refused rather than reporting coefficients that cannot be trusted.

Solving for the components

The system is triangular, so it is solved by back-substitution from the bottom up. Each term's component is solved only after every component its own expected mean square depends on has been solved.

The residual mean square starts it off, since \(E[MS_{\text{residual}}] = \sigma^2_{\text{repeat}}\) with no other term in it, so the residual mean square estimates repeatability directly:

\[ \hat{\sigma}^2_{\text{repeat}} = MS_{\text{residual}} \]

Where the lowest term in the model is itself the lowest estimable level, meaning there is one observation per cell and no residual, there is no residual mean square to start from and the error variance enters the solve as zero instead.

Every component therefore ends up as a linear combination of the mean squares, and the weights of that combination are kept. They are what lets the confidence interval layer recognise whether a component came from a single mean square, from a sum, or from a difference, which decides which interval formula applies.

The balanced closed form

On balanced data the back-substitution reduces to the familiar textbook form. A term's component is the difference between its own mean square and its matched denominator's, divided by its own coefficient:

\[ \hat{\sigma}^2_T = \frac{MS_T - MS_{\text{denominator}}}{c_{TT}} \]

The matched denominator is the term whose expected mean square is \(T\)'s with \(T\)'s own component taken out, so the subtraction removes everything except the component being estimated. For a main effect in a simple crossed study the denominator is the interaction, or the residual where there is no interaction.

This is worth stating because it makes the whole method checkable by hand on a balanced study: the numbers in the analysis of variance table are enough to reproduce every component.

Negative estimates

The subtraction in that formula is why this method can produce a negative variance estimate. If the mean square being tested comes out smaller than its own denominator, the difference is negative, and dividing by a positive coefficient keeps it negative.

Nothing about the arithmetic is wrong when that happens. A variance component is a non-negative quantity being estimated by a difference of two noisy numbers, and a difference can land on the wrong side of zero when the true component is small.

The report handles it by reporting zero, keeping the unfloored estimate beside it, flagging the row, and printing this footnote:

A negative variance component estimate was set to zero. Consider the REML method, which estimates variance components under the constraint that they cannot be negative.

The F tests

Each term is tested with an F statistic, and the denominator is chosen the same way the component solve chooses its subtraction: the term whose expected mean square equals the numerator's with the tested component removed.

\[ F_T = \frac{MS_T}{MS_{\text{denominator}}} \]

Where that reduced expectation is the residual variance alone, the residual mean square is the denominator. This is an exact F test, and the analysis of variance table says so by not flagging it.

When the denominator has to be synthesized

In a more complicated model no single mean square matches what the denominator needs to be. A denominator is then synthesized as a combination of several mean squares whose expected value is the right one, and its degrees of freedom are approximated:

\[ \nu_{\text{denominator}} = \frac{\left(\sum_i a_i MS_i\right)^2}{\sum_i \dfrac{\left(a_i MS_i\right)^2}{\nu_i}} \]

The weights \(a_i\) come from the same elimination that chooses the denominator, and the residual always carries a weight of one minus the sum of the term weights, because every row of the system has an error coefficient of exactly one. A mean square whose weight works out to zero is left out of the printed synthesis rather than listed with a zero beside it, and the residual appears in that list under the name Error.

A negative weight is not a problem for the degrees of freedom: each contribution is squared, so a denominator formed from a difference of mean squares still gets a positive approximation.

Two visible consequences, both of which the table reports rather than hides:

  • The degrees of freedom are not in general a whole number. A fractional denominator degrees of freedom on the report is this approximation, not a rounding error.
  • The test is marked as not exact. The table prints Not an exact F-test. for such a term, and reports the denominator mean square and its degrees of freedom so the test can be traced.

Where the synthesized denominator does not come out strictly positive there is no usable F statistic at all, and the table reports no F and no p for that term rather than an arbitrary number.

The interaction removal loop

When Remove insignificant interactions is on, terms are tested and removed one at a time, and each removed term's degrees of freedom and sum of squares are pooled into the residual. A removed term's variation is therefore counted as repeatability rather than being dropped from the study.

The pooling changes the residual mean square, so every remaining term's F test and every component estimate change with it. Terms are therefore removed in successive passes rather than all at once, and the report records which pass removed a given term.

The report carries two analysis of variance tables when anything was removed, headed ANOVA (All Terms) and ANOVA (Terms used for the Gage R&R calculation), and a removed term is marked (removed) in the first. With nothing removed there is one table.

Confidence intervals on unbalanced data

On data that is not balanced, this method reports no confidence intervals at all.

The estimates themselves are still computed, by the general projector construction above, and they are reported as usual. It is only the intervals that are withheld, and the report says so in place of each bound rather than leaving the cells blank.

REML reports intervals on unbalanced data, so it is the method to choose when the intervals matter and the study is not balanced. That is also what the Automatic setting picks in that case.

See Also