|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.stats.descriptive.Covariance
public class Covariance
Covariance is a measure of how much two variables change together.
In this implementation, we compute covariance using the Pearson method.
Cov(X, Y) = E[(X - E(X)) * (Y - E(Y))]
Note that we use N - 1 as the denominator to give an unbiased estimator of the covariance for i.i.d. observations.
| Constructor Summary | |
|---|---|
Covariance()
Construct an empty Covariance calculator. |
|
Covariance(Covariance that)
Copy constructor. |
|
Covariance(double[][] data)
Construct a Covariance calculator, initialized with two samples. |
|
| Method Summary | |
|---|---|
void |
addData(double... data)
Recompute the statistic, incrementally if possible. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Covariance()
public Covariance(double[][] data)
For example,
Covariance = new Covariance(new double[][]{
{1, 2, 3},
{4, 5, 6}
});
The size of the two double[]s must be equal.
public Covariance(Covariance that)
that - a Covariance instance| Method Detail |
|---|
public void addData(double... data)
Since this function takes only a single double array, we concatenate two arrays into one.
For example, suppose we want to
addData(new double[][]{
{1, 2, 3},
{4, 5, 6}
});
We can instead write
addData(new double[]{
{1, 2, 3, 4, 5, 6}
});
There must be an even number of data points.
addData in interface Statisticdata - a data array made by concatenating two samplespublic void addData(double[][] data)
data - two new samplespublic double value()
Statistic
value in interface Statisticpublic double correlation()
public long N()
Statistic
N in interface Statisticpublic java.lang.String toString()
toString in class java.lang.Object
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||