# A tibble: 1 × 1
adj.r.squared
<dbl>
1 0.678
Lecture 18
Duke University
STA 199 - Fall 2026
November 2, 2026
At the end of last class, I asked you to write a description for what this code from AE 10 does. Copy and paste your response here.

Go to wooclap.com and use the code SLCBQZT.
Fit two (or more) models to the same data set with different sets of predictors, selected based on subject-matter knowledge and/or exploratory data analysis results, compared their adjusted \(R^2\) values, and selected the model with the highest adjusted \(R^2\) value.
Perform stepwise selection (forward or backward) to select a model that maximizes adjusted \(R^2\):
Goal: Predict mental_distress. Candidate variables: development_tier, loneliness, and short_sleep. Method for model selection: Backward elimination using adjusted \(R^2\) as decision criterion.
Start with all three predictors; use the same 100 counties for every model since there are no missing values in these four variables.
At each step, try removing each remaining predictor and keep the removal only if it increases adjusted \(R^2\) the most.
Treat development tier as one predictor even though when fitting the model it is represented by two dummy variables.
Fit each model obtained by removing one predictor from the full model.
Which variable should we drop in Step 1 of backward elimination using adjusted \(R^2\)?
| Predictor removed | Adjusted R² |
|---|---|
| None (full model) | 0.6780 |
| Development tier | 0.5868 |
| Loneliness | 0.6121 |
| Short sleep | 0.6810 |

Go to wooclap.com and use the code SLCBQZT.
Start from mental_distress ~ development_tier + loneliness (i.e., md_tier_sleep_fit) and try removing each remaining predictor.
Which variable should we drop in Step 2 of backward elimination using adjusted \(R^2\)?
| Predictor removed | Adjusted R² |
|---|---|
| None (current model) | 0.6810 |
| Development tier | 0.5881 |
| Loneliness | 0.5452 |

Go to wooclap.com and use the code SLCBQZT.
Same model selection approaches (subject-matter knowledge, stepwise selection) can be used with various model comparison criteria, such as:
Note
Only mentioning criteria other than adjusted \(R^2\) here to build awareness that other criteria exist. We will not cover all of them in detail in this course (and this is not even a complete list), but you will encounter them in higher-level modeling courses and in practice.
More complex models (i.e., models with more predictors) tend to fit the data at hand better, but may not generalize well to new data.
Model selection criteria, like adjusted \(R^2\), help balance model fit and complexity to avoid overfitting by penalizing models with more predictors.
Overfitting occurs when a model captures not only the underlying relationship between predictors and outcome but also the random noise in the data.
Overfitted models that perform well on the observed data can perform poorly on new, unseen data.
What are some features of datasets (that we have discussed so far) that could lead to overfitting?
Start with your goal / high-level question
Don’t chronicle your steps, but instead tell us a compelling story of what you set out to find and what you found
“No significant results” or “no concrete relationships” are still results – what did you learn? how deep did you dig and with what tools and techniques?
Advice from those much more successful than me at telling stories:
The docs folder.
Making sure your website reflects your latest changes.
Customizing the look of your website.
_brand.yml, learn more at https://quarto.org/docs/authoring/brand.html.Important
Make sure the presentation is called presentation.pdf.
One way to look at smells is with respect to principles and quality: “Smells are certain structures in the code that indicate violation of fundamental design principles and negatively impact design quality”. Code smells are usually not bugs; they are not technically incorrect and do not prevent the program from functioning. Instead, they indicate weaknesses in design that may slow down development or increase the risk of bugs or failures in the future.
Follow the Tidyverse style guide:
Spaces before and line breaks after each + when building a ggplot
Spaces before and line breaks after each |> in a data transformation pipeline,
Proper indentation
Spaces around = signs and spaces after commas
Lines should not span more than 80 characters, long lines should be broken up with each argument on its own line