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.
To compute the correlation coefficient for a single pair of arrays, use PearsonsCorrelation()
to construct an instance with no data and then correlation(double[], double[]).
Correlation matrices can also be computed directly from an instance with no data using
computeCorrelationMatrix(double[][]). In order to use getCorrelationMatrix(),
getCorrelationPValues(), or getCorrelationStandardErrors(); however, one of the
constructors supplying data or a covariance matrix must be used to create the instance.
| Modifier and Type | Field and Description |
|---|---|
| private final RealMatrix | correlationMatrix
correlation matrix |
| private final int | nObs
number of observations |
| Access | Constructor and Description |
|---|---|
| public | |
| public | PearsonsCorrelation(double[][]
rectangular array with columns representing variables data)Create a PearsonsCorrelation from a rectangular array whose columns represent values of variables to be correlated. |
| public | PearsonsCorrelation(RealMatrix
matrix with columns representing variables to correlate matrix)Create a PearsonsCorrelation from a RealMatrix whose columns represent variables to be correlated. |
| public | PearsonsCorrelation(Covariance
Covariance instance covariance)Create a PearsonsCorrelation from a |
| public | PearsonsCorrelation(RealMatrix
covariance matrix covarianceMatrix, int the number of observations in the dataset used to compute
the covariance matrix numberOfObservations)Create a PearsonsCorrelation from a covariance matrix. |
| Modifier and Type | Method and Description |
|---|---|
| private void | checkSufficientData(final RealMatrix
matrix to check for sufficiency matrix)Throws MathIllegalArgumentException if the matrix does not have at least two columns and two rows. |
| public RealMatrix | Returns: correlation matrixmatrix with columns representing variables to correlate matrix)Computes the correlation matrix for the columns of the
input matrix, using |
| public RealMatrix | Returns: correlation matrixmatrix with columns representing variables to correlate data)Computes the correlation matrix for the columns of the input rectangular array. |
| public double | Returns: Returns Pearson's correlation coefficient for the two arraysfirst data array xArray, final double[] second data array yArray)Computes the Pearson's product-moment correlation coefficient between two arrays. |
| public RealMatrix | Returns: correlation matrixthe covariance matrix covarianceMatrix)Derives a correlation matrix from a covariance matrix. |
| public RealMatrix | |
| public RealMatrix | Returns: matrix of p-valuesReturns a matrix of p-values associated with the (two-sided) null hypothesis that the corresponding correlation coefficient is zero. |
| public RealMatrix | Returns: matrix of correlation standard errorsReturns a matrix of standard errors associated with the estimates in the correlation matrix. |
| correlationMatrix | back to summary |
|---|---|
| private final RealMatrix correlationMatrix correlation matrix | |
| nObs | back to summary |
|---|---|
| private final int nObs number of observations | |
| PearsonsCorrelation | back to summary |
|---|---|
| public PearsonsCorrelation() Create a PearsonsCorrelation instance without data. | |
| PearsonsCorrelation | back to summary |
|---|---|
| public PearsonsCorrelation(double[][] data) Create a PearsonsCorrelation from a rectangular array whose columns represent values of variables to be correlated. Throws MathIllegalArgumentException if the input array does not have at least two columns and two rows. Pairwise correlations are set to NaN if one of the correlates has zero variance.
| |
| PearsonsCorrelation | back to summary |
|---|---|
| public PearsonsCorrelation(RealMatrix matrix) Create a PearsonsCorrelation from a RealMatrix whose columns represent variables to be correlated. Throws MathIllegalArgumentException if the matrix does not have at least two columns and two rows. Pairwise correlations are set to NaN if one of the correlates has zero variance.
| |
| PearsonsCorrelation | back to summary |
|---|---|
| public PearsonsCorrelation(Covariance covariance) Create a PearsonsCorrelation from a
| |
| PearsonsCorrelation | back to summary |
|---|---|
| public PearsonsCorrelation(RealMatrix covarianceMatrix, int numberOfObservations) Create a PearsonsCorrelation from a covariance matrix. The correlation matrix is computed by scaling the covariance matrix.
| |
| checkSufficientData | back to summary |
|---|---|
| private void checkSufficientData(final RealMatrix matrix) Throws MathIllegalArgumentException if the matrix does not have at least two columns and two rows.
| |
| computeCorrelationMatrix | back to summary |
|---|---|
| public RealMatrix computeCorrelationMatrix(RealMatrix matrix) Computes the correlation matrix for the columns of the
input matrix, using
| |
| computeCorrelationMatrix | back to summary |
|---|---|
| public RealMatrix computeCorrelationMatrix(double[][] data) Computes the correlation matrix for the columns of the input rectangular array. The columns of the array represent values of variables to be correlated. Throws MathIllegalArgumentException if the matrix does not have at least two columns and two rows or if the array is not rectangular. Pairwise correlations are set to NaN if one of the correlates has zero variance.
| |
| correlation | back to summary |
|---|---|
| public double correlation(final double[] xArray, final double[] yArray) Computes the Pearson's product-moment correlation coefficient between two arrays. Throws MathIllegalArgumentException if the arrays do not have the same length
or their common length is less than 2. Returns
| |
| covarianceToCorrelation | back to summary |
|---|---|
| public RealMatrix covarianceToCorrelation(RealMatrix covarianceMatrix) Derives a correlation matrix from a covariance matrix. Uses the formula
| |
| getCorrelationMatrix | back to summary |
|---|---|
| public RealMatrix getCorrelationMatrix() Returns the correlation matrix. This method will return null if the argumentless constructor was used
to create this instance, even if
| |
| getCorrelationPValues | back to summary |
|---|---|
| public RealMatrix getCorrelationPValues() Returns a matrix of p-values associated with the (two-sided) null hypothesis that the corresponding correlation coefficient is zero.
The values in the matrix are sometimes referred to as the significance of the corresponding correlation coefficients. To use this method, one of the constructors that supply an input matrix must have been used to create this instance.
| |
| getCorrelationStandardErrors | back to summary |
|---|---|
| public RealMatrix getCorrelationStandardErrors() Returns a matrix of standard errors associated with the estimates
in the correlation matrix. The formula used to compute the standard error is To use this method, one of the constructors that supply an input matrix must have been used to create this instance.
| |