arviz.rhat(data, *, var_names=None, method='rank', dask_kwargs=None)[source]

Compute estimate of rank normalized splitR-hat for a set of traces.

The rank normalized R-hat diagnostic tests for lack of convergence by comparing the variance between multiple chains to the variance within each chain. If convergence has been achieved, the between-chain and within-chain variances should be identical. To be most effective in detecting evidence for nonconvergence, each chain should have been initialized to starting values that are dispersed relative to the target distribution.


Any object that can be converted to an arviz.InferenceData object. Refer to documentation of arviz.convert_to_dataset() for details. At least 2 posterior chains are needed to compute this diagnostic of one or more stochastic parameters. For ndarray: shape = (chain, draw). For n-dimensional ndarray transform first to dataset with az.convert_to_dataset.


Names of variables to include in the rhat report


Select R-hat method. Valid methods are: - “rank” # recommended by Vehtari et al. (2019) - “split” - “folded” - “z_scale” - “identity”

dask_kwargsdict, optional

Dask related kwargs passed to wrap_xarray_ufunc().


Returns dataset of the potential scale reduction factors, \(\hat{R}\)

See also


Calculate estimate of the effective sample size (ess).


Calculate Markov Chain Standard Error statistic.


Forest plot to compare HDI intervals from a number of distributions.


The diagnostic is computed by:

\[\hat{R} = \frac{\hat{V}}{W}\]

where \(W\) is the within-chain variance and \(\hat{V}\) is the posterior variance estimate for the pooled rank-traces. This is the potential scale reduction factor, which converges to unity when each of the traces is a sample from the target posterior. Values greater than one indicate that one or more chains have not yet converged.

Rank values are calculated over all the chains with scipy.stats.rankdata. Each chain is split in two and normalized with the z-transform following Vehtari et al. (2019).



Calculate the R-hat using the default arguments:

In [1]: import arviz as az
   ...: data = az.load_arviz_data("non_centered_eight")
   ...: az.rhat(data)
Dimensions:  (school: 8)
  * school   (school) object 'Choate' 'Deerfield' ... "St. Paul's" 'Mt. Hermon'
Data variables:
    mu       float64 1.0
    theta_t  (school) float64 1.001 1.002 1.004 1.0 0.9999 1.0 1.0 1.006
    tau      float64 1.001
    theta    (school) float64 1.001 1.001 1.008 1.001 1.0 1.002 1.001 1.001

Calculate the R-hat of some variables using the folded method:

In [2]: az.rhat(data, var_names=["mu", "theta_t"], method="folded")
Dimensions:  (school: 8)
  * school   (school) object 'Choate' 'Deerfield' ... "St. Paul's" 'Mt. Hermon'
Data variables:
    mu       float64 1.0
    theta_t  (school) float64 1.0 1.002 1.004 1.0 0.9999 1.0 1.0 1.006