Compute Log Predictive Distributions for a Hurdle Poisson Model of a 'brms' Fit
Source:R/log_pred_dist_HP.R
log_pred_dist_HP.RdThis function calculates the log predictive mass function (log-PMF) and the log cumulative distribution function (log-CDF) for each observation from a fitted hurdle Poisson model (fitted using brms). The function extracts posterior samples for the model parameters and evaluates the predictive distributions across all posterior draws.
Value
A list with the following components:
lpmf_hatA matrix of log-PMF values (posterior samples × observations).
lcdf_hatA matrix of log-CDF values (posterior samples × observations).
zero_idIndices of observations with zero counts.
count_idIndices of observations with positive counts.
Details
For each posterior draw and observation, the function computes:
lpmf_hat: Log predictive mass function values usingdhurdle.pois().lcdf_hat: Log cumulative distribution function values usingphurdle.pois()withlower.tail = FALSE.
The function also identifies indices of zero and positive count responses.
Examples
if (FALSE) { # \dontrun{
# Example usage:
fit <- brm(bf(y ~ x1 + x2, hu ~ x1), family = hurdle_poisson(), data = mydata)
pred_dist <- log_pred_dist_HP(fit)
str(pred_dist)
} # }