- Not a standalone exam question type on its own — it’s the presentation format any of the other problems could be posed in: “here’s
summary(lm())/anova()/ a plot — answer this,” instead of a raw data table.
Concepts
- R never uses different theory from the by-hand work —
summary(lm())just reports the same estimates, standard errors, tests, and sums of squares computed earlier, in a compact printed format.m <- lm(y ~ x, data = dat)fits and gives the fitted line .- The end goal of this whole note is to look at
summary(m)(oranova(),confint(),predict(),hatvalues()…) and translate every printed number back into a mathematical statement about the regression model.
- The coefficient table is the first thing to read, and its four columns answer four different questions about each coefficient.
Estimateis the coefficient itself: in the intercept row, in the predictor row.Std. Erroris that coefficient’s standard error, or — how uncertain the estimate is.t valueis the estimate divided by its standard error — by default this tests or .Pr(>|t|)is the two-sided -value for that same default test.- If the question instead asks about a nonzero null like , the printed
t valueis the wrong number to use — recompute it by hand as .
- The residual standard error line reports the overall scale of a typical miss.
- It reads
Residual standard error: ... on ... degrees of freedom. - The number itself is , where is the number of predictors — simple linear regression is the special case, giving the familiar .
- It’s measured in the same units as the response, and gives a rough sense of how far off a typical prediction is.
- It reads
- Multiple R-squared is the same from the decomposition note, just printed under a different name.
- .
- Read it as ” of the total sample variability in the response is explained by the fitted regression” — not as a percent causal effect.
- R also prints an adjusted , which penalizes for model complexity; in simple linear regression the ordinary is still the one tied directly to the formula.
- The -statistic line reports the overall model test, with the numerator/denominator degrees of freedom and a -value attached.
- Numerator df (the number of predictors) and denominator df ; the test is always the global — see MLR Inference, ANOVA, and Adjusted R-Squared for the full derivation once .
- In simple linear regression , so numerator df is always , denominator df is always , and for the single slope’s two-sided test (shown in the Inference and ANOVA note) — the -test’s -value matches that slope test’s -value exactly.
- With predictors, no longer equals any single coefficient’s — it tests all of them jointly, not one at a time; to test a subset instead of every predictor at once, see Partial F-Tests for Subsets of Predictors.
- A few fast consistency checks can catch a transcription mistake before it costs points on an exam.
- Each predictor’s
t valueshould equalEstimate / Std. Error. - The residual degrees of freedom should equal (with giving SLR’s familiar ).
- In simple linear regression only, the statistic should equal the squared slope -statistic; with predictors, tests all of them jointly and generally won’t match any single .
- A large should correspond to a small relative to .
- Each predictor’s
anova(m)prints the sum-of-squares table directly, instead of the coefficient-focused view fromsummary().- The regression row has , df , , and .
- The residual row has , df , and .
- The total usually isn’t printed directly — reconstruct it as if needed.
confint(m)prints a confidence interval for each coefficient — for the slope, this is just computed for you.predict()can give either of two different intervals, depending on which question is being asked.interval = "confidence"gives a confidence interval for the mean response at a new .interval = "prediction"gives a prediction interval for one new individual observation at that .- Both print
fit,lwr,uprcolumns, but the prediction interval is always the wider one — it adds the new observation’s own random error on top of the uncertainty in the estimated mean line.
- A handful of other functions pull out diagnostic quantities directly, instead of reading them off a plot.
resid(m)gives the raw residuals, andfitted(m)gives the fitted values.hatvalues(m)gives the leverages , andrstandard(m)gives the standardized residuals.cooks.distance(m)gives the Cook’s distances.plot(m)on its own produces four diagnostic panels: residuals vs. fitted, Q-Q, scale-location, and residuals vs. leverage.
- A fixed order of steps for answering any R-output question:
- read the fitted equation off the coefficient estimates
- interpret the slope in context
- read the standard error for whichever coefficient is asked about
- identify the null hypothesis attached to the printed / (default is against )
- compare to and state the conclusion in context
- use and residual standard error to describe fit
- read the overall line and, in SLR, connect it to the slope test
- With more than one predictor, step 2’s interpretation must say “holding the other predictors fixed” or it’s graded as incomplete — see MLR Inference, ANOVA, and Adjusted R-Squared.
Practice Problems
-
Problem 1 — class data (
y ~ x, ).x <- c(-1, 0, 1, 2, 3) y <- c(1, 2, 2, 3, 4) m <- lm(y ~ x) summary(m)Call: lm(formula = y ~ x) Residuals: 1 2 3 4 5 9.714e-17 3.000e-01 -4.000e-01 -1.000e-01 2.000e-01 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.7000 0.1732 9.815 0.00225 ** x 0.7000 0.1000 7.000 0.00599 ** --- Residual standard error: 0.3162 on 3 degrees of freedom Multiple R-squared: 0.9423, Adjusted R-squared: 0.9231 F-statistic: 49 on 1 and 3 DF, p-value: 0.005986- Solution.
x Estimate 0.7000isx Std. Error 0.1000isx t value 7.000testsResidual standard error 0.3162 on 3 dfisMultiple R-squared 0.9423isF-statistic 49matches
- Solution.
-
Problem 2 — real second dataset (Production data,
RunTime ~ RunSize, ).Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 149.74770 8.32815 17.98 6.00e-13 *** RunSize 0.25924 0.03714 6.98 1.61e-06 *** --- Residual standard error: 16.25 on 18 degrees of freedom Multiple R-squared: 0.7302, Adjusted R-squared: 0.7152 F-statistic: 48.72 on 1 and 18 DF, p-value: 1.615e-06- Solution.
- fitted line
- slope tests and matches
- : RunSize explains about 73% of the variation in RunTime
- residual standard error on df
- Solution.
-
Problem 3 — real third dataset (airfares,
Fare ~ Distance, ).Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 48.971770 4.405493 11.12 1.22e-08 *** Distance 0.219687 0.004421 49.69 < 2e-16 *** --- Residual standard error: 10.41 on 15 degrees of freedom Multiple R-squared: 0.994, Adjusted R-squared: 0.9936 F-statistic: 2469 on 1 and 15 DF, p-value: < 2.2e-16- Solution.
- fitted line
- (very large, matches the near-perfect )
- , confirming
- residual df for
- Solution.
-
Problem 4 — real fourth dataset, multiple predictors (
mtcars,mpg ~ disp + hp + drat + wt, ).Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 29.148738 6.293588 4.631 8.2e-05 *** disp 0.003815 0.010805 0.353 0.72675 hp -0.034784 0.011597 -2.999 0.00576 ** drat 1.768049 1.319779 1.340 0.19153 wt -3.479668 1.078371 -3.227 0.00327 ** --- Residual standard error: 2.602 on 27 degrees of freedom Multiple R-squared: 0.8376, Adjusted R-squared: 0.8136 F-statistic: 34.82 on 4 and 27 DF, p-value: 2.704e-10- Solution.
- fitted model
hpandwtare individually significant given the other three predictors are in the model;dispanddratare not- residual df , matching predictors
- global on df tests jointly — not the same test as any individual coefficient’s
- does not equal any single here (e.g.
wt’s ) — the SLR-only shortcut from Problems 1-3 above doesn’t carry over once - and adjusted are noticeably different, since predictors already cost more against than SLR’s single predictor would
- Solution.