\(R^2\) is defined as the proportion of variation in the response variable explained by the model. So, one minus the proportion of variation unexplained:
Question: Given many competing models for the same response, which model is “best”? What does that even mean?
Answer: Assign a “quality score” to each model, and pick the model with the best score:
Model
Score
Verdict
Simple
0.1
❌
Additive
0.5
✅
Interaction
0.48
❌
Variable selection: all of our models were linear, and they differed only by which predictor variables are included. By ranking models by quality score and picking the “best” one, we can determine which predictors are the “most important” to include.
Selection criteria
This is a big area of statistical research. There are loads of “quality scores” you could consider, and they prioritize different things: predictive accuracy, goodness-of-fit, simplicity, fairness, etc.
\(R^2\);
adjusted \(R^2\);
Akaike Information criterion (AIC);
Bayesian information criterion (BIC);
… so many more
We won’t go into detail, but you will if you keep studying statistics.
Because vanilla \(R^2\) blithely rewards the addition of any variable, no matter how meaningless, you shouldn’t use it for model selection. Instead, use adjusted\(R^2\). The formula is in the textbook if you’re dying to know, but here’s the tea:
adjusted \(R^2\) penalizes the inclusion of unnecessary predictors;
It prioritizes a parsimonious model:
a model that fits/predicts well, and…
a model that’s not too complicated (so our pea brains can still understand it);
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
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 tend to perform well on the observed data but poorly on new, unseen data.
Good news: We have techniques to detect and prevent overfitting;
Bad news: We won’t get into those until next week.
Back to variable selection
Given a set of competing models, all trying to predict the same response, we can line ’em up, compute adjusted\(R^2\) for each model, and then pick the model with the highest score.
Easy, right?
Listing out all the possible models
The penguins dataset has \(p=6\) variables apart from body mass: species, island, bill length, bill depth, flipper length, and sex;
How many models is that (ignoring the possibility of interaction, which makes things worse):
1 “empty” model: include no predictors;
6 “simple” models: include only one predictor;
15 two-predictor models;
20 three-predictor models;
15 four-predictor models;
6 five-predictor models;
1 “full” model: include all predictors.
That’s \(2^6=64\) models in total you have to consider. Not the end of the world if you have a computer, but it gets worse…
Combinatorial explosion
If you have \(p\) candidate predictors, then the set of all possible subsets you could include in a model grows very quickly;
In the “big data” era, 100 predictors is amateur hour, so it becomes infeasible to fit every possible model;
It pays to “search” through the space of models in a smarter, less brute-force way.
\(p\)
# of models = \(2^p\)
2
4
5
32
10
1024
20
1048576
30
1073741824
40
\(\approx 1.098\times 10^{12}\)
50
\(\approx 1.13\times 10^{15}\)
100
\(\approx 1.27\times 10^{30}\)
Backward elimination
Start with the full model (the model that includes all potential predictor variables). Variables are eliminated one-at-a-time from the model until we cannot improve the model any further.
Procedure:
Start with a model that has all predictors we consider and compute the adjusted \(R^2\).
Next fit every possible model with 1 fewer predictor.
Compare adjusted \(R^2\)s to select the best model (highest adjusted \(R^2\)) with 1 fewer predictor.
Repeat steps 2 and 3 until adjusted \(R^2\) no longer increases.
Forward stepwise regression is the reverse of the backward elimination technique. Instead, of eliminating variables one-at-a-time, we start from an “empty model” and we add variables one-at-a-time until we cannot find any variables that improve the model any further.
Procedure:
Start with a model that has no predictors.
Next fit every possible model with 1 additional predictor and calculate adjusted \(R^2\) of each model.
Compare adjusted \(R^2\) values to select the best model (highest adjusted \(R^2\)) with 1 additional predictor.
Repeat steps 2 and 3 until adjusted \(R^2\) no longer increases.
A new application
A girl’s best friend
A game
10-carat old mine brilliant-cut diamond
58 facets
Est. at $550K - $1M
5-carat antique cushion-cut diamond
$280,000 price tag
Est. 30-40-carat high color center diamond
1-carat oval side stones
Est. value upwards of $3M
The 4 Cs
When evaluating a diamond, jewelers typically focus on four key characteristics known as the 4 Cs:
Carat — How big is it?
Cut — How much does it sparkle?
Clarity — How flawless is it?
Color — How colorless is it?
The 4 Cs are the primary factors that determine a diamond’s value.
What do these things mean?
What do these things mean?
For example:
We have some data!
diamonds
# A tibble: 5,000 × 7
price carat cut color clarity length_mm width_mm
<dbl> <dbl> <fct> <fct> <fct> <dbl> <dbl>
1 3867 0.9 Ideal I VS 6.13 6.18
2 12048 2.01 Ideal J SI 8.08 8.03
3 878 0.41 Very Good F SI 4.73 4.69
4 4325 0.68 Ideal D VVS 5.66 5.69
5 401 0.3 Ideal E SI 4.33 4.35
6 5504 1.19 Ideal D SI 6.91 6.89
7 1767 0.63 Good H VS 5.47 5.56
8 4704 1.02 Very Good G SI 6.36 6.4
9 1121 0.52 Ideal F SI 5.17 5.2
10 2137 0.7 Very Good H VS 5.58 5.62
# ℹ 4,990 more rows