Tutorials › Generalized Linear Models › Gaussian Tests for Linear Contrasts

Gaussian GLMs and Weights · Tutorial 338 of 981

Gaussian Tests for Linear Contrasts

Learn to specify a coefficient contrast, calculate its standard error, and use the resulting t distribution for an exact test and confidence interval.

Beginner 9 min read

What You'll Learn

  • Express a linear combination of regression coefficients as a contrast vector.
  • Calculate a contrast’s estimated variance, including covariance terms.
  • Construct the t statistic for testing a specified contrast value.
  • Form an exact confidence interval using residual degrees of freedom.
  • Distinguish estimated dispersion from the covariance matrix’s design component.

Why Test a Contrast?

A regression model estimates several coefficients, but a scientific question often concerns a particular combination of them. For example, a researcher may ask whether two slopes are equal, or whether a weighted sum of coefficients has a specified value. Such questions are expressed as linear contrasts. The uncertainty in a contrast depends not only on the uncertainties of the individual coefficient estimates, but also on how those estimates covary.

Here we use the Gaussian linear regression model with known positive precision weights and an unknown common dispersion. The results give exact t tests and confidence intervals under the model’s assumptions. They use the coefficient covariance matrix from weighted least squares, together with the residual estimate of dispersion.

Model and Contrast Notation

Definition: Let \(Y_1,\ldots,Y_n\) be independent responses with \(Y_i\sim N(x_i^\mathsf{T}\beta,\phi/w_i)\), where \(w_i>0\) are known precision weights and \(\phi>0\) is an unknown dispersion. Write \(X\) for the \(n\times p\) design matrix, \(W=\operatorname{diag}(w_1,\ldots,w_n)\), and \(\beta=(\beta_0,\ldots,\beta_{p-1})^\mathsf{T}\). Assume \(X\) has full column rank and \(n>p\). A contrast is a specified scalar \(a^\mathsf{T}\beta\), where \(a=(a_0,\ldots,a_{p-1})^\mathsf{T}\) is fixed.

The coefficient indices here run from \(0\) through \(p-1\). Thus the entries of \(a\) must match the order of the entries in \(\beta\). A zero entry means that the corresponding coefficient does not contribute to the contrast. The weighted least-squares estimate and the residual dispersion estimate are

$$ \hat{\beta}=(X^\mathsf{T}WX)^{-1}X^\mathsf{T}WY,\qquad s^2=\frac{\operatorname{RSS}_W}{n-p},\qquad \operatorname{RSS}_W=(Y-X\hat{\beta})^\mathsf{T}W(Y-X\hat{\beta}). $$

The estimated covariance matrix of \(\hat{\beta}\) is \(s^2(X^\mathsf{T}WX)^{-1}\). Consequently, the estimated variance of a contrast estimate is obtained by applying the contrast vector to both sides of that matrix. This calculation includes off-diagonal entries: ignoring them can give the wrong standard error.

From Coefficient Covariance to Contrast Standard Error

Theorem: Under the model and rank assumptions above, define \(C=(X^\mathsf{T}WX)^{-1}\). Then \[ E[\hat{\beta}]=\beta,\qquad \operatorname{Cov}(\hat{\beta})=\phi C. \] For a fixed contrast vector \(a\), the estimate \(a^\mathsf{T}\hat{\beta}\) has variance \(\phi\,a^\mathsf{T}Ca\), and its estimated standard error is \[ \operatorname{SE}(a^\mathsf{T}\hat{\beta})=s\sqrt{a^\mathsf{T}Ca}. \]

To verify the covariance calculation, note that \(E[Y]=X\beta\) and \(\operatorname{Cov}(Y)=\phi W^{-1}\). Substituting the weighted least-squares expression gives

$$ E[\hat{\beta}] =(X^\mathsf{T}WX)^{-1}X^\mathsf{T}WX\beta =\beta, $$
$$ \begin{aligned} \operatorname{Cov}(\hat{\beta}) &=(X^\mathsf{T}WX)^{-1}X^\mathsf{T}W (\phi W^{-1})WX(X^\mathsf{T}WX)^{-1}\\ &=\phi(X^\mathsf{T}WX)^{-1} =\phi C. \end{aligned} $$

For any fixed vector \(a\), the variance of a linear transformation is \(a^\mathsf{T}\operatorname{Cov}(\hat{\beta})a\). Therefore

$$ \operatorname{Var}(a^\mathsf{T}\hat{\beta}) =a^\mathsf{T}(\phi C)a =\phi\,a^\mathsf{T}Ca. $$

Replacing the unknown \(\phi\) by \(s^2\) gives the estimated variance \(s^2a^\mathsf{T}Ca\), and taking its nonnegative square root gives the stated standard error. Since \(C\) is positive definite under full column rank, \(a^\mathsf{T}Ca>0\) for every nonzero \(a\). A zero vector defines the identically zero contrast and is not a useful test.

Worked Example: Testing Whether Two Coefficients Are Equal

Suppose \(p=3\), with coefficients \((\beta_0,\beta_1,\beta_2)\), and the fitted estimates are \((2.0,3.1,1.7)\). The design component of the covariance matrix and residual dispersion estimate are

$$ C= \begin{pmatrix} 0.04&0&0\\ 0&0.09&0.02\\ 0&0.02&0.16 \end{pmatrix}, \qquad s^2=4,\qquad n-p=18. $$

To test whether \(\beta_1=\beta_2\), write the contrast as \(\beta_1-\beta_2\). Under the stated coefficient ordering, its vector is \(a=(0,1,-1)^\mathsf{T}\). The estimated contrast is

$$ a^\mathsf{T}\hat{\beta}=0(2.0)+1(3.1)-1(1.7)=1.4. $$

The covariance term matters in the variance calculation:

$$ a^\mathsf{T}Ca=0.09+0.16-2(0.02)=0.21,\qquad \widehat{\operatorname{Var}}(a^\mathsf{T}\hat{\beta})=4(0.21)=0.84. $$

Thus the standard error is \(\sqrt{0.84}\approx0.9165\). For \(H_0:\beta_1-\beta_2=0\), the test statistic is \(t=1.4/0.9165\approx1.528\), with 18 degrees of freedom under the null. The two-sided p-value is \(2P(T_{18}\geq1.528)\). A 95% confidence interval, using \(t_{18,0.975}\approx2.101\), is

$$ 1.4\pm2.101(0.9165) =1.4\pm1.9256 \approx(-0.526,\ 3.326). $$

This interval contains zero, consistent with not rejecting the equality null at the 5% two-sided level.

Exact t Tests and Confidence Intervals

Theorem: Under the Gaussian model, with independent responses, known positive weights, full column rank \(X\), and \(n>p\), for any fixed nonzero contrast vector \(a\), the statistic \[ T=\frac{a^\mathsf{T}\hat{\beta}-a^\mathsf{T}\beta} {s\sqrt{a^\mathsf{T}Ca}} \] has a Student t distribution with \(n-p\) degrees of freedom. Therefore, under \(H_0:a^\mathsf{T}\beta=\psi_0\), replacing \(a^\mathsf{T}\beta\) in the numerator by \(\psi_0\) gives an exact t test. A \(100(1-\alpha)\%\) confidence interval is \[ a^\mathsf{T}\hat{\beta}\ \pm\ t_{n-p,1-\alpha/2}\,s\sqrt{a^\mathsf{T}Ca}. \]

For a proof, let \(Z=W^{1/2}X\) and \(\varepsilon^*=W^{1/2}(Y-X\beta)\). Because the responses are independent Gaussian variables with variances \(\phi/w_i\), \(\varepsilon^*\sim N(0,\phi I_n)\). Let \(P=Z(Z^\mathsf{T}Z)^{-1}Z^\mathsf{T}\), the orthogonal projection onto the column space of \(Z\). Direct substitution into the weighted least-squares estimator gives

$$ \hat{\beta}-\beta=(Z^\mathsf{T}Z)^{-1}Z^\mathsf{T}\varepsilon^*, \qquad \operatorname{RSS}_W=(\varepsilon^*)^\mathsf{T}(I-P)\varepsilon^*. $$

The first expression is a linear transformation of a Gaussian vector, so \(a^\mathsf{T}\hat{\beta}-a^\mathsf{T}\beta\) is Gaussian with mean zero and variance \(\phi a^\mathsf{T}Ca\). The matrix \(P\) is symmetric and idempotent with rank \(p\); hence \(I-P\) is symmetric and idempotent with rank \(n-p\). The Gaussian quadratic-form result for an idempotent projection therefore gives \(\operatorname{RSS}_W/\phi\sim\chi^2_{n-p}\).

Finally, \(P(I-P)=0\). The coefficient estimation error depends only on the projection of \(\varepsilon^*\) onto the column space of \(Z\), while the residual vector depends only on its orthogonal complement. These are jointly Gaussian linear transformations with zero cross-covariance, so they are independent. Thus the standardized contrast numerator is a standard normal variable independent of \(\operatorname{RSS}_W/\phi\). Since \(s^2=\operatorname{RSS}_W/(n-p)\), their ratio has the Student t distribution with \(n-p\) degrees of freedom. Inverting the two-sided test yields the displayed confidence interval. \(\square\)

The interval is for the fixed coefficient contrast \(a^\mathsf{T}\beta\), not for a future response. Its width is determined by the chosen contrast, the fitted design and weights through \(C\), and the residual dispersion estimate through \(s\).

Worked Example: Testing a General Linear Combination

Consider a two-coefficient model with \(\hat{\beta}=(1.0,0.5)^\mathsf{T}\), \(s^2=1.5\), \(n=12\), and

$$ C= \begin{pmatrix} 0.25&0.05\\ 0.05&0.04 \end{pmatrix}. $$

Suppose the target is \(\psi=\beta_0+2\beta_1\), so \(a=(1,2)^\mathsf{T}\). The estimate is \(1.0+2(0.5)=2.0\). Its design variance factor is

$$ a^\mathsf{T}Ca =0.25+2(0.05)(2)+4(0.04) =0.25+0.20+0.16 =0.61. $$

The estimated variance is \(1.5(0.61)=0.915\), giving standard error \(\sqrt{0.915}\approx0.9566\). For the null hypothesis \(H_0:\beta_0+2\beta_1=1\), with \(n-p=10\) degrees of freedom,

$$ t=\frac{2.0-1}{0.9566}\approx1.045. $$

The two-sided p-value is \(2P(T_{10}\geq1.045)\). A 95% confidence interval uses \(t_{10,0.975}\approx2.228\):

$$ 2.0\pm2.228(0.9566) =2.0\pm2.131 \approx(-0.131,\ 4.131). $$

The off-diagonal covariance contributes \(0.20\) to \(a^\mathsf{T}Ca\). Omitting it would not reproduce the variance implied by the fitted coefficient covariance matrix.

Writing the Test and Reading the Interval

For a specified null value \(\psi_0\), the test statistic and its null reference distribution are

$$ t_{\mathrm{obs}}= \frac{a^\mathsf{T}\hat{\beta}-\psi_0} {s\sqrt{a^\mathsf{T}Ca}}, \qquad T\mid H_0\sim t_{n-p}. $$

A two-sided test rejects at level \(\alpha\) when \(|t_{\mathrm{obs}}|>t_{n-p,1-\alpha/2}\). Its p-value is \(2P(T_{n-p}\geq|t_{\mathrm{obs}}|)\). For a one-sided alternative, use the corresponding tail probability and critical value. The confidence interval contains exactly those null values that would not be rejected by the corresponding two-sided test.

If \(\phi\) were known rather than estimated, the contrast standardized by \(\sqrt{\phi a^\mathsf{T}Ca}\) would have a standard normal distribution. The t distribution arises here because the same data estimate dispersion, and the independent residual variance estimate contributes a chi-square denominator. This distinction is why the residual degrees of freedom \(n-p\) are part of the test.

Worked Example: A Difference in a Four-Coefficient Model

Let \(p=4\), with ordering \((\beta_0,\beta_1,\beta_2,\beta_3)\). Suppose the fitted coefficients are \((0.8,1.2,-0.4,0.5)\), \(n=20\), \(s^2=0.64\), and the relevant entries of \(C\) are \(C_{22}=0.09\), \(C_{33}=0.16\), and \(C_{23}=C_{32}=0.03\). To compare \(\beta_2\) with \(\beta_3\), use \(a=(0,0,1,-1)^\mathsf{T}\). The estimated difference is \(-0.4-0.5=-0.9\), and

$$ a^\mathsf{T}Ca=0.09+0.16-2(0.03)=0.19,\qquad \widehat{\operatorname{Var}}(a^\mathsf{T}\hat{\beta})=0.64(0.19)=0.1216. $$

The standard error is \(\sqrt{0.1216}\approx0.3487\). For \(H_0:\beta_2-\beta_3=0\), the degrees of freedom are \(20-4=16\), and \(t=-0.9/0.3487\approx-2.581\). The 95% confidence interval, using \(t_{16,0.975}\approx2.120\), is

$$ -0.9\pm2.120(0.3487) =-0.9\pm0.7392 \approx(-1.639,\ -0.161). $$

The interval excludes zero, so the two-sided test rejects equality at the 5% level. The four entries of \(a\) align with the four coefficients: its third and fourth entries select \(\beta_2\) and \(-\beta_3\), respectively.

Common Mistake: Dropping Covariances or Misaligning Indices

A frequent error is to calculate the variance of a difference as the sum of the two coefficient variances. In general,

$$ \operatorname{Var}(\hat{\beta}_j-\hat{\beta}_k) =\operatorname{Var}(\hat{\beta}_j)+\operatorname{Var}(\hat{\beta}_k) -2\operatorname{Cov}(\hat{\beta}_j,\hat{\beta}_k). $$

The incorrect reasoning is that a minus sign changes the estimate but not its variance. The correction is to apply \(a^\mathsf{T}\widehat{\operatorname{Cov}}(\hat{\beta})a\), which necessarily includes the cross terms. A second source of error is mismatching a contrast vector and the coefficient order. For instance, with \((\beta_0,\beta_1,\beta_2)\), the vector \((0,1,-1)^\mathsf{T}\) selects \(\beta_1-\beta_2\), not \(\beta_2-\beta_3\). Always write the coefficient order first, then assign one contrast-vector entry to each coefficient.

Key takeaway: For a Gaussian linear contrast, calculate the estimate \(a^\mathsf{T}\hat{\beta}\), its standard error \(s\sqrt{a^\mathsf{T}(X^\mathsf{T}WX)^{-1}a}\), and use a \(t_{n-p}\) reference distribution when dispersion is estimated. Keep coefficient indices aligned and retain covariance terms.

Check Your Understanding

Use the model assumptions and coefficient ordering stated in this tutorial.

  1. For coefficients \((\beta_0,\beta_1,\beta_2)\), write a contrast vector for \(\beta_0+3\beta_2\).
  2. Why can the variance of \(\hat{\beta}_1-\hat{\beta}_2\) not generally be found by adding only the two coefficient variances?
  3. In a model with \(n=25\) observations and \(p=4\) coefficients, what degrees of freedom are used for the contrast t test?
  4. What additional distributional fact, beyond the normality of the contrast estimate, makes the t statistic exact?
  5. How does the confidence interval for a contrast relate to the corresponding two-sided hypothesis tests?
Clinical Biostats