liveBook · Manning

Glm

As explained in Statistics Slam Dunk

The glm() function is a base R function that fits generalized linear models, including logistic regression models.

glm() is base R’s generalized linear model function. For logistic regression, it models a binary outcome by estimating probabilities between 0 and 1 with maximum likelihood estimation. section 14.6.2

Use glm() for a practical binary-classification workflow:

  • Provide a formula, binary outcome, predictor, family = "binomial", and data frame. section 14.6.2
  • Inspect coefficients, p-values, deviance, AIC, and Fisher scoring iterations with summary(). section 14.6.2
  • Evaluate fit with McFadden’s pseudo-R2, then generate response probabilities with predict(..., type = "response"). section 14.6.2
  • Convert probabilities at a chosen threshold into classes and assess them with a confusion matrix, sensitivity, specificity, accuracy, and an ROC curve. section 14.6.2

Predicting NBA playoff qualification

A model can predict the binary variable playoffs2 from standardized points allowed: fit3 <- glm(playoffs2 ~ z_o_pts, family = "binomial", data = train). The predictor is statistically significant, and the model’s McFadden pseudo-R2 is 0.31. Predictions from test data can be thresholded at 0.50, producing 0.80 sensitivity, 0.63 specificity, 0.7375 accuracy, and an ROC AUC of 0.73. section 14.6.2

fit3 <- glm(playoffs2 ~ z_o_pts, family = "binomial", data = train)
summary(fit3)
## 
## Call:
## glm(formula = playoffs2 ~ z_o_pts, family = "binomial", data = train)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -2.17428  -0.77250  -0.01473   0.76694   2.13669  
## 
## Coefficients:
##             Estimate Std. Error z value         Pr(>|z|)    
## (Intercept)   0.1998     0.1727   1.157            0.247    
## z_o_pts      -1.7210     0.2317  -7.428 0.00000000000011 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 304.98  on 219  degrees of freedom
## Residual deviance: 210.91  on 218  degrees of freedom
## AIC: 214.91
## 
## Number of Fisher Scoring iterations: 5

View the complete fit3 call and summary output, including coefficients, deviance, AIC, and Fisher scoring iterations. section 14.6.2

How Statistics Slam Dunk covers it

How deep it goes
Explains binomial fitting, log odds, model summaries, predictions, and evaluation, while deferring broader generalized linear model details.
Examples
Uses NBA playoff qualification, points allowed, points scored, training and test data, confusion matrices, and ROC curves.
What it assumes
Assumes linear-model-style formula syntax and a prepared binary target while teaching the binomial family requirement.
What you can do after
Build it from scratch, predict binary-outcome probabilities, classify observations, and compare model performance with statistical metrics.
How it connects
Connects generalized linear models with logistic regression, maximum likelihood estimation, model evaluation, and ROC analysis.

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.