## org.apache.commons.math3.stat.correlation
Class StorelessBivariateCovariance

    java.lang.Object
      org.apache.commons.math3.stat.correlation.StorelessBivariateCovariance

     class StorelessBivariateCovariance

extends java.lang.Object

Bivariate Covariance implementation that does not require input data to be stored in memory.

This class is based on a paper written by Philippe Pébay: Formulas for Robust, One-Pass Parallel Computation of Covariances and Arbitrary-Order Statistical Moments, 2008, Technical Report SAND2008-6212, Sandia National Laboratories. It computes the covariance for a pair of variables. Use `StorelessCovariance` to estimate an entire covariance matrix.

Note: This class is package private as it is only used internally in the `StorelessCovariance` class.

Since:
  3.0
Version:
  $Id: StorelessBivariateCovariance.java 1410238 2012-11-16 07:58:49Z luc $

Field Summary
`private boolean` `biasCorrected` flag for bias correction
`private double` `covarianceNumerator` the running covariance estimate
`private double` `meanX` the mean of variable x
`private double` `meanY` the mean of variable y
`private double` `n` number of observations

Constructor Summary
`StorelessBivariateCovariance()` Create an empty `StorelessBivariateCovariance` instance with bias correction.
`StorelessBivariateCovariance(boolean biasCorrection)` Create an empty `StorelessBivariateCovariance` instance.

Method Summary
`double` `getN()` Returns the number of observations.
`double` `getResult()` Return the current covariance estimate.
`void` `increment(double x, double y)` Update the covariance estimation with a pair of variables (x, y).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### meanX

    private double meanX

  the mean of variable x

### meanY

    private double meanY

  the mean of variable y

### n

    private double n

  number of observations

### covarianceNumerator

    private double covarianceNumerator

  the running covariance estimate

### biasCorrected

    private boolean biasCorrected

  flag for bias correction

Constructor Detail

### StorelessBivariateCovariance

    public StorelessBivariateCovariance()

  Create an empty `StorelessBivariateCovariance` instance with bias correction.

### StorelessBivariateCovariance

    public StorelessBivariateCovariance(boolean biasCorrection)

  Create an empty `StorelessBivariateCovariance` instance.

  Parameters:
    `biasCorrection` - if `true` the covariance estimate is corrected for bias, i.e. n-1 in the denominator, otherwise there is no bias correction, i.e. n in the denominator.

Method Detail

### increment

    public void increment(double x,
                          double y)

  Update the covariance estimation with a pair of variables (x, y).

  Parameters:
    `x` - the x value
    `y` - the y value

### getN

    public double getN()

  Returns the number of observations.

  Returns:
    number of observations

### getResult

    public double getResult()
                     throws NumberIsTooSmallException

  Return the current covariance estimate.

  Returns:
    the current covariance
  Throws:
    `NumberIsTooSmallException` - if the number of observations is < 2

Copyright (c) 2003-2013 Apache Software Foundation