Full worked answers are in the solutions sheet.
Five exercises on Lectures 4 to 7. 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.
The dataset faithful, which ships with R, records 272
eruptions of the Old Faithful geyser in Yellowstone: the
duration of each eruption, in minutes, and the
waiting time until the next eruption, also in minutes.
Durations range from 1.6 to 5.1 minutes. We regress waiting time on
duration. Two numbers in the output have been replaced by
xxxx.
Call:
lm(formula = waiting ~ eruptions, data = faithful)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 33.4744 1.1549 28.98 <2e-16 ***
eruptions 10.7296 0.3148 xxxx <2e-16 ***
Residual standard error: 5.914 on 270 degrees of freedom
Multiple R-squared: 0.8115, Adjusted R-squared: 0.8108
F-statistic: xxxx on 1 and 270 DF, p-value: < 2.2e-16
You may use \(t(0.975;\,270) = 1.969\) and \(t(0.995;\,270) = 2.594\).
Questions.
eruptions, and the missing \(F\) statistic.var(faithful$eruptions).To see the full output once you are done:
summary(lm(waiting ~ eruptions, data = faithful))
A campus coffee shop records, over 20 days in May and June, the day’s maximum temperature \(x\) (in °C) and the number of iced drinks sold \(Y\). The temperatures range from 12.0 to 28.4 °C. Assume the simple linear regression model with normal errors.
| \(n\) | \(\sum x_i\) | \(\sum Y_i\) | \(S_{xx}\) | \(S_{YY}\) | \(S_{xY}\) |
|---|---|---|---|---|---|
| 20 | 384.3 | 2726 | 538.5 | 50082.2 | 4769.9 |
You may use \(t(0.975;\,18) = 2.101\).
Questions.
The dataset trees records the girth (in
inches) and the volume (in cubic feet) of black cherry
trees. A regression of volume on girth gives an estimated slope of \(\hat\beta_1 = 5.066\) and the following
ANOVA table, with some entries missing.
| Source | Df | Sum of squares | Mean square | \(F\) |
|---|---|---|---|---|
| Regression | ? | 7581.8 | ? | ? |
| Error | 29 | ? | ? | |
| Total | ? | 8106.1 |
You may use \(F(0.99;\,1,\,29) = 7.60\).
Questions.
To check:
fit <- lm(Volume ~ Girth, data = trees)
anova(fit)
summary(fit)
Consider the simple linear regression model under the Gauss-Markov conditions, with residuals \(e_i = Y_i - \hat Y_i\).
Questions.
The code below simulates 2000 datasets from a known model with \(\beta_1 = 0.5\), fits a regression to each, and records how often the 95% confidence interval for \(\beta_1\) contains the true value. The design, the \(x\) values, stays fixed. Run it yourself: the answers depend on it.
set.seed(67)
n <- 20
x <- runif(n, 1, 10) # the same x values in every dataset
beta0 <- 2; beta1 <- 0.5
covers <- function(make_errors, copies = 1, reps = 2000) {
mean(replicate(reps, {
y <- beta0 + beta1 * x + make_errors(x)
xx <- rep(x, copies); yy <- rep(y, copies) # copies > 1: the same units measured again
ci <- confint(lm(yy ~ xx), "xx", level = 0.95)
ci[1] <= beta1 && beta1 <= ci[2]
}))
}
normal <- function(x) rnorm(length(x), 0, 1) # the model is true
funnel <- function(x) rnorm(length(x), 0, 0.25 * x) # the spread grows with x
skewed <- function(x) rexp(length(x), 1) - 1 # mean 0, sd 1, but skewed
covers(normal)
Questions.
covers(normal). What exactly
is this number an estimate of, and why is it not exactly 0.95?covers(normal, copies = 3): each of the 20 units is
now measured three times, as in the xkcd cartoon of Lecture 5. What
happens to the coverage? Which assumption fails? Try
copies = 10.covers(funnel). What happens, and which assumption
fails?covers(skewed). What happens, and which assumption
fails? Comparing (b), (c) and (d), which assumption does the confidence
interval for \(\beta_1\) depend on
most, and which one least?