Full worked answers are in the solutions sheet.
Three exercises on Lectures 7 and 8. They illustrate the material from the lectures on real data, and at times go a little beyond it. For the pen-and-paper ones, work them out with a calculator first, as you would in a quiz or the midterm, and only then check your numbers in R.
Each panel below plots the residuals against the fitted values for a different dataset, of about 60 observations each.
Questions.
The dataset Loblolly, which ships with R, records the
height (in feet) of loblolly pine trees grown from 14
seed sources. Each seed source was measured at the ages
of 3, 5, 10, 15, 20 and 25 years, giving 84 heights in all.
Questions.
Fit the regression of height on age.
Report \(R^2\), and say what it would
usually suggest about the fit.
Plot the residuals against the fitted values. Describe the pattern, and say which assumption it calls into question.
Draw the scatterplot with the least squares line and its 95% confidence band, and add a lowess curve with its own 95% confidence band:
ggplot(Loblolly, aes(age, height)) +
geom_point() +
geom_smooth(method = "lm") +
geom_smooth(method = "loess", colour = "orange", fill = "orange")
The bands are narrow: to see them, zoom in, for example by adding
+ coord_cartesian(xlim = c(2, 11), ylim = c(0, 30)).
Where does the lowess curve leave the band of the line, and in which direction? Does the line stay within the band of the lowess curve? What does that tell you about the straight line?
Explain how \(R^2\) can be about 0.98 when the straight line is the wrong shape. What does \(R^2\) measure, and what does it not measure?
The same 14 seed sources are measured at every age. Which assumption of the model does that put in doubt? Could the plot in (b) reveal it?
The dataset cars, which ships with R, records the
speed (in mph) of 50 cars and the
distance (in feet) each one took to stop. The data were
collected in the 1920s; speeds range from 4 to 25 mph.
Questions.
Fit the regression of dist on speed.
Plot the residuals against the fitted values, and draw a normal Q-Q plot
of the residuals. Describe what you see.
The Shapiro-Wilk test applied to the residuals gives
W = 0.94509, p-value = 0.02152
State the hypotheses and your conclusion at the 5% level. Which feature of your Q-Q plot does this correspond to?
For the Brown-Forsythe test, the data are split at the median speed, 15 mph. Group 1 contains the 23 cars slower than 15 mph and group 2 the 27 others. The absolute deviations \(d_{ij} = |e_{ij} - \tilde e_j|\) of the residuals from their group median have the following means and standard deviations.
| Group | \(n_j\) | \(\bar d_j\) | \(s_j\) |
|---|---|---|---|
| 1 (speed below 15) | 23 | 8.947 | 9.086 |
| 2 (speed 15 or more) | 27 | 13.016 | 11.334 |
Compute the pooled standard deviation \(s\) and the statistic \(t_{BF}\), and test for constant variance at the 5% level, using \(t(0.975;\,48) = 2.011\). Does your conclusion mean that the variance is constant? Compare with your residual plot.
The Box-Cox procedure gives \(\hat\lambda = 0.43\), with a 95% interval
of \((0.23,\ 0.66)\). Which simple
transformation of dist does this suggest? Does it support
leaving dist unchanged? Taking logs?
Fit the regression of sqrt(dist) on
speed, and redo the plots of (a). For this model, the
Shapiro-Wilk test gives \(p = 0.314\)
and the Brown-Forsythe test \(t_{BF} =
0.068\) on 48 degrees of freedom. Has the transformation fixed
the problems you found in (a) to (c)?