|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math3.stat.correlation.Covariance
public class Covariance
Computes covariances for pairs of arrays or columns of a matrix.
The constructors that take RealMatrix
or
double[][]
arguments generate covariance matrices. The
columns of the input matrices are assumed to represent variable values.
The constructor argument biasCorrected
determines whether or
not computed covariances are bias-corrected.
Unbiased covariances are given by the formula
cov(X, Y) = Σ[(xi - E(X))(yi - E(Y))] / (n - 1)
where E(X)
is the mean of X
and E(Y)
is the mean of the Y
values.
Non-bias-corrected estimates use n
in place of n - 1
Field Summary | |
---|---|
private RealMatrix |
covarianceMatrix
covariance matrix |
private int |
n
Number of observations (length of covariate vectors) |
Constructor Summary | |
---|---|
Covariance()
Create a Covariance with no data |
|
Covariance(double[][] data)
Create a Covariance matrix from a rectangular array whose columns represent covariates. |
|
Covariance(double[][] data,
boolean biasCorrected)
Create a Covariance matrix from a rectangular array whose columns represent covariates. |
|
Covariance(RealMatrix matrix)
Create a covariance matrix from a matrix whose columns represent covariates. |
|
Covariance(RealMatrix matrix,
boolean biasCorrected)
Create a covariance matrix from a matrix whose columns represent covariates. |
Method Summary | |
---|---|
private void |
checkSufficientData(RealMatrix matrix)
Throws MathIllegalArgumentException if the matrix does not have at least one column and two rows. |
protected RealMatrix |
computeCovarianceMatrix(double[][] data)
Create a covariance matrix from a rectangular array whose columns represent covariates. |
protected RealMatrix |
computeCovarianceMatrix(double[][] data,
boolean biasCorrected)
Compute a covariance matrix from a rectangular array whose columns represent covariates. |
protected RealMatrix |
computeCovarianceMatrix(RealMatrix matrix)
Create a covariance matrix from a matrix whose columns represent covariates. |
protected RealMatrix |
computeCovarianceMatrix(RealMatrix matrix,
boolean biasCorrected)
Compute a covariance matrix from a matrix whose columns represent covariates. |
double |
covariance(double[] xArray,
double[] yArray)
Computes the covariance between the two arrays, using the bias-corrected formula. |
double |
covariance(double[] xArray,
double[] yArray,
boolean biasCorrected)
Computes the covariance between the two arrays. |
RealMatrix |
getCovarianceMatrix()
Returns the covariance matrix |
int |
getN()
Returns the number of observations (length of covariate vectors) |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final RealMatrix covarianceMatrix
private final int n
Constructor Detail |
---|
public Covariance()
public Covariance(double[][] data, boolean biasCorrected) throws MathIllegalArgumentException, NotStrictlyPositiveException
The biasCorrected
parameter determines whether or not
covariance estimates are bias-corrected.
The input array must be rectangular with at least one column and two rows.
data
- rectangular array with columns representing covariatesbiasCorrected
- true means covariances are bias-corrected
MathIllegalArgumentException
- if the input data array is not
rectangular with at least two rows and one column.
NotStrictlyPositiveException
- if the input data array is not
rectangular with at least one row and one column.public Covariance(double[][] data) throws MathIllegalArgumentException, NotStrictlyPositiveException
The input array must be rectangular with at least one column and two rows
data
- rectangular array with columns representing covariates
MathIllegalArgumentException
- if the input data array is not
rectangular with at least two rows and one column.
NotStrictlyPositiveException
- if the input data array is not
rectangular with at least one row and one column.public Covariance(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException
The biasCorrected
parameter determines whether or not
covariance estimates are bias-corrected.
The matrix must have at least one column and two rows
matrix
- matrix with columns representing covariatesbiasCorrected
- true means covariances are bias-corrected
MathIllegalArgumentException
- if the input matrix does not have
at least two rows and one columnpublic Covariance(RealMatrix matrix) throws MathIllegalArgumentException
The matrix must have at least one column and two rows
matrix
- matrix with columns representing covariates
MathIllegalArgumentException
- if the input matrix does not have
at least two rows and one columnMethod Detail |
---|
public RealMatrix getCovarianceMatrix()
public int getN()
protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) throws MathIllegalArgumentException
matrix
- input matrix (must have at least one column and two rows)biasCorrected
- determines whether or not covariance estimates are bias-corrected
MathIllegalArgumentException
- if the matrix does not contain sufficient dataprotected RealMatrix computeCovarianceMatrix(RealMatrix matrix) throws MathIllegalArgumentException
matrix
- input matrix (must have at least one column and two rows)
MathIllegalArgumentException
- if matrix does not contain sufficient dataCovariance(org.apache.commons.math3.linear.RealMatrix)
protected RealMatrix computeCovarianceMatrix(double[][] data, boolean biasCorrected) throws MathIllegalArgumentException, NotStrictlyPositiveException
data
- input array (must have at least one column and two rows)biasCorrected
- determines whether or not covariance estimates are bias-corrected
MathIllegalArgumentException
- if the data array does not contain sufficient
data
NotStrictlyPositiveException
- if the input data array is not
rectangular with at least one row and one column.protected RealMatrix computeCovarianceMatrix(double[][] data) throws MathIllegalArgumentException, NotStrictlyPositiveException
data
- input array (must have at least one column and two rows)
MathIllegalArgumentException
- if the data array does not contain sufficient data
NotStrictlyPositiveException
- if the input data array is not
rectangular with at least one row and one column.Covariance(org.apache.commons.math3.linear.RealMatrix)
public double covariance(double[] xArray, double[] yArray, boolean biasCorrected) throws MathIllegalArgumentException
Array lengths must match and the common length must be at least 2.
xArray
- first data arrayyArray
- second data arraybiasCorrected
- if true, returned value will be bias-corrected
MathIllegalArgumentException
- if the arrays lengths do not match or
there is insufficient datapublic double covariance(double[] xArray, double[] yArray) throws MathIllegalArgumentException
Array lengths must match and the common length must be at least 2.
xArray
- first data arrayyArray
- second data array
MathIllegalArgumentException
- if the arrays lengths do not match or
there is insufficient dataprivate void checkSufficientData(RealMatrix matrix) throws MathIllegalArgumentException
matrix
- matrix to check
MathIllegalArgumentException
- if the matrix does not contain sufficient data
to compute covariance
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |