How to use this sheet

Full worked answers are in the solutions sheet.

Three exercises on Lectures 11 and 12. They illustrate the material from the lectures, and at times go a little beyond it. Exercises 1 and 3 are pen-and-paper: work them out with a calculator and the statistical tables first, as you would at the midterm, and only then check your numbers in R. Exercise 2 is done in R.


Exercise 1. Reading a regression output

The dataset stackloss, which ships with R, records 21 days of operation of a chemical plant. The response, stack.loss, measures how much raw material the plant lost that day: the larger it is, the less efficient the plant. The three predictors are settings of the plant:

  • Air.Flow: how fast the plant was running (larger means faster);
  • Water.Temp: the temperature of the water used to cool it (°C);
  • Acid.Conc.: the concentration of a liquid used in the process.

No knowledge of chemistry is needed: think of them as three settings that may affect the loss.

A regression of stack.loss on the three predictors gives the following output, with some values removed.

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -39.9197    11.8960  -3.356  0.00375 **
Air.Flow      0.7156        (a)   5.307  5.8e-05 ***
Water.Temp    1.2953     0.3680   3.520  0.00263 **
Acid.Conc.   -0.1521     0.1563     (b)  0.34405
---
Residual standard error: 3.243 on (c) degrees of freedom
Multiple R-squared:  0.9136,    Adjusted R-squared:  (e)
F-statistic:  (d) on 3 and (c) DF,  p-value: 3.016e-09

Questions.

  1. How many parameters does the model have? Fill in (a) to (e).
  2. Give a 95% confidence interval for the coefficient of Water.Temp, and interpret it in context.
  3. Test whether Acid.Conc. is related to stack loss, at the 5% level. Does your conclusion mean that acid concentration has nothing to do with the efficiency of the plant?
  4. Test, at the 5% level, whether the three predictors taken together are related to stack loss (the overall \(F\) test). State the null and alternative hypotheses, give the critical value from the \(F\) table, and state your conclusion in the context of the plant.

Exercise 2. Two days of operation, and one of them is unusual

Use the same data and the same model as in Exercise 1.

fit <- lm(stack.loss ~ Air.Flow + Water.Temp + Acid.Conc., data = stackloss)

Questions.

  1. Consider a day with Air.Flow = 60, Water.Temp = 20 and Acid.Conc. = 87. Using predict, give a 95% confidence interval for the mean stack loss of all days with these settings, and a 95% prediction interval for the stack loss of one such day.

    With new <- data.frame(Air.Flow = 60, Water.Temp = 20, Acid.Conc. = 87), predict(fit, new, se.fit = TRUE)$se.fit returns the standard error \(s\{\hat Y_h\}\) that the confidence interval uses. Check that you obtain the same value by computing it yourself: \(s^2\{\hat Y_h\} = \boldsymbol{X}_h'\,\boldsymbol{s^2}\{\hat{\boldsymbol{\beta}}\}\,\boldsymbol{X}_h\), with \(\boldsymbol{X}_h = (1, 60, 20, 87)'\), where vcov(fit) gives \(\boldsymbol{s^2}\{\hat{\boldsymbol{\beta}}\} = MSE\,(\boldsymbol{X}'\boldsymbol{X})^{-1}\).

  2. Do the same at Air.Flow = 75, Water.Temp = 18, Acid.Conc. = 87. Is each of these values within the range of the data? Compare the widths of the intervals with those of (a).

  3. Plot Water.Temp against Air.Flow for the 21 days, and add the two points of (a) and (b). Compute \(\boldsymbol{X}_h'(\boldsymbol{X}'\boldsymbol{X})^{-1}\boldsymbol{X}_h\) at both points, and compare these two numbers with the values of \(\boldsymbol{X}_i'(\boldsymbol{X}'\boldsymbol{X})^{-1}\boldsymbol{X}_i\) for the 21 observed days (hatvalues(fit) gives them). What do you conclude about the intervals of (b)? You can use the function lev below, which returns \(\boldsymbol{X}_h'(\boldsymbol{X}'\boldsymbol{X})^{-1}\boldsymbol{X}_h\) for a vector \(\boldsymbol{X}_h\), for example lev(c(1, 60, 20, 87)).

X <- model.matrix(fit)                      # the design matrix
XtX_inv <- solve(t(X) %*% X)
lev <- function(xh) drop(t(xh) %*% XtX_inv %*% xh)

Exercise 3. Adding predictors

An agronomist records the yield of \(n = 25\) plots of wheat, for which \(SST = 400\). Model A regresses the yield on the rainfall alone, with \(SSE = 160\). Model B adds two soil measurements to the rainfall, with \(SSE = 150\). Both models have an intercept.

Questions.

  1. Compute \(R^2\) and the adjusted \(R^2\) of both models. Which one does each criterion prefer?
  2. Carry out the overall \(F\) test of model B at the 5% level.
  3. Explain, using the geometry of least squares, why \(SSE\) can never increase when predictors are added to a model, whatever the data. What does it imply for \(R^2\)?
  4. Using \(E(MSE) = \sigma^2\) and \(E(MSR) = \sigma^2 + \frac{1}{p - 1}\sum_{i=1}^n (\mu_i - \bar\mu)^2\), where \(\mu_i = E(Y_i)\), explain why large values of \(F^* = MSR/MSE\) are evidence against \(H_0: \beta_1 = \cdots = \beta_{p-1} = 0\).