Skip to content

Update Chapter 8 numbers to match the loans model output - #561

Open
prawalpokharel wants to merge 2 commits into
OpenIntroStat:mainfrom
prawalpokharel:fix-ch8-model-mlr-numbers
Open

prawalpokharel wants to merge 2 commits into
OpenIntroStat:mainfrom
prawalpokharel:fix-ch8-model-mlr-numbers

Conversation

@prawalpokharel

@prawalpokharel prawalpokharel commented Nov 18, 2026 •

Copy link
Copy Markdown

Several numbers typed into Chapter 8 (model-mlr.qmd) no longer match what the chapter's code produces. This updates them. Only prose and one table caption change, so the code output is the same.

  • The tbl-loans-full caption says the model has 9990 degrees of freedom. It has 9964, because lm() drops 26 loans that are missing debt_to_income or credit_util.
  • The R-squared and adjusted R-squared Guided Practices use variances of 18.53 and 25.01 and n = 10,000 "auctions", which look like they came from the Mario Kart example in Chapter 7. With this model's residuals and the 9,974 loans it uses, the footnotes now give 0.2603 and 0.2597, and 0.2597 matches the adjusted R-squared printed in tbl-loans-full-for-model-selection. The variances have three decimals because two decimals give 0.2599.
  • In forward selection, the values for credit_checks and issue_month were swapped in the first three steps, and credit_checks enters the model before debt_to_income. The last step gave 0.25854 for the model without issue_month, while backward elimination and the table give 0.2598 for the same model. It now says 0.25979.
  • The other adjusted R-squared values in both stepwise examples were off in the third or fourth decimal place. Values for models that include neither debt_to_income nor credit_util were already right apart from the swap, so those are unchanged.

Apart from that order, each step picks the same variable as before, and both methods still end with the model without issue_month.

Each value comes from lm() on loans as prepared in the chapter, so models that leave out debt_to_income or credit_util are fit to a few more rows than the full model. For example, the first backward elimination step is

preds <- setdiff(names(loans), "interest_rate")
adj_r2 <- function(vars) summary(lm(reformulate(vars, "interest_rate"), data = loans))$adj.r.squared
sapply(preds, function(p) adj_r2(setdiff(preds, p)))

I rendered the chapter with Quarto 1.4.553 under R 4.5.2 and R 4.6.2. The code output matched the committed _freeze, so I didn't include a _freeze update. I also fixed a stray comma at the end of one of the edited lines.

A second commit fixes two things I had first left alone. The SSE formula and the sentence after it now count 9,974 residuals, which is the model's 9,964 residual degrees of freedom plus its 10 coefficients. The equation for the model without issue_month now labels the level Source Verified, as the data and the full-model equation do. No code chunks change.

Several numbers typed into model-mlr.qmd no longer matched what the
chapter's code produces:

- tbl-loans-full caption: 9964 residual degrees of freedom, was 9990
- R-squared and adjusted R-squared Guided Practices: use the variances
  and n (9,974 loans) of the fitted model, replacing values and
  "auctions" wording left over from the Mario Kart example
- forward selection: swap back the credit_checks and issue_month
  values, and add credit_checks before debt_to_income
- backward elimination and forward selection: update the remaining
  adjusted R-squared values

Apart from that order, each step picks the same variable as before and
both methods end with the same model.
@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

👷 Deploy request for openintro-ims1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 21fba27

@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

👷 Deploy request for openintro-ims pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 21fba27

The model is fit to 9,974 loans (9,964 residual degrees of freedom plus 10
coefficients), and the factor level is named Source Verified.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant