Calculates and prints key summaries of posterior samples and diagnostic
quantities from MCMC chains.
These include the posterior mean, standard deviation, quantiles, rhat,
effective sample size and (if running time is supplied) effective samples
per second.
Parameters:
chains – An array or list of chains returned by an MCMC sampler.
time (float) – The time taken for the run, in seconds (optional).
parameter_names (sequence) – A list of parameter names (optional).
Return Gelman and Rubin’s rhat value as defined in [1]. If a single
chain is used, the chain is split into two halves and rhat is
calculated using these two parts.
Return a list of the parameter name, posterior mean, posterior std
deviation, the 2.5%, 25%, 50%, 75% and 97.5% posterior quantiles,
rhat, effective sample size (ess) and ess per second of run time.
Returns the convergence measure \(\hat{R}\) for the approximate
posterior according to [3].
\(\hat{R}\) diagnoses convergence by checking mixing and stationarity
of \(m\) chains (at least two, \(m\geq 2\)). To diminish the
influence of starting values, the first portion of each chain can be
excluded from the computation. Subsequently, the truncated
chains are split in half, resulting in a total number of \(m'=2m\)
chains of length \(n'=(1-\text{warm_up})n/2\). The mean of the
variances within and between the resulting chains are computed, \(W\)
and \(B\) respectively. Based on those variances an estimator of the
marginal posterior variance is constructed
The estimator overestimates the variance of the marginal posterior
if the chains are not well mixed and stationary, but is unbiased if the
original chains equal the target distribution. At the same time, the mean
within variance \(W\) underestimates the marginal posterior variance
for finite \(n\), but converges to the true variance for
\(n\rightarrow \infty\). By comparing \(\widehat{\text{var}}^+\)
and \(W\) the mixing and stationarity of the chains can be quantified
Here, \(\psi _{ij}\) is the jth sample of the ith
chain, \(\bar{\psi _j}=\sum _{i=1}^{n'}\psi _{ij}/n'\) is the within
chain mean of the parameter \(\psi\) and
\(\bar{\psi } = \sum _{j=1}^{m'}\bar{\psi} _{j}/m'\) is the between
chain mean of the within chain means.
References
Parameters:
chains (np.ndarray of shape (m, n) or (m, n, p)) – A numpy array with \(n\) samples for each of \(m\) chains.
Optionally the \(\hat{R}\) for \(p\) parameters can be computed
by passing a numpy array with \(m\) chains of length \(n\)
for \(p\) parameters.
warm_up (float) – First portion of each chain that will not be used for the
computation of \(\hat{R}\).
Returns:
rhat – \(\hat{R}\) of the posteriors for each parameter.