Bayesian Modal Regression Analysis of 2003 United States Crime Data

library(GUD)

Introduction

The general unimodal distribution (GUD) family is essentially a family of two-component mixture distributions. The probability density function (pdf) of a member of GUD family is \[ f\left(y \mid w, \theta, \boldsymbol{\xi}_1, \boldsymbol{\xi}_2\right)=w f_1\left(y \mid \theta, \boldsymbol{\xi}_1\right)+(1-w) f_2\left(y \mid \theta, \boldsymbol{\xi}_2\right), \] where \(w \in [0,1]\) is the weight parameter, \(\theta \in (-\infty, +\infty)\) is the mode as a location parameter, \(\boldsymbol{\xi}_1\) consists of parameters other than the location parameter in \(f_1\left(\cdot \mid \theta, \boldsymbol{\xi}_1\right)\) and \(\boldsymbol{\xi}_2\) is defined similarly for \(f_2\left(\cdot \mid \theta, \boldsymbol{\xi}_2\right)\). Besides unimodality, all members of the GUD family share three features:

  1. The pdfs \(f_1\left(\cdot \mid \theta, \boldsymbol{\xi}_1\right)\) and \(f_2\left(\cdot \mid \theta, \boldsymbol{\xi}_2\right)\) are unimodal at \(\theta\).
  2. The pdfs \(f_1\left(\cdot \mid \theta, \boldsymbol{\xi}_1\right)\) and \(f_2\left(\cdot \mid \theta, \boldsymbol{\xi}_2\right)\) are left-skewed and right-skewed respectively.
  3. The mixture pdf \(f\left(\cdot \mid w, \theta, \boldsymbol{\xi}_1, \boldsymbol{\xi}_2\right)\) in (1) is continuous in its domain.

More details of the GUD family can be found in Liu, Q., Huang, X., & Bai, R. (2022).

Bayesian Modal Regression Analysis of 2003 United States Crime Data

In this section, we demonstrate how to use the GUD package to analyze 2003 United States Crime Data as in Section 2 of Liu, Q., Huang, X., & Bai, R. (2022).

In “The Art and Science of Learning from Data, 5th edition” by Alan Agresti, Christine A. Franklin, and Bernhard Klingenberg, an interesting example about the 2003 United States crime data is presented to demonstrate the influence of outliers in the classic linear regression model. This example is very compelling and partially motivates the construction of the Bayesian modal regression based on the GUD family. This data contains the murder rate, percentage of college education, poverty percentage, and metropolitan rate for the 50 states in the United States and the District of Columbia (D.C.) from 2003. The murder rate is defined as the annual number of murders per \(100{,}000\) people in the population. The poverty percentage is the percentage of residents with income below the poverty level, and the metropolitan rate is defined as the percentage of population living in the metropolitan area. In the exploratory data analysis, we present the conditional scatter plot matrices below.

# load data crime from the GUD package
df1 <- crime
# the conditional scatter plot matrices of U.S. crime data
if (require(lattice)) {
  lattice::splom(~df1[c(6,4,9,3)],
                 main = NULL,
                 panel = function(x,y,...) {
                   panel.splom(x,y,...)
            })
}
#> Loading required package: lattice

In the conditional scatter plot matrices, we notice an outlier, Washington, D.C., which stands out and does not follow the common pattern of other states.

Next, we demonstrate how to fit the Bayesian modal regression model based on the TPSC distribution to the 2003 United States crime data.

df1 <- as.data.frame(df1)
TPSC_model <- modal_regression(`murder rate` ~ college + poverty + metropolitan, 
                               data = df1, 
                               model = "TPSC",
                               chains = 2,
                               iter = 2000)
#> 
#> SAMPLING FOR MODEL 'TPSC' NOW (CHAIN 1).
#> Chain 1: 
#> Chain 1: Gradient evaluation took 6.6e-05 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.66 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1: 
#> Chain 1: 
#> Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 1.057 seconds (Warm-up)
#> Chain 1:                0.66 seconds (Sampling)
#> Chain 1:                1.717 seconds (Total)
#> Chain 1: 
#> 
#> SAMPLING FOR MODEL 'TPSC' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 1.3e-05 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.13 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2: 
#> Chain 2: 
#> Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
#> Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
#> Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
#> Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
#> Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
#> Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
#> Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
#> Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
#> Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
#> Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
#> Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
#> Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
#> Chain 2: 
#> Chain 2:  Elapsed Time: 1.115 seconds (Warm-up)
#> Chain 2:                0.783 seconds (Sampling)
#> Chain 2:                1.898 seconds (Total)
#> Chain 2:

Summary of Bayesian Analysis

One can summarize the Bayesian analysis using the summary function.

print(summary(TPSC_model), n = 7)
#> # A tibble: 113 × 10
#>   variable        mean  median     sd    mad        q5     q95  rhat ess_bulk
#>   <chr>          <dbl>   <dbl>  <dbl>  <dbl>     <dbl>   <dbl> <dbl>    <dbl>
#> 1 w             0.283   0.283  0.119  0.125   0.0895    0.479  1.00      407.
#> 2 delta         1.85    1.72   0.635  0.547   1.09      3.08   1.00      736.
#> 3 sigma         1.18    1.17   0.255  0.262   0.775     1.60   1.00      779.
#> 4 (Intercept)   1.05    1.26   2.69   2.65   -3.70      5.07   1.00      704.
#> 5 college      -0.196  -0.201  0.0827 0.0836 -0.322    -0.0506 0.999     701.
#> 6 poverty       0.248   0.258  0.140  0.141  -0.000294  0.460  1.01      627.
#> 7 metropolitan  0.0634  0.0622 0.0150 0.0143  0.0407    0.0905 1.00      656.
#> # ℹ 106 more rows
#> # ℹ 1 more variable: ess_tail <dbl>

One can present the traceplot of the MCMC chain using the bayesplot::mcmc_trace function.

if (require(bayesplot)) {
  bayesplot::mcmc_trace(TPSC_model, pars = c("(Intercept)",
                                             "college", 
                                             "poverty", 
                                             "metropolitan"))
}
#> Loading required package: bayesplot
#> Warning: package 'bayesplot' was built under R version 4.3.1
#> This is bayesplot version 1.11.1
#> - Online documentation and vignettes at mc-stan.org/bayesplot
#> - bayesplot theme set to bayesplot::theme_default()
#>    * Does _not_ affect other ggplot2 plots
#>    * See ?bayesplot_theme_set for details on theme setting

The summary of posterior predictive distribution can be assessed using the following command. Here ystar[1] represents the posterior prediction of the first observation in the dataset, and so on.

summary(posterior::subset_draws(TPSC_model, variable = "ystar"))
#> # A tibble: 51 × 10
#>    variable    mean median       sd   mad     q5   q95  rhat ess_bulk ess_tail
#>    <chr>      <dbl>  <dbl>    <dbl> <dbl>  <dbl> <dbl> <dbl>    <dbl>    <dbl>
#>  1 ystar[1]    7.17   6.22     7.40  2.05  3.20  14.0  1.00     1857.    1834.
#>  2 ystar[2]    2.37   1.28    10.4   2.09 -1.68   9.20 1.00     1919.    1888.
#>  3 ystar[3]    6.36   6.03    23.4   1.87  3.09  13.1  1.00     1922.    1873.
#>  4 ystar[4]    6.13   5.56     5.77  2.22  2.18  12.6  1.00     1714.    1780.
#>  5 ystar[5]    7.07   6.25    40.8   2.07  3.19  13.8  0.999    1893.    1792.
#>  6 ystar[6]   21.6    2.65   806.    2.04 -0.356  9.84 1.00     1869.    1813.
#>  7 ystar[7]    6.77   3.76    72.8   1.87  0.864 11.6  1.00     1347.    1600.
#>  8 ystar[8]    5.87   4.87     7.00  1.94  2.10  12.3  1.00     2015.    1881.
#>  9 ystar[9]  242.     5.41 10536.    2.67  1.35  13.3  1.00     1479.    1555.
#> 10 ystar[10]   7.94   6.41    14.5   1.87  3.72  13.8  1.00     1844.    1823.
#> # ℹ 41 more rows

Further comparisons between mean, median, and modal regression can be found in Section 2 of Liu, Q., Huang, X., & Bai, R. (2022) and Section 6 of Liu, Q., Huang, X., & Zhou, H. (2024).