2.6 Regression in software
Software 2.6.1 (A two-variable regression). The savings data of Example 1.3.5, with the savings rate regressed on the share of the population under 15:
> fit <- lm(sr ~ pop15, data = LifeCycleSavings) > summary(fit) Call: lm(formula = sr ~ pop15, data = LifeCycleSavings) Residuals: Min 1Q Median 3Q Max -8.637 -2.374 0.349 2.022 11.155 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 17.49660 2.27972 7.675 6.85e-10 *** pop15 -0.22302 0.06291 -3.545 0.000887 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 4.03 on 48 degrees of freedom Multiple R-squared: 0.2075, Adjusted R-squared: 0.191 F-statistic: 12.57 on 1 and 48 DF, p-value: 0.0008866
Reading the output, line by line against the theory of this section.
- Residuals: the five-number summary of the \(e_i\). Their mean is zero by Theorem 2.2.2, so it is not printed; a median near zero and roughly symmetric quartiles are what (A5) would lead one to expect.
- Estimate: \(a = 17.497\) and \(b = -0.223\). A country whose share of under-15s is one percentage point higher saves, on average, \(0.22\) percentage points less of its income.
- Std. Error: \(\operatorname {se}(b) = s/\sqrt {\sum x_i^2}\). Here \(\sum x_i^2 = 4103.95\) and \(s = 4.03\), so \(4.03/64.06 = 0.0629\).
- t value: the estimate divided by its standard error, the statistic for \(H_0\colon \beta = 0\). Pr(>|t|) is its two-sided \(p\)-value from \(t_{48}\). The stars are a convention of R’s, not a substitute for reading the \(p\)-value.
- Residual standard error: \(s = \sqrt {\text {RSS}/(n-2)}\), with \(48 = 50 - 2\) degrees of freedom.
- Multiple R-squared: \(R^2 = 0.2075 = (-0.4555)^2\), the squared correlation of Section 1.5 (Theorem 2.2.4). The adjusted \(R^2\) is explained with the \(k\)-variable model.
- F-statistic: \(12.57 = (-3.545)^2\), with the same \(p\)-value as the \(t\) test, by Theorem 2.4.2.
Stata: regress sr pop15. Stata prints the ANOVA table above the coefficients, with confidence intervals in place of \(p\)-value stars. EViews: ls sr c pop15, where c is EViews’ name for the constant.
Software 2.6.2 (The analysis of variance and confidence intervals). The decomposition of Theorem 2.2.3, and intervals for the coefficients:
> anova(fit) Analysis of Variance Table Response: sr Df Sum Sq Mean Sq F value Pr(>F) pop15 1 204.12 204.12 12.569 0.0008866 *** Residuals 48 779.51 16.24 > confint(fit) 2.5 % 97.5 % (Intercept) 12.9129180 22.08027686 pop15 -0.3494978 -0.09653739
Reading the output. ESS \(= 204.12\) on 1 degree of freedom and RSS \(= 779.51\) on 48. Their sum is TSS \(= 983.63\), and \(R^2 = 204.12/983.63 = 0.2075\). The residual mean square \(16.24 = s^2 = 4.03^2\). The interval for the slope is \(-0.2230 \pm t_{0.025,48}(0.0629)\) with \(t_{0.025,48} = 2.011\). It excludes zero, consistent with the \(t\) test.
Stata: the ANOVA table is printed by regress itself. EViews: the confidence intervals are under View \(\to \) Coefficient Diagnostics \(\to \) Confidence Intervals.
Software 2.6.3 (Predicting the mean and an individual). Predictions at pop15 \(= 25\) and \(45\), near the two ends of the data:
> new <- data.frame(pop15 = c(25, 45)) > predict(fit, new, interval = "confidence") fit lwr upr 1 11.921158 10.206061 13.636255 2 7.460807 5.762507 9.159107 > predict(fit, new, interval = "prediction") fit lwr upr 1 11.921158 3.6390423 20.20327 2 7.460807 -0.8178472 15.73946
Reading the output. The point predictions are the same for both questions; only the intervals differ. The mean savings rate of countries with 25% under 15 is estimated to lie between \(10.2\%\) and \(13.6\%\). A single such country could have a savings rate anywhere from \(3.6\%\) to \(20.2\%\). The prediction interval is about five times as wide, because \(s = 4.03\) is large compared with the precision of the line. Its lower limit at 45% under 15 is negative, an impossible savings rate. That is a reminder that the normal disturbance of (A5) is an approximation, and a poor one near a natural boundary.
Stata: after regress, predict yhat, xb; predict sem, stdp gives the standard error for the mean and predict sef, stdf that for an individual. EViews: Proc \(\to \) Forecast in the equation window, which produces the forecast and its standard error (the individual one).
Questions on this section
Stuck on something here? Ask below and it stays attached to this topic.