20 Negative Binomial: Estimating Homicides in Census Tracks

The data are from the 1990 United States Census for the city of St. Louis, Missouri for Census Tracts, and from records of the St. Louis City Metropolitan Police Department for the years 1980 through 1994. For each Census Tract (with a population), N=111, an observation includes

  • the median household income in 1990
  • the percentage unemployed (base of labor force)
  • a count of the number of homicide incidents.

The number of homicides in this 15 year period totals 2,815. The average size of a Census Tract is 3,571 with a range of 249–8,791. Income has been rescaled by dividing by 1,000 which produces a range similar to that of percentage unemployed and standard deviations that are very close. Tract homicide counts range from 0 through 99 with a median of 16 (mean is 25.+). An enhanced set of linear, predictors does better than this two predictor example.

\[ \begin{aligned}[t] y_i &\sim \mathsf{NegBinomial2}(\mu_i,\phi) \\ \mu_i &= \frac{1}{1 + e^{-\eta_i}} \\ \eta_i &= x_i \beta \end{aligned} \] The negative binomial distribution is parameterized so that \(\mu \in \mathbb{R}^+\) is the location parameter, and \(\phi \in \mathbb{R}^+\) is the reciprocal overdispersion parameter, such that the mean and variance of a random variable \(Y\) distributed negative binomial is \[ \begin{aligned}[t] E[Y] &= \mu , \\ V[Y] &= \mu + \frac{\mu^2}{\phi} . \end{aligned} \] As \(\phi \to \infty\), the negative binomial approaches the Poisson distribution.

The parameters are given weakly informative priors, \[ \begin{aligned}[t] \alpha &\sim \mathsf{Normal}(0, 10), \\ \beta_k &\sim \mathsf{Normal}(0, 2.5), \\ \phi^{-1} &\sim \mathsf{HalfCauchy}(0, 5). \end{aligned} \]

  data {
  int N;
  int y[N];
  int K;
  matrix[N, K] X;
  // priors
  real alpha_mean;
  real alpha_scale;
  vector[K] beta_mean;
  vector[K] beta_scale;
  real reciprocal_phi_scale;
}
parameters {
  real alpha;
  vector[K] beta;
  real reciprocal_phi;
}
transformed parameters {
  vector[N] eta;
  real phi;
  eta = alpha + X * beta;
  phi = 1. / reciprocal_phi;
}
model {
  reciprocal_phi ~ cauchy(0., reciprocal_phi_scale);
  alpha ~ normal(alpha_mean, alpha_scale);
  beta ~ normal(beta_mean, beta_scale);
  y ~ neg_binomial_2_log(eta, phi);
}
generated quantities {
  vector[N] mu;
  vector[N] log_lik;
  vector[N] y_rep;
  mu = exp(eta);
  for (i in 1:N) {
    log_lik[i] = neg_binomial_2_log_lpmf(y[i] | eta[i], phi);
    y_rep[i] = neg_binomial_2_rng(mu[i], phi);
  }
}

We could also fit the model using the rstanarm function stan_glm.nb (or stan_glm):

Example derived from Simon Jackman, “negative binomial using the ones trick with log link”, 2005-10-27, URL.