public class PearsonsCorrelation extends Object
The constructors that take RealMatrix
or double[][]
arguments generate correlation
matrices. The columns of the input matrices are assumed to represent variable values. Correlations are given by the
formula
cor(X, Y) = Σ[(xi - E(X))(yi - E(Y))] / [(n - 1)s(X)s(Y)]
where
E(X)
is the mean of X
, E(Y)
is the mean of the Y
values and s(X),
s(Y) are standard deviations.Constructor and Description |
---|
PearsonsCorrelation()
Create a PearsonsCorrelation instance without data
|
PearsonsCorrelation(Covariance covariance)
Create a PearsonsCorrelation from a
Covariance . |
PearsonsCorrelation(double[][] data)
Create a PearsonsCorrelation from a rectangular array
whose columns represent values of variables to be correlated.
|
PearsonsCorrelation(RealMatrix matrix)
Create a PearsonsCorrelation from a RealMatrix whose columns
represent variables to be correlated.
|
PearsonsCorrelation(RealMatrix covarianceMatrix,
int numberOfObservations)
Create a PearsonsCorrelation from a covariance matrix.
|
Modifier and Type | Method and Description |
---|---|
RealMatrix |
computeCorrelationMatrix(double[][] data)
Computes the correlation matrix for the columns of the
input rectangular array.
|
RealMatrix |
computeCorrelationMatrix(RealMatrix matrix)
Computes the correlation matrix for the columns of the
input matrix.
|
double |
correlation(double[] xArray,
double[] yArray)
Computes the Pearson's product-moment correlation coefficient between the two arrays.
|
RealMatrix |
covarianceToCorrelation(RealMatrix covarianceMatrix)
Derives a correlation matrix from a covariance matrix.
|
RealMatrix |
getCorrelationMatrix()
Returns the correlation matrix
|
RealMatrix |
getCorrelationPValues()
Returns a matrix of p-values associated with the (two-sided) null
hypothesis that the corresponding correlation coefficient is zero.
|
RealMatrix |
getCorrelationStandardErrors()
Returns a matrix of standard errors associated with the estimates
in the correlation matrix.
|
public PearsonsCorrelation()
public PearsonsCorrelation(double[][] data)
data
- rectangular array with columns representing variablesIllegalArgumentException
- if the input data array is not
rectangular with at least two rows and two columns.public PearsonsCorrelation(RealMatrix matrix)
matrix
- matrix with columns representing variables to correlatepublic PearsonsCorrelation(Covariance covariance)
Covariance
. The correlation
matrix is computed by scaling the Covariance's covariance matrix.
The Covariance instance must have been created from a data matrix with
columns representing variable values.covariance
- Covariance instancepublic PearsonsCorrelation(RealMatrix covarianceMatrix, int numberOfObservations)
covarianceMatrix
- covariance matrixnumberOfObservations
- the number of observations in the dataset used to compute
the covariance matrixpublic RealMatrix getCorrelationMatrix()
public RealMatrix getCorrelationStandardErrors()
getCorrelationStandardErrors().getEntry(i,j)
is the standard
error associated with getCorrelationMatrix.getEntry(i,j)
The formula used to compute the standard error is
SEr = ((1 - r2) / (n - 2))1/2
where r
is the estimated
correlation coefficient and n
is the number of observations in the source dataset.
public RealMatrix getCorrelationPValues()
getCorrelationPValues().getEntry(i,j)
is the probability that a random variable distributed as
tn-2
takes a value with absolute value greater than or equal to
|r|((n - 2) / (1 - r2))1/2
The values in the matrix are sometimes referred to as the significance of the corresponding correlation coefficients.
MaxCountExceededException
- if an error occurs estimating probabilitiespublic RealMatrix computeCorrelationMatrix(RealMatrix matrix)
matrix
- matrix with columns representing variables to correlatepublic RealMatrix computeCorrelationMatrix(double[][] data)
data
- matrix with columns representing variables to correlatepublic double correlation(double[] xArray, double[] yArray)
xArray
- first data arrayyArray
- second data arrayDimensionMismatchException
- if the arrays lengths do not matchMathIllegalArgumentException
- if there is insufficient datapublic RealMatrix covarianceToCorrelation(RealMatrix covarianceMatrix)
Uses the formula
r(X,Y) = cov(X,Y)/s(X)s(Y)
where r(·,·)
is the correlation coefficient and
s(·)
means standard deviation.
covarianceMatrix
- the covariance matrixCopyright © 2019 CNES. All rights reserved.