Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Random Effects & Mixed Models

A fixed-effect analysis compares the particular levels under study. A random-effect analysis treats observed levels as draws from a population and asks how much variation that population contributes. The distinction comes from the sampling plan and inferential goal, not whether the factor is numeric or categorical.

One Random Factor

For aa groups and nn observations per group,

yij=μ+ui+ϵij,ui∼N(0,σu2),ϵij∼N(0,σ2),y_{ij}=\mu+u_i+\epsilon_{ij},\qquad u_i\sim N(0,\sigma_u^2),\quad\epsilon_{ij}\sim N(0,\sigma^2),

where uiu_i are independent group effects and all residuals are independent of them. The mean of the group-effect distribution is zero; the realized group effects need not sum to zero.

The marginal variance is σu2+σ2\sigma_u^2+\sigma^2. Two distinct observations in the same group share uiu_i, so their covariance is σu2\sigma_u^2. Consequently,

ρ=σu2σu2+σ2\rho=\frac{\sigma_u^2}{\sigma_u^2+\sigma^2}

is the intraclass correlation. It measures within-group similarity and the between-group fraction of marginal variance in this model.

Expected Mean Squares

The balanced ANOVA arithmetic is unchanged from a one-way fixed model. Its interpretation changes:

SourcedfExpected mean square
Groupsa−1a-1σ2+nσu2\sigma^2+n\sigma_u^2
Errora(n−1)a(n-1)σ2\sigma^2

Thus the normal-model test of H0:σu2=0H_0:\sigma_u^2=0 uses F=MSA/MSEF=MS_A/MS_E with (a−1,a(n−1))(a-1,a(n-1)) df. The alternative is positive variance, so use the upper tail.

Method-of-moments estimates are

σ^2=MSE,σ^u2=MSA−MSEn.\widehat\sigma^2=MS_E,\qquad \widehat\sigma_u^2=\frac{MS_A-MS_E}{n}.
Why the group mean square contains a factor of n

A group mean has variance Var⁡(yˉi⋅)=σu2+σ2/n\operatorname{Var}(\bar y_{i\cdot})=\sigma_u^2+\sigma^2/n. The between-group mean square is nn times the sample variance of the independent group means. Its expectation is therefore nσu2+σ2n\sigma_u^2+\sigma^2.

For an illustrative experiment with a=5a=5, n=4n=4, MSA=18MS_A=18 and MSE=2MS_E=2, the estimates are σ^u2=4\widehat\sigma_u^2=4, σ^2=2\widehat\sigma^2=2, and ρ^=2/3\widehat\rho=2/3.

A negative moment estimate can occur when MSA<MSEMS_A<MS_E. It does not imply a negative population variance. Report the estimation issue and use an appropriate nonnegative estimation method, such as constrained REML, when fitting the model; simply truncating at zero changes the estimator.

Two Crossed Random Factors

For aa levels of A, bb levels of B, and nn replicates per cell,

yijk=μ+ui+vj+wij+ϵijk.y_{ijk}=\mu+u_i+v_j+w_{ij}+\epsilon_{ijk}.

Assume mutually independent zero-mean normal effects with variances σA2,σB2,σAB2,σ2\sigma_A^2,\sigma_B^2,\sigma_{AB}^2,\sigma^2 respectively.

SourcedfExpected mean squareDenominator for testing its variance component
Aa−1a-1σ2+nσAB2+bnσA2\sigma^2+n\sigma_{AB}^2+bn\sigma_A^2MSABMS_{AB}
Bb−1b-1σ2+nσAB2+anσB2\sigma^2+n\sigma_{AB}^2+an\sigma_B^2MSABMS_{AB}
AB(a−1)(b−1)(a-1)(b-1)σ2+nσAB2\sigma^2+n\sigma_{AB}^2MSEMS_E
Errorab(n−1)ab(n-1)σ2\sigma^2,

For example, under H0:σA2=0H_0:\sigma_A^2=0, MSAMS_A and MSABMS_{AB} estimate the same quantity. Comparing A with MSEMS_E would leave interaction variation in the numerator only. Normality and the balanced orthogonal design supply the independent scaled chi-square distributions needed for these exact F tests; matching expectations alone is not sufficient in arbitrary models.

Subtracting expected mean squares gives

σ^AB2=MSAB−MSEn,σ^A2=MSA−MSABbn,σ^B2=MSB−MSABan.\widehat\sigma_{AB}^2=\frac{MS_{AB}-MS_E}{n},\quad \widehat\sigma_A^2=\frac{MS_A-MS_{AB}}{bn},\quad \widehat\sigma_B^2=\frac{MS_B-MS_{AB}}{an}.

Covariance Depends on What Is Shared

Let V=σA2+σB2+σAB2+σ2V=\sigma_A^2+\sigma_B^2+\sigma_{AB}^2+\sigma^2. Distinct observations sharing only A have covariance σA2\sigma_A^2; sharing only B gives σB2\sigma_B^2; sharing the same cell gives σA2+σB2+σAB2\sigma_A^2+\sigma_B^2+\sigma_{AB}^2. Divide the appropriate covariance by VV for the correlation. A single interaction variance fraction is not, by itself, the same-cell correlation.

A Fixed, B Random: Restricted Mixed Model

Replace uiu_i by fixed constants τi\tau_i, with ∑iτi=0\sum_i\tau_i=0. In the restricted mixed model, require

∑i=1awij=0for every j.\sum_{i=1}^a w_{ij}=0\quad\text{for every }j.

One construction is wij=qij−qˉ⋅jw_{ij}=q_{ij}-\bar q_{\cdot j} for independent qij∼N(0,σAB2)q_{ij}\sim N(0,\sigma_{AB}^2). This yields

Var⁡(wij)=a−1aσAB2,Cov⁡(wij,wi′j)=−1aσAB2(i≠i′).\operatorname{Var}(w_{ij})=\frac{a-1}{a}\sigma_{AB}^2,\qquad \operatorname{Cov}(w_{ij},w_{i'j})=-\frac1a\sigma_{AB}^2\quad(i\ne i').

Here σAB2\sigma_{AB}^2 is the covariance-scale parameter; it is not the variance of a single constrained interaction. Different B groups are independent, and vjv_j and residuals are independent of the interactions.

Derive the negative covariance

Since Var⁡(qˉ⋅j)=σAB2/a\operatorname{Var}(\bar q_{\cdot j})=\sigma_{AB}^2/a and Cov⁡(qij,qˉ⋅j)=σAB2/a\operatorname{Cov}(q_{ij},\bar q_{\cdot j})=\sigma_{AB}^2/a, subtracting the group mean gives variance σAB2(1−1/a)\sigma_{AB}^2(1-1/a). For distinct i,i′i,i', the covariance is 0−σAB2/a−σAB2/a+σAB2/a=−σAB2/a0-\sigma_{AB}^2/a-\sigma_{AB}^2/a+\sigma_{AB}^2/a=-\sigma_{AB}^2/a.

The expected mean squares become

E[MSA]=σ2+nσAB2+bna−1∑iτi2,E[MS_A]=\sigma^2+n\sigma_{AB}^2+\frac{bn}{a-1}\sum_i\tau_i^2,
E[MSB]=σ2+anσB2,E[MSAB]=σ2+nσAB2,E[MSE]=σ2.E[MS_B]=\sigma^2+an\sigma_B^2,\qquad E[MS_{AB}]=\sigma^2+n\sigma_{AB}^2,\qquad E[MS_E]=\sigma^2.
Null hypothesisF statisticNumerator / denominator df
All τi=0\tau_i=0MSA/MSABMS_A/MS_{AB}a−1a-1 / (a−1)(b−1)(a-1)(b-1)
σB2=0\sigma_B^2=0MSB/MSEMS_B/MS_Eb−1b-1 / ab(n−1)ab(n-1)
σAB2=0\sigma_{AB}^2=0MSAB/MSEMS_{AB}/MS_E(a−1)(b−1)(a-1)(b-1) / ab(n−1)ab(n-1)

The interaction cancels when averaging across all fixed A levels within a B level. That is why it is absent from E[MSB]E[MS_B]. It does not cancel from contrasts between A levels, which explains the interaction denominator for testing A.

For this restricted model, σ^B2=(MSB−MSE)/(an)\widehat\sigma_B^2=(MS_B-MS_E)/(an). There is no σA2\sigma_A^2 to estimate because A has fixed effects.

Do Not Mix Model Conventions

An unrestricted mixed model uses independent wijw_{ij} without the sum-to-zero restriction. Then E[MSB]E[MS_B] includes nσAB2n\sigma_{AB}^2, and the B test uses MSABMS_{AB}. The comparison of mixed-model conventions explains this distinction. Identify the assumptions used by a software fit before choosing an ANOVA denominator.

Practical Limits

These simple tables assume a balanced design, common residual variance, independent random components, and sufficient replication. With n=1n=1, interaction and residual variance cannot be separated by the usual cell replication. Missing cells or unequal group sizes generally require a model-based mixed-effects analysis rather than these plug-in formulas.

For a one-way model, Var⁡(yˉ⋅⋅)=σu2/a+σ2/(an)\operatorname{Var}(\bar y_{\cdot\cdot})=\sigma_u^2/a+\sigma^2/(an). More observations per group reduce residual uncertainty, but adding independent groups is needed to reduce the group component effectively. Treating all observations as independent ignores this distinction.