/** * Created with IntelliJ IDEA. * User: rebeccamancy * Date: 25/10/2013 * Time: 16:16 * To change this template use File | Settings | File Templates. */ public class Sequences { // The sequence class is used to test for convergence using the Rhat statistic, which approaches 1 as n->infty // Properties private int prevN; private double[] prevSum, prevSumSq; private double rHat; /** * Constructor - before rhat is calculated - sets rhat to zero initially. * @param prevN * @param prevSum * @param prevSumSq */ public Sequences (int prevN, double[] prevSum, double[] prevSumSq) { // Set up a sequence from the information read in ... this.prevN = prevN; this.prevSum = prevSum; this.prevSumSq = prevSumSq; this.rHat = 0; // Some arbitrary value to start } /** * Tests convergence given the existing information on the sequences and an array of new data, returning current rhat * @param curSlice * @return */ public double testConvergence( double[][] curSlice) { // Calculate rHat on a Sequences object (i.e. given an array of doubles) int n, curN, m; double[] sumij, sumsq; double[] curSum, curSumSq; m = this.prevSum.length; // Calculate n, sum and sumsq for current window curN = curSlice.length; curSum = Util.sumArray(curSlice); curSumSq = Util.sumSqArray(curSlice); // Calculate total n, sum and sumsq n = this.prevN + curN; sumij = Util.add(this.prevSum, curSum); sumsq = Util.add(this.prevSumSq, curSumSq); // Intermediate calculations double[] psidotjbar = Util.div(sumij,n); double psidotdotbar = Util.sumArray(psidotjbar)/m; double[] psidotdotbararr = new double[m]; for (int i=0; i