Ch 25: Diagnostics, Step by Step

Chapter 25 — Diagnostic Plots and Influential Cases · on your own, one class or two · 20 points

Fitting a regression takes one line of R. Checking whether you can trust it is the real work, and that is what Chapter 25 is about. This chapter is not taught in class. You work through it here, one section at a time. At each step you:

  1. Read one section of Chapter 25 (the link opens it in a new tab; keep it open).
  2. Answer one question from the book, in your own words.
  3. Run a new dataset in R that shows the problem that section describes, and say what you see.

Every step uses the same three lines to draw the four diagnostic plots. Only the model name changes.

One page, one answer document, one PDF. Work alone or with one partner. You may submit one answer document with both names on it, or one each. Your answers save in this browser as you type, so you can stop anywhere and pick up later on the same computer. Switching computers? Click Download my answers at the bottom of the answer document before you leave, then Load my answers on the other computer. Submit one PDF when you finish Step 6.
Before you start: Step 6 uses library(car), the same package as Chapter 24. If R says there is no package called 'car', run install.packages("car") once, then try again.
A note on AI tools: You may use AI assistants to help debug your R code. You may not use AI to answer the book questions, to read the plots for you, or to write your interpretations. If you use AI for any part of this activity, note where in the AI Use Log at the end of the answer document.

Step 0: What “good” looks like (not scored, ~5 min)

Read: the opening of Chapter 25, down to the start of “1. Residuals vs. Fitted.”

Start a new script for today. First, the phone data from Chapter 24, a model with no problems. Run this and look at the four plots:

exam_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch24_study_phone.csv") model0 <- lm(exam ~ phone_hours + study_hours, data = exam_data) par(mfrow = c(2, 2)) plot(model0) par(mfrow = c(1, 1))
Record in your answer document (Step 0): Do any of the four plots show a curve, a funnel, or one point far from all the others?
Check yourself

No. The points scatter with no clear shape, the Q-Q points sit close to the diagonal, and no point sits far from the rest in the bottom-right plot. The red lines wander a little, which is normal with only 45 students. This is what “good” looks like. Keep the picture in mind: each step below breaks it in one way.

Step 1: A curve (2 points)

Read: 1. Residuals vs. Fitted.

B1 (1 pt): The chapter says this plot checks two things. Name them, and the shape that signals a problem with each.

Full credit: an answer from the chapter for each part, in your own words.

The caffeine data. Sixty people report how much caffeine they had in the last hour (mg), then take a concentration test. Does more caffeine go with a higher score?

(The data are simulated for this class.)

caffeine_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch25_caffeine.csv") model1 <- lm(score ~ caffeine_mg, data = caffeine_data) summary(model1) par(mfrow = c(2, 2)) plot(model1) par(mfrow = c(1, 1))

The chapter's fix for a curve is a polynomial term: add the predictor squared. One change to the model line:

model1b <- lm(score ~ caffeine_mg + I(caffeine_mg^2), data = caffeine_data) summary(model1b)
R1 (1 pt):
  1. Describe the shape in the Residuals vs. Fitted plot for model1, and name the problem it signals.
  2. Copy R² from model1 and from model1b. What does the jump tell you about caffeine and the score?

Full credit: (a) the shape and the problem; (b) both R² values and what they say.

Step 2: A bowed Q-Q plot (2 points)

Read: 2. Normal Q-Q plot, and the red Common Misconception box near the end of Cook's distance.

B2 (1 pt): What does a bowed curve in the Q-Q plot signal? And according to the Common Misconception box, why can a significant Shapiro-Wilk test be a minor concern in a large sample?

Full credit: an answer from the chapter for each part, in your own words.

The reaction-time data. Three hundred people report how many hours they slept last night, then press a key as fast as they can when a light flashes (reaction time, in milliseconds). Do people who slept more react faster?

(The data are simulated for this class.)

rt_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch25_reaction.csv") model2 <- lm(rt_ms ~ sleep_hours, data = rt_data) par(mfrow = c(2, 2)) plot(model2) par(mfrow = c(1, 1)) shapiro.test(residuals(model2))
R2 (1 pt):
  1. Describe the Q-Q plot: which end of the points leaves the line, and in which direction? Copy the Shapiro-Wilk W and p.
  2. Find “Non-normal residuals” in the chapter's table What to do when assumptions are violated. With 300 people, what does it say to do, and why?

Full credit: (a) the end and direction, plus W and p; (b) what the table says to do at this sample size, and why.

Step 3: A funnel (2 points)

Read: 3. Scale-Location.

B3 (1 pt): What pattern in the Scale-Location plot signals heteroscedasticity? Which other plot checks the same thing, and what shape does the problem make there?

Full credit: an answer from the chapter for each part, in your own words.

The texting data. Eighty people report how many close friends they have and how many texts they send on a typical day. How many more texts go with each extra close friend?

(The data are simulated for this class.)

text_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch25_texts.csv") model3 <- lm(texts_per_day ~ close_friends, data = text_data) par(mfrow = c(2, 2)) plot(model3) par(mfrow = c(1, 1))

One fix the chapter lists is to transform Y with a log. One change to the model line, then plot again:

model3b <- lm(log(texts_per_day) ~ close_friends, data = text_data) par(mfrow = c(2, 2)) plot(model3b) par(mfrow = c(1, 1))
R3 (1 pt):
  1. For model3, describe the Residuals vs. Fitted plot and the Scale-Location plot. Name the problem.
  2. For model3b, describe the same two plots. Did the log fix the problem?

Full credit: (a) both plots and the problem; (b) both plots again, and whether the fix worked.

Step 4: One person pulling the line (2 points)

Read: 4. Residuals vs. Leverage and Cook's distance (up to the Common Misconception box).

B4 (1 pt): How is high leverage different from a large residual, and what makes a point influential? Give the chapter's two Cook's distance cutoffs.

Full credit: an answer from the chapter for each part, in your own words.

The exercise data. Forty people report how many minutes they exercise in a typical week and rate their mood. Do people who exercise more report a better mood?

(The data are simulated for this class.)

exercise_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch25_exercise.csv") model4 <- lm(mood ~ exercise_min, data = exercise_data) par(mfrow = c(2, 2)) plot(model4) par(mfrow = c(1, 1)) cooks_d <- cooks.distance(model4) which(cooks_d > 4 / length(cooks_d)) cooks_d[c(7, 23)] exercise_data[c(7, 23), ]

which() prints each flagged row twice: once as a name, once as a number. The next two lines show those people's Cook's distances and their data.

R4 (1 pt):
  1. Which people are over the 4/n cutoff? Copy each one's Cook's distance.
  2. Compare each to both of the chapter's cutoffs. Which one is clearly influential, and what about their data makes them unusual?

Full credit: (a) the people and their Cook's distances; (b) each one compared to both cutoffs, and what is unusual about the influential one.

Step 5: What to do about it (3 points)

Read: What to do about an influential observation.

B5 (1 pt): What should you do first with an influential point? What does the chapter say to do if it's a data error, and if it's real but extreme? What is the worst response, and why?

Full credit: an answer from the chapter for each part, in your own words.

Case A: a real person

The researcher checked person 23 in the exercise data. The entry is correct: this person was training for a marathon. The chapter's option for a real case is to run the analysis with and without it. Without person 23 is exercise_data[-23, ] (the minus sign drops row 23):

summary(model4) model4b <- lm(mood ~ exercise_min, data = exercise_data[-23, ]) summary(model4b)
R5a (1 pt): Copy the exercise slope and its p with person 23 and without. Does the conclusion change? Following the chapter, what would you report?

Full credit: both slopes with their p-values, whether the conclusion changes, and what to report.

Case B: a typo

The sleep-and-quiz data. Fifty students report how many hours they slept the night before a quiz, and their quiz score (out of 10). Did students who slept more score higher?

(The data are simulated for this class.)

sleep_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch25_sleep_typo.csv") model5 <- lm(quiz ~ sleep_hours, data = sleep_data) summary(model5) cooks_d <- cooks.distance(model5) which(cooks_d > 1) cooks_d[17] sleep_data[17, ]

Look at student 17's sleep hours. The researcher pulled student 17's paper survey: it says 7.0. Correct the entry, then fit the model again:

sleep_data$sleep_hours[17] <- 7 model5b <- lm(quiz ~ sleep_hours, data = sleep_data) summary(model5b)
R5b (1 pt):
  1. What was wrong with student 17's row, and what was their Cook's distance?
  2. Copy the sleep slope and its p before and after the correction. What changed?

Full credit: (a) the problem and the Cook's distance; (b) both slopes with their p-values, and what changed.

Step 6: The whole check, and the write-up (9 points)

Read: A complete diagnostics workflow and Reporting on diagnostics.

The well-being data. A researcher predicts well-being from typical sleep (hours a night) and social time (hours a week) for 120 students. Before anyone reports this model, run the chapter's full check and write it up.

(The data are simulated for this class.)

wb_data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/ch25_wellbeing.csv")
The columns are wellbeing (the outcome), sleep_hours, and social_hours.
S1 (2 pts): Paste your script. Start from the chapter's complete diagnostics workflow and change the data and variable names to fit this problem. Add max(cooks_d) at the end.

Full credit: the chapter's workflow, adapted to this problem, with output that matches your answers below.

S2 (2 pts): For each of the four plots, describe what you see in a phrase and say whether it shows a problem.

Full credit: all four plots, each with a phrase and a problem / no problem call (1 pt for two of them).

S3 (1 pt): Copy the Shapiro-Wilk W and p and the two VIFs. Using the chapter's cutoffs, what does each tell you?

Full credit: W, p, both VIFs, and what each says.

S4 (2 pts):
  1. How many students are over the 4/n cutoff, and what is the largest Cook's distance?
  2. Should the researcher remove those students? Use the chapter's two cutoffs to say why or why not.

Full credit: 1 pt for each part.

S5 (2 pts): Write the diagnostics paragraph for this model, modeled on the chapter's Baby Dataset paragraph in Reporting on diagnostics.

Full credit: names the model and N, and reports every check the chapter's paragraph reports (the plots, Shapiro-Wilk with W and p, the largest Cook's distance), plus the two VIFs.

When you finish Step 6: on your answer document, check that every step is there, then click Print / Save as PDF and submit that one PDF to the Chapter 25 assignment in D2L.