@@ -0,0 +1,3091 @@
+package galileo.stat;%0A%0A/**%0A * Expanding on the %7B@link RunningStatistics%7D class, this class supports%0A * two dimensions (x and y), along with some extra features (simple linear%0A * regression and calculating correlation).%0A *%0A * @author malensek%0A */%0Apublic class RunningStatistics2D %7B%0A%0A    private RunningStatistics xs;%0A    private RunningStatistics ys;%0A%0A    private double SSxy;%0A%0A    public RunningStatistics2D() %7B%0A        xs = new RunningStatistics();%0A        ys = new RunningStatistics();%0A    %7D%0A%0A    /**%0A     * Adds several new (x, y) sample pairs to the 2D running statistics.%0A     *%0A     * @param samples Array of two-element arrays (representing x and y)%0A     */%0A    public void put(double%5B%5D... samples) %7B%0A        for (double%5B%5D sample : samples) %7B%0A            if (sample.length != 2) %7B%0A                throw new IllegalArgumentException(%22Input arrays must contain %22%0A                        + %22a single sample pair (x, y)%22);%0A            %7D%0A            put(sample%5B0%5D, sample%5B1%5D);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Adds a new sample to the 2D running statistics.%0A     */%0A    public void put(double x, double y) %7B%0A        double n = (double) xs.numSamples();%0A%0A        double dx = x - xs.mean();%0A        double dy = y - ys.mean();%0A        SSxy += dx * dy * n / (n + 1);%0A%0A        xs.put(x);%0A        ys.put(y);%0A    %7D%0A%0A    /**%0A     * @return Sum of the cross products (xy)%0A     */%0A    public double SSxy() %7B%0A        return SSxy;%0A    %7D%0A%0A    /**%0A     * @return Sum of squared deviations from the mean of x%0A     */%0A    public double SSxx() %7B%0A        return xs.var() * (xs.numSamples() - 1.0);%0A    %7D%0A%0A    /**%0A     * @return Sum of squared deviations from the mean of y%0A     */%0A    public double SSyy() %7B%0A        return ys.var() * (xs.numSamples() - 1.0);%0A    %7D%0A%0A    /**%0A     * Calculate the Pearson product-moment correlation coefficient.%0A     *%0A     * @return PPMCC (Pearson's r)%0A     */%0A    public double R() %7B%0A        return Math.sqrt(R2());%0A    %7D%0A%0A    /**%0A     * Calculate the coefficient of determination (R squared).%0A     *%0A     * @return coefficient of determination%0A     */%0A    public double R2() %7B%0A        double SSE = (SSyy() - SSxy() * SSxy() / SSxx());%0A        return (SSyy() - SSE) / SSyy();%0A    %7D%0A%0A    /**%0A     * @return the slope of the regression line (beta).%0A     */%0A    public double slope() %7B%0A        return SSxy() / SSxx();%0A    %7D%0A%0A    /**%0A     * @return the y-intercept of the regression line (alpha).%0A     */%0A    public double intercept() %7B%0A        return ys.mean() - slope() * xs.mean();%0A    %7D%0A%0A    /**%0A     * Given a value of x, estimate the outcome of y using simple linear%0A     * regression.%0A     *%0A     * @return estimated value of y%0A     */%0A    public double predict(double x) %7B%0A        return intercept() + slope() * x;%0A    %7D%0A%0A    /**%0A     * @return a copy of the running statistics instance for x.%0A     */%0A    public RunningStatistics xStatistics() %7B%0A        return new RunningStatistics(xs);%0A    %7D%0A%0A    /**%0A     * @return a copy of the running statistics instance for y.%0A     */%0A    public RunningStatistics yStatistics() %7B%0A        return new RunningStatistics(ys);%0A    %7D%0A%7D%0A

Add 2D running stats class