Positive definite warnings during beta binomial model (brms)

I am attempting to run a multilevel beta binomial model (with multiple imputation) and am getting some warnings from Stan. Are these safe to ignore or could I avoid them with better priors or starting values or something? Thanks!

m <- brm_multiple(
  formula = y | trials(27) ~ 1 + x + w + z + (1 + x + w + z | cluster),
  family = beta_binomial(link = "logit", link_phi = "log"),
  prior = set_prior("normal(0, 2)", class = "b"),
  data = mids,
  backend = "rstan",
  ...
)

Messages from Stan:

Chain 1: Rejecting initial value:
Chain 1: Error evaluating the log probability at the initial value.
Chain 1: Exception: beta_binomial_lpmf: Second prior sample size parameter is 0, but must be positive finite! (in ‘string’, line 141, column 6 to column 85)

Chain 1: Exception: model51c034f86857__namespace::write_array: y is not positive definite. (in ‘string’, line 152, column 2 to column 66)

Here is a MWE:

library(brms)

set.seed(2023)

# Simulate beta-binomial response var
y <- rep(
  0:27, 
  times = c(1572, 683, 573, 440, 336, 260, 220, 170, 130, 
            105, 84, 63, 54, 43, 37, 28, 23, 19, 18, 14, 
            8, 10, 6, 4, 5, 3, 1, 2)
)

# Simulate continuous predictor
x <- rnorm(length(y), mean = 0, sd = 1)

# Simulate nominal predictor
w <- factor(sample(
  letters[1:5], 
  size = length(y), 
  replace = TRUE, 
  prob = c(.17, .23, .39, .12, .09)
))

# Simulate cluster membership
cluster <- sample(1:7, size = length(y), replace = TRUE)

# Combine simulated variables
df <- data.frame(y, w, x, cluster)

m <- brm(
  y | trials(27) ~ 1 + x * w + (1 + x * w | cluster),
  family = beta_binomial(link = "logit", link_phi = "log"),
  prior = set_prior("normal(0, 2)", class = "b"),
  data = df,
  cores = 4,
  chains = 4,
  iter = 5000,
  seed = 2023
)
Response from Stan

SAMPLING FOR MODEL ‘anon_model’ NOW (CHAIN 3).
Chain 3: Rejecting initial value:
Chain 3: Error evaluating the log probability at the initial value.
Chain 3: Exception: beta_binomial_lpmf: Second prior sample size parameter is 0, but must be positive finite! (in ‘string’, line 102, column 6 to column 85)
Chain 3: Rejecting initial value:
Chain 3: Error evaluating the log probability at the initial value.
Chain 3: Exception: beta_binomial_lpmf: Second prior sample size parameter is 0, but must be positive finite! (in ‘string’, line 102, column 6 to column 85)
Chain 3:
Chain 3: Gradient evaluation took 0.008117 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 81.17 seconds.
Chain 3: Adjust your expectations accordingly!

Trimming out some of the random slopes seemed to help.

The errors here are safe to ignore because they only occur during the initialisation phase, and it only rejects the initial values twice (for me locally) before continuing to sample.

As a technical explainer for where this error is coming from, the brms likelihood translates to the following Stan likelihood:

beta_binomial_lpmf(Y[n] | trials[n], mu[n] * phi, (1 - mu[n]) * phi)

The quantity in the error (Second prior sample size parameter) is the last term: (1 - mu[n]) * phi, where mu[n] is the linear term for the n-th individual (after applying the inv_logit() function.

Given that this second term is evaluating to zero, but not the first (since there’s no rejection error), we can assume that phi is not initialising zero. This means that (for some individuals) their linear predictor mu[n] is initialising to 1. This is likely due to overflow, since mu[n] is the result of the inv_logit() function, which overflows to 1 for very large inputs.

TLDR: this is just the model rejecting initial values that are too large, and safe to ignore

2 Likes