public class Covariance extends Object implements Statistic
Cov(X, Y) = E[(X - E(X)) * (Y - E(Y))]Note that this implementation uses N - 1 as the denominator to give an unbiased estimator of the covariance for i.i.d. observations. This implementation uses Pébay's update formula to incrementally compute the new statistic.
Constructor and Description |
---|
Covariance()
Construct an empty
Covariance calculator. |
Covariance(Covariance that)
Copy constructor.
|
Covariance(double[] data1,
double[] data2)
Construct a
Covariance calculator, initialized with two samples. |
Modifier and Type | Method and Description |
---|---|
void |
addData(double... data)
Update the covariance statistic with more data.
|
void |
addData(double[] data1,
double[] data2)
Update the covariance statistic with more data.
|
double |
correlation()
Get the correlation, i.e., Pearson's correlation coefficient.
|
long |
N()
Get the size of the sample.
|
String |
toString() |
double |
value()
Get the value of the statistic.
|
public Covariance()
Covariance
calculator.public Covariance(double[] data1, double[] data2)
Covariance
calculator, initialized with two samples.
The size of the two samples must be equal.data1
- the first sampledata2
- the second samplepublic Covariance(Covariance that)
that
- a Covariance
instancepublic double correlation()
public void addData(double... data)
double[]
,
we concatenate the two arrays into one.
For example, suppose we want to do
addData(new double[][]{
{1, 2, 3},
{4, 5, 6}
});
We can also write
addData(new double[]{
{1, 2, 3, 4, 5, 6}
});
In the latter case, there must be an even number of data points.public void addData(double[] data1, double[] data2)
data1
- the first new sampledata2
- the second new samplepublic double value()
Statistic
public long N()
Statistic
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.