Tutorials › Regression Analysis (Undergraduate) › Robust Tests for Linear Contrasts

Unequal Variance and Robust Uncertainty · Tutorial 532 of 991

Robust Tests for Linear Contrasts

Use the full robust covariance matrix to calculate a contrast’s standard error and test a linear hypothesis about regression coefficients.

Advanced 11 min read

What You'll Learn

  • Define a linear contrast of regression coefficients
  • Calculate its robust variance from the full covariance matrix
  • Test a null value using a large-sample normal statistic
  • Interpret the test and its p-value in context
  • Identify why ignoring coefficient covariances can give the wrong result

Why Test a Contrast?

A regression analysis often asks about a particular combination of coefficients, not just whether each coefficient is individually different from zero. For example, a researcher may want to test whether two slopes differ, or whether a specified combination of slopes is zero. These are questions about linear contrasts.

With heteroskedasticity-robust inference, the standard error for such a combination must use the full robust covariance matrix. The diagonal entries give the robust variances of individual coefficients, while the off-diagonal entries describe how their estimates vary together. Leaving out those covariances can change the standard error—and therefore the test conclusion.

The calculations below use an estimated robust covariance matrix, such as an HC0, HC1, HC2, or HC3 estimate. The choice of estimator should be reported. The focus here is how to use the resulting matrix for a contrast, rather than how to construct it.

Defining a Linear Contrast

Write the regression coefficient vector as \(\boldsymbol{\beta}=(\beta_1,\ldots,\beta_k)^\mathsf{T}\), and its least-squares estimate as \(\hat{\boldsymbol{\beta}}\). A linear contrast is a specified weighted sum of coefficients, \(L=\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}\), where \(\boldsymbol{c}\) is a fixed vector of weights. The estimated contrast is \(\hat{L}=\boldsymbol{c}^\mathsf{T}\hat{\boldsymbol{\beta}}\). For instance, the difference \(\beta_1-\beta_2\) uses weights \(1\) and \(-1\).

Definition: Let \(\widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{\boldsymbol{\beta}})=\widehat{\boldsymbol{V}}_{\mathrm{rob}}\) be the estimated robust covariance matrix of the coefficient estimates. For a contrast \(\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}\), its estimated robust variance and robust standard error are \(\boldsymbol{c}^\mathsf{T}\widehat{\boldsymbol{V}}_{\mathrm{rob}}\boldsymbol{c}\) and \(\sqrt{\boldsymbol{c}^\mathsf{T}\widehat{\boldsymbol{V}}_{\mathrm{rob}}\boldsymbol{c}}\), respectively.

The covariance matrix is symmetric. Its diagonal entry in position \(j\) is the estimated robust variance of \(\hat{\beta}_j\); its entry in positions \(j,\ell\) is the estimated robust covariance of \(\hat{\beta}_j\) and \(\hat{\beta}_\ell\). For a contrast involving two coefficients, the calculation expands to

$$ \widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{L}) =c_1^2\widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{\beta}_1) +c_2^2\widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{\beta}_2) +2c_1c_2\widehat{\mathrm{Cov}}_{\mathrm{rob}}(\hat{\beta}_1,\hat{\beta}_2). $$

The covariance term can increase or decrease the variance, depending on its sign and the contrast weights. For a difference, the weights have opposite signs, so a positive covariance reduces the variance of that difference.

Testing a Hypothesis About a Contrast

A one-contrast test specifies a null value \(q\), usually zero, and tests \(H_0:\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}=q\) against an alternative. For a two-sided alternative, the hypotheses are \(H_0:\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}=q\) and \(H_a:\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}\ne q\). If the conditions for robust large-sample inference are reasonable, the standardized contrast is approximately standard normal under \(H_0\).

$$ Z=\frac{\boldsymbol{c}^\mathsf{T}\hat{\boldsymbol{\beta}}-q} {\sqrt{\boldsymbol{c}^\mathsf{T}\widehat{\boldsymbol{V}}_{\mathrm{rob}}\boldsymbol{c}}} \ \approx\ N(0,1)\quad\text{under }H_0. $$

The two-sided p-value is \(2P(Z_{\mathrm{std}}\ge |z_{\mathrm{obs}}|)\), where \(Z_{\mathrm{std}}\sim N(0,1)\). It measures how unusual a test statistic at least as far from zero as the observed one would be if the null hypothesis and the approximation were appropriate. The robust standard error accounts for unequal error variances; it does not make the test an exact small-sample test.

This approximation is used under the usual conditions for robust regression inference: the mean model is correctly specified and linear in its coefficients, observations are independent, the design has full column rank, errors have suitable finite moments, and the sample is sufficiently large for the robust covariance estimate and normal approximation to be useful. Unequal conditional error variances are allowed. Robust standard errors do not, by themselves, repair dependence between observations or an incorrect mean model.

Why the Covariance Formula Works

The variance identity follows from the rule for the variance of a linear combination. If \(\hat{\boldsymbol{\beta}}\) has covariance matrix \(\boldsymbol{V}\), multiplying by the fixed weights \(\boldsymbol{c}\) gives a scalar random quantity \(\boldsymbol{c}^\mathsf{T}\hat{\boldsymbol{\beta}}\). Its variance is \(\boldsymbol{c}^\mathsf{T}\boldsymbol{V}\boldsymbol{c}\). To see the role of every entry, write the contrast as a sum and expand:

$$ \mathrm{Var}\!\left(\sum_{j=1}^{k}c_j\hat{\beta}_j\right) =\sum_{j=1}^{k}\sum_{\ell=1}^{k} c_jc_\ell\mathrm{Cov}(\hat{\beta}_j,\hat{\beta}_\ell). $$

Terms with \(j=\ell\) are the weighted variances. For each pair \(j\ne\ell\), symmetry gives two equal covariance terms, producing the factor of \(2\) in the two-coefficient expansion. Replacing \(\boldsymbol{V}\) by its robust estimate gives the estimated robust variance. The standard error is its nonnegative square root. This is why a contrast’s robust standard error cannot generally be obtained by combining coefficient standard errors alone.

Worked Contrast Tests

Worked Example: Testing a Difference Between Two Slopes

Suppose a hypothetical regression estimates two slopes, \(\beta_1\) and \(\beta_2\), each measured in outcome units per one-unit increase in its predictor. The estimated slopes are \(4.8\) and \(2.3\). Their estimated robust covariance matrix is

$$ \widehat{\boldsymbol{V}}_{\mathrm{rob}} = \begin{pmatrix} 0.49 & 0.12\\ 0.12 & 0.64 \end{pmatrix}. $$

Test at \(\alpha=0.05\) whether the slopes differ. The contrast is \(\beta_1-\beta_2\), so \(\boldsymbol{c}=(1,-1)^\mathsf{T}\) and \(q=0\). Its estimate is

$$ \hat{L}=1(4.8)-1(2.3)=2.50 \quad\text{outcome units per predictor unit}. $$

Use both diagonal variances and the off-diagonal covariance to calculate its variance:

$$ \widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{L}) =(1)^2(0.49)+(-1)^2(0.64)+2(1)(-1)(0.12) =0.49+0.64-0.24=0.89. $$

Thus \(SE_{\mathrm{rob}}(\hat{L})=\sqrt{0.89}=0.9434\) outcome units per predictor unit. The test statistic is

$$ z=\frac{2.50-0}{\sqrt{0.89}}=2.650. $$

The two-sided standard-normal p-value is approximately \(0.008049\). Since \(0.008049<0.05\), reject \(H_0\) at the 5% significance level. These hypothetical results provide evidence that the two slopes differ; the estimated difference is \(2.50\) outcome units per predictor unit. This test does not establish that either predictor causes a change in the outcome.

Worked Example: Testing a Weighted Combination

In a second hypothetical regression, two coefficients describe outcome changes for specified predictor changes. Their estimates are \(\hat{\beta}_1=1.4\) and \(\hat{\beta}_2=0.3\), and their robust covariance matrix is

$$ \widehat{\boldsymbol{V}}_{\mathrm{rob}} = \begin{pmatrix} 0.36 & 0.10\\ 0.10 & 0.25 \end{pmatrix}. $$

Consider the contrast \(2\beta_1+\beta_2\), and test \(H_0:2\beta_1+\beta_2=0\) against a two-sided alternative. The estimated contrast is \(2(1.4)+0.3=3.1\) outcome units. The weights are \(\boldsymbol{c}=(2,1)^\mathsf{T}\), so

$$ \widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{L}) =(2)^2(0.36)+(1)^2(0.25)+2(2)(1)(0.10) =1.44+0.25+0.40=2.09. $$

The robust standard error is \(\sqrt{2.09}=1.446\) outcome units. Therefore,

$$ z=\frac{3.1-0}{\sqrt{2.09}}=2.144. $$

The two-sided standard-normal p-value is approximately \(0.0320\). Because \(0.0320<0.05\), reject the null hypothesis at the 5% level. Under the stated model and large-sample conditions, the data provide evidence that this weighted combination is nonzero. The result concerns the specified combination, not necessarily either coefficient separately.

Worked Example: A Positive Covariance in a Difference

Suppose a third hypothetical analysis estimates two coefficients whose difference is scientifically meaningful. The estimates are \(\hat{\beta}_1=4.2\) and \(\hat{\beta}_2=3.5\), and the robust covariance matrix is

$$ \widehat{\boldsymbol{V}}_{\mathrm{rob}} = \begin{pmatrix} 0.16 & 0.10\\ 0.10 & 0.25 \end{pmatrix}. $$

Test \(H_0:\beta_1-\beta_2=0\). The estimated difference is \(4.2-3.5=0.70\) coefficient units. With weights \((1,-1)^\mathsf{T}\), the robust variance is

$$ \widehat{\mathrm{Var}}_{\mathrm{rob}}(\hat{\beta}_1-\hat{\beta}_2) =0.16+0.25-2(0.10)=0.21. $$

The robust standard error is \(\sqrt{0.21}=0.4583\) coefficient units, and the test statistic is \(z=0.70/\sqrt{0.21}=1.528\). The two-sided p-value is approximately \(0.1267\). At \(\alpha=0.05\), do not reject \(H_0\): the data do not provide sufficient evidence of a difference between these coefficients. This is not proof that the coefficients are equal.

If the covariance were incorrectly omitted, the variance would be \(0.16+0.25=0.41\), giving a standard error of \(\sqrt{0.41}=0.6403\), rather than \(0.4583\). The resulting test statistic and p-value would differ. The covariance belongs in the calculation even when the final conclusion happens to remain the same.

A Reliable Calculation Sequence

Writing the contrast explicitly before calculating helps prevent sign and covariance errors. For a single linear hypothesis, use the following sequence:

1
State the hypothesis in context.
Identify the coefficient combination and its null value \(q\), for example, \(H_0:\beta_1-\beta_2=0\).
2
Write the contrast weights.
Express the combination as \(\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}\), matching each weight to the coefficient in the same position.
3
Calculate the estimate and robust standard error.
Compute \(\boldsymbol{c}^\mathsf{T}\hat{\boldsymbol{\beta}}\) and \(\sqrt{\boldsymbol{c}^\mathsf{T}\widehat{\boldsymbol{V}}_{\mathrm{rob}}\boldsymbol{c}}\), retaining the off-diagonal covariances.
4
Standardize and conclude.
Calculate \(z=(\hat{L}-q)/SE_{\mathrm{rob}}(\hat{L})\), find the appropriate tail probability, and compare the p-value with \(\alpha\). Report the contrast and its units in context.

Common Pitfalls and Why the Test Matters

A common mistake is to test whether \(\beta_1\) and \(\beta_2\) differ by looking at whether their separate tests against zero are significant. Those are different hypotheses: separate tests concern \(\beta_1=0\) and \(\beta_2=0\), whereas a difference test concerns \(\beta_1-\beta_2=0\). One coefficient can be individually significant and the other not, even when the difference between them is not significant. The direct contrast test answers the question asked.

Another frequent error is to square the contrast weights but omit covariance terms, or to use the wrong sign for a covariance term. Always use the matrix expression \(\boldsymbol{c}^\mathsf{T}\widehat{\boldsymbol{V}}_{\mathrm{rob}}\boldsymbol{c}\), or expand it carefully. For a difference, a positive covariance enters with a minus sign; for a sum, it enters with a plus sign.

Key takeaway: A robust test of a linear contrast uses the estimated contrast minus its null value, divided by the square root of the contrast’s variance from the full robust covariance matrix. Interpret the result as evidence about that particular coefficient combination, in its stated units.

Check Your Understanding

Try these questions before reviewing the worked calculations.

  1. For the contrast \(3\beta_1-\beta_2\), what are the contrast weights, and how do you calculate its estimated value?
  2. Why does a positive covariance reduce the variance of a difference \(\hat{\beta}_1-\hat{\beta}_2\)?
  3. A test gives \(z=-2.10\) for a two-sided contrast test. Should the sign or absolute value of \(z\) be used to obtain the p-value?
  4. Why do separate tests of \(\beta_1=0\) and \(\beta_2=0\) not directly test whether \(\beta_1=\beta_2\)?
  5. In the third worked example, what incorrect variance would result from dropping the covariance, and why is that calculation invalid?