Tutorials › Regression Analysis (Undergraduate) › Uncertainty for Fixed-Knot Segmented Fits

Piecewise Regression and Splines · Tutorial 451 of 991

Uncertainty for Fixed-Knot Segmented Fits

Use coefficient estimates and their covariance to quantify uncertainty in fitted means, segment slopes, and comparisons across a fixed knot.

Advanced 10 min read

What You'll Learn

  • Write a fixed-knot segmented model in terms of its coefficients and design row.
  • Calculate a standard error for a fitted mean from the coefficient covariance matrix.
  • Form confidence intervals for left- and right-segment slopes.
  • Build and evaluate a linear contrast to compare fitted means at two predictor values.
  • Distinguish uncertainty in an estimated mean from variation in a future observation.
  • Recognize why knot selection and coefficient covariance matter for inference.

Why Uncertainty Requires the Coefficient Covariance

A segmented regression fit gives estimates of the mean response at predictor values and of the slopes on each segment. Those estimates are uncertain because they depend on a sample. To quantify that uncertainty, it is not enough to look at the separate standard errors of the fitted coefficients: a fitted mean or a segment slope can combine several coefficients, and those coefficient estimates may be correlated.

This tutorial considers inference when the knot locations are fixed in advance. The calculations use the estimated covariance matrix of the regression coefficients. They apply to fitted means, segment slopes, and other linear combinations of coefficients, including differences between fitted means. A confidence interval for a fitted mean describes uncertainty in the model’s mean response, not the spread of individual future responses around that mean.

Model and Assumptions

For one fixed knot at \( \kappa \), a continuous piecewise linear regression can be written using a hinge term:

$$ Y_i=\beta_0+\beta_1x_i+\beta_2(x_i-\kappa)_+ +\varepsilon_i, \qquad (x_i-\kappa)_+=\max(0,x_i-\kappa). $$

The mean response is continuous at \( \kappa \). To the left of the knot, the slope is \( \beta_1 \); to the right, it is \( \beta_1+\beta_2 \). The coefficient \( \beta_2 \) is the change in slope at the knot, not the right-segment slope by itself.

Assumptions for the usual confidence intervals: The knot locations are treated as fixed, and the model’s mean structure is correctly specified. Conditional on the predictor values, the errors have mean zero, are independent, and have common variance \( \sigma^2 \). For exact small-sample \(t\) intervals, assume also that the errors are normally distributed. The model matrix must have full column rank so that all coefficients are estimable.

With \(p\) coefficients and \(n\) observations, the residual degrees of freedom are \(df=n-p\). Let \(\hat{\boldsymbol{\beta}}\) be the vector of fitted coefficients, and let \(\widehat{\operatorname{Cov}}(\hat{\boldsymbol{\beta}})\) be its estimated covariance matrix. In ordinary least squares under these assumptions, this matrix is \(s^2(X^\mathsf{T}X)^{-1}\), where \(s\) is the residual standard deviation and \(X\) is the model matrix. It includes both the estimated variances of the coefficients and their estimated covariances.

For a predictor value \(x_0\), the fitted mean is a linear combination of the coefficients. In the one-knot model its design row is \(z(x_0)=(1,x_0,(x_0-\kappa)_+)\), so the fitted mean is \(z(x_0)\hat{\boldsymbol{\beta}}\). With multiple fixed knots, the design row contains the intercept, the predictor, and the hinge terms for those knots; the same covariance calculation applies.

Standard Errors and Confidence Intervals for Linear Combinations

Result: For any estimable linear combination \(c^\mathsf{T}\boldsymbol{\beta}\), its estimate is \(c^\mathsf{T}\hat{\boldsymbol{\beta}}\), and its estimated standard error is $$ SE(c^\mathsf{T}\hat{\boldsymbol{\beta}}) = \sqrt{c^\mathsf{T}\widehat{\operatorname{Cov}}(\hat{\boldsymbol{\beta}})c}. $$ A two-sided \(100(1-\alpha)\%\) confidence interval is $$ c^\mathsf{T}\hat{\boldsymbol{\beta}} \ \pm\ t_{1-\alpha/2,\,df}\, SE(c^\mathsf{T}\hat{\boldsymbol{\beta}}), $$ where \(t_{1-\alpha/2,\,df}\) is the corresponding quantile of the \(t\) distribution.

A fitted mean is covered by taking \(c=z(x_0)^\mathsf{T}\), with the coefficient vector treated as a column vector. A segment slope is also a linear combination: for one knot, the left slope uses \(c=(0,1,0)^\mathsf{T}\), and the right slope uses \(c=(0,1,1)^\mathsf{T}\). A comparison between two fitted means uses the difference between their design rows as its contrast.

The standard error is not usually obtained by adding the individual coefficient standard errors. The covariance terms contribute to the variance of a combination, and may increase or decrease it.

Why the Contrast Formula Works

The formula follows from the variance of a linear combination. If \(c\) is fixed, then subtracting the true value from the estimated contrast gives \(c^\mathsf{T}(\hat{\boldsymbol{\beta}}-\boldsymbol{\beta})\). Applying the variance rule for a fixed matrix multiplying a random vector gives:

$$ \begin{aligned} \operatorname{Var}\!\left(c^\mathsf{T}\hat{\boldsymbol{\beta}}\right) &= \operatorname{Var}\!\left(c^\mathsf{T}(\hat{\boldsymbol{\beta}}-\boldsymbol{\beta})\right)\\ &= c^\mathsf{T}\operatorname{Cov}(\hat{\boldsymbol{\beta}})c. \end{aligned} $$

Replacing the unknown coefficient covariance matrix with its estimate gives the estimated variance; taking its square root gives the standard error. Under the stated normal-error and fixed-design assumptions, the estimated contrast divided by its standard error, after centering at its true value, has a \(t\) distribution with \(df=n-p\). Using the appropriate \(t\) quantile therefore gives the stated confidence interval.

Worked Example: A Fitted Mean at a Predictor Value

Suppose a hypothetical study relates \(Y\), measured in outcome units, to \(x\), measured in days, using one fixed knot at day \(5\). There are \(n=27\) observations and \(p=3\) coefficients, so \(df=24\). The fitted coefficients are \(\hat{\beta}_0=10\), \(\hat{\beta}_1=1.2\), and \(\hat{\beta}_2=-0.4\). The estimated coefficient covariance matrix is:

$$ \widehat{\operatorname{Cov}}(\hat{\boldsymbol{\beta}}) = \begin{pmatrix} 4 & 0.10 & -0.20\\ 0.10 & 0.04 & -0.01\\ -0.20 & -0.01 & 0.09 \end{pmatrix}. $$

Find a 95% confidence interval for the mean response at day \(6\). The hinge value is \((6-5)_+=1\), so the design row is \(z(6)=(1,6,1)\). The estimated mean is:

$$ \hat{\mu}(6)=10+6(1.2)+1(-0.4)=10+7.2-0.4=16.8 \quad\text{outcome units}. $$

The estimated variance of this fitted mean uses all entries in the covariance matrix:

$$ \begin{aligned} \widehat{\operatorname{Var}}\{\hat{\mu}(6)\} &=z(6)\widehat{\operatorname{Cov}}(\hat{\boldsymbol{\beta}})z(6)^\mathsf{T}\\ &=4+36(0.04)+1(0.09)+2(6)(0.10)+2(1)(-0.20)+2(6)(-0.01)\\ &=4+1.44+0.09+1.20-0.40-0.12\\ &=6.21. \end{aligned} $$

Thus \(SE\{\hat{\mu}(6)\}=\sqrt{6.21}=2.492\) outcome units. For \(df=24\), the 95% critical value is approximately \(t_{0.975,24}=2.064\). The interval is:

$$ 16.8\pm 2.064(2.492) = 16.8\pm 5.143 = (11.657,\ 21.943) \quad\text{outcome units}. $$

On the basis of this model, the 95% confidence interval for the mean response at day \(6\) is approximately 11.66 to 21.94 outcome units. It is an interval for the mean, not a prediction interval for one new response.

Worked Example: Confidence Intervals for Both Segment Slopes

Use the fitted coefficients and covariance matrix from the previous example. The estimated left-segment slope is \(\hat{\beta}_1=1.2\) outcome units per day. Its variance is the variance of \(\hat{\beta}_1\), which is \(0.04\), so its standard error is \(\sqrt{0.04}=0.200\) outcome units per day. Using \(t_{0.975,24}=2.064\):

$$ 1.2\pm2.064(0.200) = 1.2\pm0.4128 = (0.7872,\ 1.6128) \quad\text{outcome units per day}. $$

The estimated right-segment slope is not \(\hat{\beta}_2\) alone. It is \(\hat{\beta}_1+\hat{\beta}_2=1.2-0.4=0.800\) outcome units per day. Its estimated variance includes the covariance between the two slope coefficients:

$$ \begin{aligned} \widehat{\operatorname{Var}}(\hat{\beta}_1+\hat{\beta}_2) &=0.04+0.09+2(-0.01)\\ &=0.11, \qquad SE=\sqrt{0.11}=0.3317 \quad\text{outcome units per day}. \end{aligned} $$

The 95% confidence interval for the right-segment slope is:

$$ 0.800\pm2.064(0.3317) = 0.800\pm0.6846 = (0.1154,\ 1.485) \quad\text{outcome units per day}. $$

These are separate pointwise intervals for the two slopes. The right-slope interval uses the uncertainty in both coefficients and their covariance. Neither interval is, by itself, a simultaneous confidence statement about both slopes.

Worked Example: Comparing Two Fitted Means

Using the same hypothetical model, compare the mean response at day \(6\) with the mean response at day \(2\). The design rows are \(z(6)=(1,6,1)\) and \(z(2)=(1,2,0)\). Their difference is \((0,4,1)\), so the estimated difference is:

$$ \hat{\mu}(6)-\hat{\mu}(2) = 0(10)+4(1.2)+1(-0.4) = 4.8-0.4 = 4.4 \quad\text{outcome units}. $$

The contrast has no intercept component. Its estimated variance is:

$$ \begin{aligned} \widehat{\operatorname{Var}}\{\hat{\mu}(6)-\hat{\mu}(2)\} &=16(0.04)+1(0.09)+2(4)(-0.01)\\ &=0.64+0.09-0.08\\ &=0.65. \end{aligned} $$

The standard error is \(\sqrt{0.65}=0.8062\) outcome units. The 95% confidence interval is:

$$ 4.4\pm2.064(0.8062) = 4.4\pm1.664 = (2.736,\ 6.064) \quad\text{outcome units}. $$

The estimated mean response at day \(6\) is 4.4 outcome units higher than at day \(2\). The interval describes uncertainty in this model-based difference in mean responses, conditional on the fixed predictor values and the fitted model.

Common Mistakes and Interpretation

  • Using the change in slope as the right slope. The coefficient \(\beta_2\) is the change from the left slope to the right slope. The right slope is \(\beta_1+\beta_2\).
  • Ignoring covariance terms. For a sum or difference of coefficients, use the full contrast formula. For example, the variance of \(\hat{\beta}_1+\hat{\beta}_2\) includes \(2\widehat{\operatorname{Cov}}(\hat{\beta}_1,\hat{\beta}_2)\).
  • Adding standard errors directly. Standard errors do not generally add to give the standard error of a sum. First calculate the contrast variance, then take its square root.
  • Calling a mean interval a prediction interval. A fitted-mean interval quantifies uncertainty about the mean response. A future individual response also varies around that mean, so its prediction interval is wider.
  • Treating a data-chosen knot as fixed without qualification. These intervals treat knot locations as fixed. If a knot was selected using the same data, the formulas here do not account for the additional uncertainty from that selection.

For a model with several fixed knots, the principle does not change: express the quantity of interest as a linear combination of the fitted coefficients, form its contrast vector, and calculate its standard error using the estimated coefficient covariance matrix. The choice of contrast is what turns the same fitted model into an interval for a mean, a segment slope, or a comparison.

Check Your Understanding

Try these questions using the definitions and results above.

  1. In a one-knot model, what does \(\beta_2\) represent, and how is the right-segment slope expressed?
  2. Why does the standard error for a fitted mean depend on the covariance terms among coefficient estimates?
  3. A contrast is \(2\beta_1-\beta_2\). Write its estimated value and its estimated variance in terms of the coefficient estimates and their covariance matrix.
  4. What does a 95% confidence interval for a fitted mean describe, and how does that differ from a prediction interval?
  5. Why do the usual fixed-knot intervals require qualification if the knot was selected using the same data?