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\).
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
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\).
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:
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
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
Use both diagonal variances and the off-diagonal covariance to calculate its variance:
Thus \(SE_{\mathrm{rob}}(\hat{L})=\sqrt{0.89}=0.9434\) outcome units per predictor unit. The test statistic is
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
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
The robust standard error is \(\sqrt{2.09}=1.446\) outcome units. Therefore,
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
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
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:
Identify the coefficient combination and its null value \(q\), for example, \(H_0:\beta_1-\beta_2=0\).
Express the combination as \(\boldsymbol{c}^\mathsf{T}\boldsymbol{\beta}\), matching each weight to the coefficient in the same position.
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.
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.
Check Your Understanding
Try these questions before reviewing the worked calculations.
- For the contrast \(3\beta_1-\beta_2\), what are the contrast weights, and how do you calculate its estimated value?
- Why does a positive covariance reduce the variance of a difference \(\hat{\beta}_1-\hat{\beta}_2\)?
- 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?
- Why do separate tests of \(\beta_1=0\) and \(\beta_2=0\) not directly test whether \(\beta_1=\beta_2\)?
- In the third worked example, what incorrect variance would result from dropping the covariance, and why is that calculation invalid?