public class Covariance extends java.lang.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[][] data)
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[][] data)
Update the covariance statistic with more data.
|
double |
correlation()
Get the correlation.
|
long |
N()
Get the size of the sample.
|
java.lang.String |
toString() |
double |
value()
Get the value of the statistic.
|
public Covariance()
Covariance calculator.public Covariance(double[][] data)
Covariance calculator, initialized with two samples.
The size of the two samples must be equal.data - the two samplespublic 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[][] data)
data - two new samplespublic double value()
Statisticpublic long N()
Statisticpublic java.lang.String toString()
toString in class java.lang.Object