credible_interval#
- bayesflow.utils.numpy_utils.credible_interval(x: ndarray, prob: float = 0.95, axis: Sequence[int] | int = None, **kwargs) ndarray[source]#
Compute credible interval from samples using quantiles.
- Parameters:
- xarray_like
Input array of samples from a posterior distribution or bootstrap samples.
- probfloat, default 0.95
Coverage probability of the credible interval (between 0 and 1). For example, 0.95 gives a 95% credible interval.
- axisSequence[int]
Axis or axes along which the credible interval is computed. Default is None (flatten array).
- Returns:
- a numpy array of shape (2, …) with the first dimension indicating the
- lower and upper bounds of the credible interval.
Examples
>>> import numpy as np >>> # Simulate posterior samples >>> samples = np.random.normal(size=(10, 1000, 3))
>>> # Different coverage probabilities >>> credible_interval(samples, prob=0.5, axis=1) # 50% CI >>> credible_interval(samples, prob=0.99, axis=1) # 99% CI