@staticmethod
    def gelman_rubin(x):
    
        if np.shape(x) < (2,):
            raise ValueError(
                'Gelman-Rubin diagnostic requires multiple chains of the same length.')
    
        m, n = np.shape(x)
    
        # Calculate between-chain variance
        B_over_n = np.sum((np.mean(x, 1) - np.mean(x)) ** 2) / (m - 1)
    
        # Calculate within-chain variances
        W = np.sum(
            [(x[i] - xbar) ** 2 for i,
             xbar in enumerate(np.mean(x,
                                       1))]) / (m * (n - 1))
    
        # (over) estimate of variance
        s2 = W * (n - 1) / n + B_over_n
    
        # Pooled posterior variance estimate
        V = s2 + B_over_n / m
    
        # Calculate PSRF
        R = V / W
    
        return R
Returns estimate of R for a set of traces.
dataset/ETHPy150Open karlnapf/kameleon-mcmc/kameleon_mcmc/tools/ConvergenceStats.py/ConvergenceStats.gelman_rubin