liveBook · Manning

Linear regression

As explained in Statistics Slam Dunk

A multiple linear regression model represents a target variable as a function of two or more predictor variables, typically using a linear form.

Multiple linear regression estimates how a continuous target changes with two or more predictors. It produces a straight-line equation through the data, helping quantify the predictors’ collective relationship with variation in the target. A simple linear regression uses only one predictor; predictors are usually continuous but may be categorical. section 5.0 section 5.7

Use it for questions such as: which NBA hustle statistics are associated with regular-season wins, and by how much? Here, wins are modeled from measures including screen-assist points, deflections, and loose balls recovered. The aim is not merely prediction; it can also be isolating predictors with statistically significant relationships to an outcome. section 5.0 section 20.4

A practical linear-regression workflow is:

  • Explore and wrangle the data first; identify and treat outliers, assess distributions, and examine correlations to find promising predictors. section 5.9 section 20.4
  • Split observations into mutually exclusive training and prediction subsets to reduce overfitting. section 5.7 section 5.9
  • Fit the model, inspect returned estimates and diagnostics, and check predictors for multicollinearity. section 5.7
  • Compare competing predictor sets using adjusted R², AIC, significance, and diagnostic results rather than trusting one fit automatically. section 5.7.6

Reducing a wins model

A reduced R model fits wins from screen-assist points, deflections, and loose balls. Each displayed predictor has a p-value below 0.05. Compared with the larger model, it has adjusted R² of 0.16 rather than 0.14 and AIC of 514 rather than 518—an improvement, though it still explains limited variation in wins. section 5.7.6 section 5.9

fit2 <- lm(wins ~ screen_assists_pts + deflections + loose_balls, 
          data = train)

tidy(fit2)
## # A tibble: 4 × 5
##   term               estimate std.error statistic p.value
##   <chr>                 <dbl>     <dbl>     <dbl>   <dbl>
## 1 (Intercept)          -56.1     25.5       -2.20 0.0317 
## 2 screen_assists_pts     1.12     0.422      2.65 0.0101 
## 3 deflections            2.35     0.859      2.74 0.00805
## 4 loose_balls            4.81     1.98       2.42 0.0182
augment(fit2) -> fit_tbl2
print(fit_tbl2)
# A tibble: 67 × 10
##    wins screen_assists_pts deflections loose_balls .fitted  .resid   
##   <int>              <dbl>       <dbl>       <dbl>   <dbl>   <dbl>  
## 1    49               20          14.1         8.3    39.3   9.66  
## 2    42               26.2        12.1         8      40.1   1.85  
## 3    39               25.7        12.6         8.1    41.2  -2.24  
## 4    19               22.4        11.8         7.6    33.3 -14.3   
## 5    33               20.1        11.5         8.4    33.8  -0.825 
## 6    54               19.9        13.9         8.6    40.2  13.8   
## 7    57               26.3        14.2         8.7    48.6   8.44  
## 8    53               16.6        14.9         8.4    37.9  15.1   
## 9    48               20.2        14.2         8.6    41.2   6.76  
##10    37               20.1        11.9         8.5    35.2   1.75  
##         hat .sigma  .cooksd .std.resid
##       <dbl>  <dbl>    <dbl>      <dbl>
## 1    0.0224   10.8 0.00472      0.907 
## 2    0.0726   10.8 0.000626     0.179 
## 3    0.0568   10.8 0.000691    -0.214 
## 4    0.0647   10.7 0.0324      -1.37  
## 5    0.0749   10.9 0.000128    -0.0797
## 6    0.0316   10.7 0.0138       1.30  
## 7    0.0792   10.8 0.0144       0.817 
## 8    0.0550   10.7 0.0303       1.44  
## 9    0.0298   10.8 0.00312      0.637 
##10    0.0632   10.9 0.000478     0.168 
## # ... with 57 more rows

fit_tbl2 %>%
 mutate(wins_dif = abs(wins - .fitted)) -> fit_tbl2
mean(fit_tbl2$wins_dif)
## [1] 8.427093
glance(fit2)
## # A tibble: 1 × 12
##   r.squared adj.r.squared sigma statistic p.value    df logLik   
##       <dbl>         <dbl> <dbl>     <dbl>   <dbl> <dbl>  <dbl> 
## 1     0.194         0.156  10.8      5.06 0.00334     3  -252.  
##        AIC   BIC deviance df.residual  nobs
##       dbl> <dbl>    <dbl>       <int> <int>
## 1     514.  525.    7302.          63    67

vif(fit2)
## screen_assists_pts        deflections        loose_balls 
##           1.085184           1.031128           1.098619
par(mfrow = c(2,2))
plot(fit2)

Inspect an executable lm() fit, coefficient table, fitted values, and residuals for the reduced wins model. section 5.7.6

A regression line minimizes differences between the line and observed data. For a quick visual view of a two-variable relationship, R can add an lm trend line to a scatterplot; this shows direction and pattern but does not replace the full multiple-regression workflow. section 4.5.3 section 5.7

Choose linear regression when the target is continuous. For a binary target, such as whether a team finishes with a winning record, use logistic regression instead. Also remember that real data may not be linear, so modest fit can still support a narrower finding about which predictors matter. section 5.7 section 5.9

How Statistics Slam Dunk covers it

How deep it goes
Walks through preparation, splitting, fitting, diagnostics, multicollinearity, prediction, and competing-model comparison without formal derivations.
Examples
Uses NBA regular-season wins, screen-assist points, deflections, and loose balls in full and reduced R models.
What it assumes
Introduces regression variables in plain terms while requiring prepared data suitable for outlier, distribution, and correlation checks.
What you can do after
Apply it via R to fit, diagnose, compare, and interpret multiple linear models for continuous targets.
How it connects
Connects linear regression with correlation, outliers, normality, multicollinearity, regression trees, logistic regression, and AIC.

Also explained in

Compare how 22 books explain linear regression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.