7.7 Testing in software

Software 7.7.1 (A joint \(F\) test by comparing two models). Do the two demographic variables matter for savings? The restricted model omits both:

> fit  <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
> fit0 <- lm(sr ~ dpi + ddpi, data = LifeCycleSavings)
> anova(fit0, fit)
Analysis of Variance Table

Model 1: sr ~ dpi + ddpi
Model 2: sr ~ pop15 + pop75 + dpi + ddpi
  Res.Df    RSS Df Sum of Sq      F   Pr(>F)
1     47 824.72
2     45 650.71  2       174 6.0167 0.004835 **

Reading the output. This is Theorem 7.4.1: \(\text {RSS}_R = 824.72\) on \(47\) degrees of freedom, \(\text {RSS}_U = 650.71\) on \(45\), and \[ F = \frac {(824.72 - 650.71)/2}{650.71/45} = \frac {87.0}{14.46} = 6.017 , \] with \(p = 0.0048\) from \(F_{2,45}\). The demographic variables are jointly highly significant, although pop75 alone was not (\(p = 0.13\) in Software 6.7.1). The two are correlated \(-0.91\), so the data cannot say which age group matters, only that age structure does. Passing a single model to anova(fit0) instead would give sequential sums of squares, a different and order-dependent decomposition.

Stata: after regress sr pop15 pop75 dpi ddpi, test pop15 pop75. EViews: in the equation window, View \(\to \) Coefficient Diagnostics \(\to \) Wald Test, entering c(2)=0, c(3)=0.

Software 7.7.2 (The same test from the Wald formula). Theorem 7.3.1(iii) computed directly from \(b\) and \(s^2(X'X)^{-1}\), which R returns as vcov(fit):

> b <- coef(fit); V <- vcov(fit)
> R <- rbind(c(0, 1, 0, 0, 0), c(0, 0, 1, 0, 0)); r <- c(0, 0)
> d <- R %*% b - r
> F <- drop(t(d) %*% solve(R %*% V %*% t(R)) %*% d) / 2
> c(F = F, p = pf(F, 2, 45, lower.tail = FALSE))
          F           p
6.016652074 0.004834923
> round(V[2:3, 2:3], 5)
        pop15   pop75
pop15 0.02092 0.11996
pop75 0.11996 1.17419

Reading the output. The Wald form agrees exactly with the restricted-versus-unrestricted form, as Theorem 7.4.1 proves it must. Since vcov already includes \(s^2\), the matrix inverted is \(s^2R(X'X)^{-1}R'\) and only the division by \(q = 2\) remains. The covariance of the two estimates, \(0.120\), is large and positive: the correlation of the estimates is \(0.120/\sqrt {0.0209 \times 1.174} = 0.76\), even though the variables themselves are correlated \(-0.91\) (Problem 7.8.5 explains the sign reversal). That correlation is what tilts the ellipse of Figure 9. Any \(R\) and \(r\) can be tested with these lines.

Stata: test accepts any linear restriction, e.g. test pop15 + pop75 = 0. EViews: the Wald test dialog accepts expressions such as c(2)+c(3)=0.

Software 7.7.3 (The overall \(F\) statistic). The test of Theorem 7.4.2 as a comparison with the intercept-only model:

> anova(lm(sr ~ 1, data = LifeCycleSavings), fit)
  Res.Df    RSS Df Sum of Sq      F    Pr(>F)
1     49 983.63
2     45 650.71  4    332.92 5.7557 0.0007904 ***

Reading the output. The restricted RSS is the total sum of squares, \(983.63\), and \(F = (332.92/4)/(650.71/45) = 5.756\), the F-statistic line of Software 6.7.1. In terms of \(R^2\): \((0.3385/4)/(0.6615/45) = 5.756\). (The table header lines printed by R are omitted here.)

Stata and EViews print this statistic in the regression output.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.