Compute Log Predictive Distributions for a Truncated Negative Binomial Model of a 'brms' Fit
Source:R/log_pred_dist_TNB.R
log_pred_dist_TNB.RdThis function calculates the log predictive mass function (log-PMF) and the log cumulative distribution function (log-CDF) for each observation from a fitted truncated negative binomial model (fitted using brms). The function extracts posterior samples for the model’s distributional 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).
Examples
if (FALSE) { # \dontrun{
# Example usage:
fit <- brm(bf(y | trunc(lb = 1) ~ x1 + x2), family = negbinomial(), data = mydata)
pred_dist <- log_pred_dist_TNB(fit)
str(pred_dist)
} # }