Marginalization#

Model transformations that integrate variables out of a model, and recover them afterwards. Marginalizing discrete variables allows sampling with gradient-based samplers like NUTS; marginalizing conjugate pairs or using the Laplace approximation reduces the dimensionality of the posterior.

marginalize returns a model where the requested variables no longer appear, but the remaining variables keep their original joint distribution (exactly, or approximately when using the Laplace approximation). unmarginalize undoes the transformation, and conditional / recover reintroduce the marginalized variables conditioned on the posterior of the remaining ones.

marginalize(model, rvs_to_marginalize, *, ...)

Marginalize a subset of variables in a PyMC model.

unmarginalize(model[, rvs_to_unmarginalize])

Unmarginalize a subset of variables in a PyMC model.

conditional(model[, rvs_to_recover])

Replace marginalized variables with their conditional distributions.

recover(idata, *[, model, var_names, ...])

Sample marginalized variables from their conditional posterior.

The set of supported marginalizations is extensible; see Extending marginalization.