# CovarianceAccumulator class

`CovarianceAccumulator`

computes covariance and correlation of pairs of samples by accumulating the
first two central moments and cross-moments.

Samples are added one pair at the time, using the `Push`

method. Other members are used to retrieve the results.
The accumulator uses a stable algorithm to prevent catastrophic cancellation.

The covariance matrix is formed by

| cov.VarianceX() cov.Covariance() | | cov.Covariance() cov.VarianceY() |

The `Regression`

method returns the parameters to the least squares fit of the equation ,
where is the first sample in each pair and is the second (this is linear regression), is the
intercept and is the slope. The `Slope`

method computes only the slope component.

It is possible to accumulate samples in different objects (e.g. when processing with multiple threads),
and add the accumulators together using the `+`

operator.

## Aliases

- using RegressionResult = dip::RegressionParameters
- Copying type for backward compatibility.

## Functions

- void Reset()
- Reset the accumulator, leaving it as if newly allocated.
- void Push(dip::dfloat x, dip::dfloat y)
- Add a pair of samples to the accumulator
- auto Number() const -> size_t
- Number of samples
- auto MeanX() const -> dip::dfloat
- Unbiased estimator of population mean for first variable
- auto MeanY() const -> dip::dfloat
- Unbiased estimator of population mean for second variable
- auto VarianceX() const -> dip::dfloat
- Unbiased estimator of population variance for first variable
- auto VarianceY() const -> dip::dfloat
- Unbiased estimator of population variance for second variable
- auto StandardDeviationX() const -> dip::dfloat
- Estimator of population standard deviation for first variable (it is not possible to derive an unbiased estimator)
- auto StandardDeviationY() const -> dip::dfloat
- Estimator of population standard deviation for second variable (it is not possible to derive an unbiased estimator)
- auto Covariance() const -> dip::dfloat
- Unbiased estimator of population covariance
- auto Correlation() const -> dip::dfloat
- Estimator of correlation between the two variables
- auto Slope() const -> dip::dfloat
- Computes the slope of the regression line
- auto Regression() const -> dip::CovarianceAccumulator::RegressionResult
- Computes the slope and intercept of the regression line

## Operators

- auto operator+=(dip::CovarianceAccumulator const& other) -> dip::CovarianceAccumulator&
- Combine two accumulators