Tutorials › Regression Analysis (Undergraduate) › Lack-of-Fit Tests With Replicated Predictor Settings

Specification Checks and Residual Patterns · Tutorial 582 of 991

Lack-of-Fit Tests With Replicated Predictor Settings

Use replication at identical predictor settings to assess whether a proposed regression mean structure fits the observed pattern.

Advanced 9 min read

What You'll Learn

  • Distinguish pure error within replicated settings from lack of fit between setting means and a proposed model.
  • Calculate the sums of squares and degrees of freedom for a lack-of-fit test.
  • Form and interpret the test statistic and its upper-tail p-value.
  • State the assumptions that justify the exact F test.
  • Recognize when a proposed model leaves no degrees of freedom for testing lack of fit.

Why Replication Makes a Lack-of-Fit Test Possible

Residual plots can suggest that a proposed regression mean structure misses a pattern, but a residual alone combines two sources of variation: ordinary observation-to-observation noise and systematic disagreement between the model and the mean response. When several observations have exactly the same predictor settings, their responses provide a direct estimate of the noise variation at those settings. This makes it possible to separate these sources and test whether the proposed mean structure is adequate.

The test asks whether the differences between observed setting means and model-fitted means are larger than would be expected from the variation among replicates. Rejection is evidence against the proposed mean structure; it does not identify the correct replacement model, and it does not establish that any particular alternative is true.

Pure Error and Lack of Fit

Suppose there are \(m\) distinct predictor settings. At setting \(i\), there are \(n_i\) observations, with responses \(y_{ij}\), where \(j=1,\ldots,n_i\). The total sample size is \(n=\sum_{i=1}^{m}n_i\). A setting means the complete set of predictor values: in a multiple-predictor model, observations are replicates only if all their predictors agree.

Let \(\bar{y}_i\) be the mean response among the replicates at setting \(i\). At each setting, the responses vary around this mean. Their squared deviations add up to the pure-error sum of squares. This variation is called pure error because the fitted mean at one setting cannot account for differences among observations that share that setting.

Definition: The pure-error sum of squares is \(SS_{\mathrm{PE}}=\sum_{i=1}^{m}\sum_{j=1}^{n_i}(y_{ij}-\bar{y}_i)^2\). Its degrees of freedom are \(df_{\mathrm{PE}}=n-m\), since estimating one mean at each of the \(m\) settings uses \(m\) degrees of freedom.

Now fit the proposed regression mean structure to all \(n\) observations by least squares. Suppose its design matrix has rank \(q\), meaning the fitted model estimates \(q\) independent coefficients. The model residual sum of squares is \(SSE\). A setting's fitted mean is the value predicted by that model at its predictor values. The model's lack-of-fit sum of squares measures the weighted squared gaps between the observed setting means and those fitted means.

Definition: The lack-of-fit sum of squares is \(SS_{\mathrm{LOF}}=\sum_{i=1}^{m}n_i(\bar{y}_i-\hat{y}_i)^2\), where \(\hat{y}_i\) is the fitted mean at setting \(i\). For a least-squares model that includes an intercept, \(SSE=SS_{\mathrm{PE}}+SS_{\mathrm{LOF}}\). If the setting-level design matrix has rank \(q\), then \(df_{\mathrm{LOF}}=m-q\).

The factor \(n_i\) is essential: a discrepancy at a setting with more observations contributes more to the lack-of-fit sum of squares. In the common case of a model with an intercept, the number \(q\) is the number of estimated coefficients, provided they are linearly independent. The general rank formulation handles redundant or dependent model terms correctly.

Why the Sums of Squares Separate

At each setting, subtract and add the setting mean when writing a model residual: \(y_{ij}-\hat{y}_i=(y_{ij}-\bar{y}_i)+(\bar{y}_i-\hat{y}_i)\). Squaring and summing gives a within-setting term, a setting-mean discrepancy term, and a cross-product. The cross-product is zero because \(\sum_j(y_{ij}-\bar{y}_i)=0\) at every setting. Therefore:

$$ \begin{aligned} \sum_{i=1}^{m}\sum_{j=1}^{n_i}(y_{ij}-\hat{y}_i)^2 &=\sum_{i=1}^{m}\sum_{j=1}^{n_i}(y_{ij}-\bar{y}_i)^2 +\sum_{i=1}^{m}n_i(\bar{y}_i-\hat{y}_i)^2\\ &\quad+2\sum_{i=1}^{m}(\bar{y}_i-\hat{y}_i)\sum_{j=1}^{n_i}(y_{ij}-\bar{y}_i)\\ &=SS_{\mathrm{PE}}+SS_{\mathrm{LOF}}. \end{aligned} $$

The degrees of freedom split in the same way. The replicate deviations use \(n-m\) degrees of freedom. Among the \(m\) setting means, fitting a rank-\(q\) mean structure leaves \(m-q\) degrees of freedom to measure lack of fit. Thus \(n-q=(n-m)+(m-q)\), matching the total residual degrees of freedom from the regression fit.

The Lack-of-Fit F Test

The null hypothesis is that the proposed regression mean structure gives the true mean response at every observed setting. The alternative is that at least one setting's mean is not represented by that structure. The test compares the lack-of-fit mean square with the pure-error mean square.

Theorem: If the errors are independent and normally distributed with mean zero and a common variance \(\sigma^2\), and the predictor settings are treated as fixed, then under \(H_0\), \(MS_{\mathrm{LOF}}=SS_{\mathrm{LOF}}/(m-q)\) and \(MS_{\mathrm{PE}}=SS_{\mathrm{PE}}/(n-m)\) are independent estimates of \(\sigma^2\). When \(m>q\) and \(n>m\), the statistic \(F=MS_{\mathrm{LOF}}/MS_{\mathrm{PE}}\) has an \(F\) distribution with \(m-q\) and \(n-m\) degrees of freedom. Large values count against \(H_0\).

The test is therefore an upper-tail test. Its p-value is the probability, assuming \(H_0\) and the stated assumptions, of obtaining an \(F\) statistic at least as large as the observed value. At significance level \(\alpha\), reject \(H_0\) if the p-value is less than \(\alpha\). A small p-value indicates that the discrepancies between setting means and fitted means are large relative to the replicate variation.

The normality and common-variance assumptions are needed for the exact F distribution, as is independence across observations. Replication estimates pure error directly, but it does not make these assumptions automatically true. If the response spread differs substantially across settings or observations are dependent, the standard test may not have its stated reference distribution.

Worked Example: Counting Replicates and Degrees of Freedom

A hypothetical experiment records responses at four distinct predictor settings, with three observations at each setting. A proposed regression model has an intercept and two independent predictor terms. Find the sample size, pure-error degrees of freedom, lack-of-fit degrees of freedom, and total residual degrees of freedom.

There are \(m=4\) settings, each with \(n_i=3\), so \(n=4(3)=12\). The model has rank \(q=3\). Therefore:

$$ df_{\mathrm{PE}}=n-m=12-4=8,\qquad df_{\mathrm{LOF}}=m-q=4-3=1,\qquad df_{\mathrm{residual}}=n-q=12-3=9. $$

The split checks: \(8+1=9\). If the model's residual sum of squares were 18.0 and the pure-error sum of squares were 12.0, then \(SS_{\mathrm{LOF}}=18.0-12.0=6.0\). The test would compare \(6.0/1\) with \(12.0/8\), using \(F_{1,8}\). These sums of squares are hypothetical; the calculation illustrates how the degrees of freedom and sums of squares fit together.

A Complete Test With Four Replicated Settings

Consider a hypothetical response measured twice at each of four predictor settings \(x=0,1,2,3\). The proposed mean structure is linear: \(E(Y\mid x)=\beta_0+\beta_1x\). The table gives the responses in arbitrary response units.

Setting \(x\)Replicate responsesSetting mean
09.3, 11.310.3
110.1, 12.111.1
213.9, 15.914.9
314.7, 16.715.7

At each setting, the two responses differ from their mean by \(-1\) and \(1\). The pure-error sum of squares is thus \(1+1=2\) at each of the four settings, for a total of \(4(2)=8\). There are \(n=8\) observations and \(m=4\) settings, so \(df_{\mathrm{PE}}=8-4=4\).

To find the lack of fit, compare the setting means with the fitted line. The means equal \(10+2x\) plus the deviations \(0.3,-0.9,0.9,-0.3\), respectively. Those deviations sum to zero, and their products with the centered predictor values \(-1.5,-0.5,0.5,1.5\) also sum to zero: \(0.3(-1.5)+(-0.9)(-0.5)+(0.9)(0.5)+(-0.3)(1.5)=0\). Thus the deviations are orthogonal to both the intercept and the linear predictor, so the fitted line is \(10+2x\). The squared gaps at the four settings are \(0.09,0.81,0.81,0.09\). Each setting has two replicates, giving:

$$ SS_{\mathrm{LOF}}=2(0.09+0.81+0.81+0.09)=3.60. $$

The line has rank \(q=2\), so \(df_{\mathrm{LOF}}=m-q=4-2=2\). The test statistic is:

$$ F=\frac{SS_{\mathrm{LOF}}/df_{\mathrm{LOF}}}{SS_{\mathrm{PE}}/df_{\mathrm{PE}}} =\frac{3.60/2}{8/4}=0.900. $$

For an \(F\) distribution with 2 and 4 degrees of freedom, the upper-tail probability at 0.900 is approximately 0.476. At \(\alpha=0.05\), do not reject \(H_0\): these data do not provide strong evidence that the linear mean structure fails at the four observed settings. This is not proof that the true mean is linear, nor does it guarantee adequate fit at predictor values outside the observed settings.

Worked Example: A Test With Three Predictor Settings

In a second hypothetical data set, responses are observed twice at \(x=0,1,2\). The setting means are 5, 7, and 8. At every setting the two responses are 0.5 below and 0.5 above the setting mean. Test the proposed linear mean structure using the lack-of-fit test.

The pure-error contribution at each setting is \(0.5^2+0.5^2=0.50\), so \(SS_{\mathrm{PE}}=3(0.50)=1.50\) and \(df_{\mathrm{PE}}=6-3=3\). A least-squares line through the three setting means has slope \((8-5)/2=1.5\) and intercept \(5.1667\). Its fitted values at \(x=0,1,2\) are 5.1667, 6.6667, and 8.1667. The gaps between observed and fitted means are \(-0.1667,0.3333,-0.1667\). Weighting their squared values by two replicates per setting gives:

$$ SS_{\mathrm{LOF}}=2\left[(-0.1667)^2+(0.3333)^2+(-0.1667)^2\right]\approx0.3333. $$

Here \(m=3\), \(q=2\), and \(df_{\mathrm{LOF}}=1\). Therefore \(F=(0.3333/1)/(1.50/3)\approx0.667\), with \(df=(1,3)\). The upper-tail p-value is approximately 0.474. At the 0.05 level, do not reject the linear mean structure. As before, this decision reflects the evidence in these observations, not certainty that the model is correct.

When the Test Has No Lack-of-Fit Degrees of Freedom

A proposed model may be flexible enough to fit every distinct setting mean. In that case \(q=m\), so \(df_{\mathrm{LOF}}=0\). For example, a model that assigns a separate mean to each of four categorical groups has four setting means and rank four. Replicates within groups still allow pure error to be calculated, but there is no remaining contrast among group means with which to test lack of fit. The same limitation occurs if there are no replicated settings: then \(n=m\) and \(df_{\mathrm{PE}}=0\), so pure error cannot be estimated from these data.

Worked Example: A Saturated Setting-Means Model

Suppose a hypothetical study has three categorical predictor settings with responses \((4,6)\), \((7,9)\), and \((8,10)\). The setting means are 5, 8, and 9. A model with a separate mean for each setting has \(m=3\) and \(q=3\), so \(df_{\mathrm{LOF}}=3-3=0\); a lack-of-fit F test cannot be formed.

The pure-error sum of squares is \((4-5)^2+(6-5)^2+(7-8)^2+(9-8)^2+(8-9)^2+(10-9)^2=6\), with \(df_{\mathrm{PE}}=6-3=3\). This estimates within-setting variation, but it cannot answer whether the separate group means follow some simpler structure. That requires a proposed structure with fewer than three independent setting-level parameters, leaving positive lack-of-fit degrees of freedom.

Common Mistakes and Practical Meaning

  • Counting only one replicate's deviation. Pure error includes every observation's squared deviation from its setting mean. With two observations at a setting, both squared deviations must be included.
  • Using the wrong denominator degrees of freedom. Pure-error degrees of freedom are \(n-m\), not the model's full residual degrees of freedom \(n-q\). The latter divide into pure error and lack of fit.
  • Calling a non-significant result proof of fit. A large p-value means the data do not give strong evidence of lack of fit under the test assumptions. Limited replication or a small number of settings may leave the test with little ability to detect departures.
  • Assuming any repeated predictor value is replication. In multiple regression, the full predictor vector must match. Repeating one predictor while other predictors differ does not give replicated settings.
  • Interpreting rejection as identifying the cause. Rejection flags disagreement with the proposed mean structure at the observed settings. It does not specify whether curvature, an omitted term, a data problem, or another feature explains that disagreement.

The lack-of-fit test is useful because it compares model departures with a noise estimate drawn from the data themselves. Its conclusion is local to the observed predictor settings and depends on the assumptions behind the F reference distribution. Read alongside residual plots and subject-matter knowledge, it provides a formal check on a proposed mean structure without turning a single p-value into a model-selection rule.

Check Your Understanding

For each question, identify the relevant quantities and explain your reasoning.

  1. There are five distinct settings, each observed three times, and the proposed model has rank 3. Find \(n\), \(df_{\mathrm{PE}}\), and \(df_{\mathrm{LOF}}\).
  2. Explain why pure error is computed from deviations around each setting's response mean rather than around the regression fitted value.
  3. If \(SS_{\mathrm{LOF}}=6\), \(df_{\mathrm{LOF}}=2\), \(SS_{\mathrm{PE}}=12\), and \(df_{\mathrm{PE}}=6\), calculate \(F\).
  4. What does rejection of the lack-of-fit null hypothesis establish, and what does it not establish?
  5. Why can a saturated setting-means model have replicated observations but no lack-of-fit test?