R_hat: Compute Gelman-Rubin statistic.

Description Usage Arguments Value References Examples

View source: R/R_hat.R

Description

This function computes the Gelman-Rubin statistic R_hat.

Usage

1
R_hat(samples, parts = 2)

Arguments

samples

A vector or a matrix of samples from a Markov chain, e.g. Gibbs samples. If samples is a matrix, each column gives the samples for a separate run.

parts

The number of parts to divide each chain into sub-chains.

Value

The Gelman-Rubin statistic.

References

https://bookdown.org/rdpeng/advstatcomp/monitoring-convergence.html

Examples

1
2
3
4
5
6
7
8
no_chains = 2
length_chains = 1e3
samples = matrix(NA,length_chains,no_chains)
samples[1,] = 1
Gamma = matrix(c(0.8,0.1,0.2,0.9),2,2)
for(c in 1:no_chains) for(t in 2:length_chains)
  samples[t,c] = sample(1:2, 1, prob = Gamma[samples[t-1,c],])
R_hat(samples)

RprobitB documentation built on Nov. 12, 2021, 5:08 p.m.