liveBook · Manning

Categorical predictor variable

As explained in Statistics Slam Dunk

A categorical predictor variable is an explanatory variable whose values identify membership in discrete groups for comparing an outcome.

A categorical predictor variable assigns each observation to a discrete group so an outcome can be compared across categories. ANOVA uses a categorical predictor with a quantitative target, such as comparing standardized wins across points-scored groups. section 14.5.1

Build a categorical predictor in R by:

  • Using mutate() and case_when() to convert standardized points into ranges labeled A through D. section 14.5.1
  • Using as.factor() so R treats the labels as factor levels rather than numeric values. section 14.5.1
  • Using summary() to check the record count in every category and identify missing assignments. section 14.5.1

NBA points categories

For NBA team data from 2008–17, categorize standardized points allowed as A (< -1), B (-1 to 0), C (0 to 1), or D (> 1). The resulting factor contains 43, 103, 105, and 49 records, respectively, with no missing values. Boxplots then compare each category with standardized regular-season wins. section 14.5.1

nba_stats %>%
 mutate(o_pts_cat = case_when(z_o_pts < -1 ~ "A",
                              z_o_pts >= -1 & z_o_pts < 0 ~ "B",
                              z_o_pts >= 0 & z_o_pts <= 1 ~ "C",
                              z_o_pts > 1 ~ "D")) -> nba_stats
nba_stats$o_pts_cat <- as.factor(nba_stats$o_pts_cat)

Inspect the R pipeline that derives a points-allowed category from standardized values and converts it into a factor. section 14.5.1

How Statistics Slam Dunk covers it

How deep it goes
Explains construction, factor conversion, count validation, and boxplot comparison, but does not detail ANOVA calculations.
Examples
Demonstrates standardized points allowed and points scored grouped into four ranges and plotted against standardized regular-season wins.
What it assumes
Assumes quantitative variables and basic R familiarity while defining factors, categories, and boxplot summaries through application.
What you can do after
Builds and validates categorical predictors in R, then compares their groups with boxplots.
How it connects
Connects categorical predictors with ANOVA, factor variables, quantitative target variables, case_when(), and boxplots.

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.