Extract Posterior Predicted Parameters from a Hurdle or Count Model
Source:R/posterior.pred.R
posterior.pred.RdComputes posterior predicted values for a specified distributional parameter (e.g., mean, shape, or hurdle probability) from a fitted Bayesian count or hurdle model. The function supports extracting parameters for positive counts only or for all observations.
Arguments
- fit
A fitted brms model object containing data, formula, and MCMC posterior draws.
- dpar
Character string specifying the distributional parameter to extract:
"mu"(mean),"shape"(dispersion), or"zero"(hurdle probability).- count.only
Logical; if
TRUE(default), computes predicted parameters only for positive counts (y > 0); otherwise, includes all observations.
Value
A numeric matrix of predicted parameter values for each observation (columns) and posterior draw (rows).
Details
The function performs the following steps:
Builds the model matrix for the chosen parameter and observation subset.
Extracts the corresponding posterior MCMC draws from the fitted model.
Computes the linear predictor via matrix multiplication of draws and model matrix.
Applies the link function associated with the parameter (e.g., logit, log) to obtain the predicted parameter values on their natural scale.