public class PartialCovariances extends Object implements Serializable
Class PartialCovariances
computes the partial covariances or partial
correlations from an input covariance or correlation matrix.
If the "independent"
variables (the linear "effect" of the independent variables is removed in computing the
partial covariances/correlations) are linearly related to one another,
PartialCovariances
detects the linearity and eliminates one or more of
the independent variables from the list of independent variables. The number of
variables eliminated, if any, can be determined from
getPartialDegreesOfFreedom
.
Given a covariance or correlation matrix partitioned as
classPartialCovariances
computes the partial covariances (of the
standardized variables if is a correlation matrix) as
A positive semidefinite solver is used to compute
.
If partial correlations are desired, these are computed as
where denotes the matrix containing the diagonal of its argument along its diagonal with zeros off the diagonal. If is singular, then as many variables as required are deleted from (and ) in order to eliminate the linear dependencies. The computations then proceed as above.The pvalue for a partial covariance tests the null hypothesis
,
where
is the (i, j) element in matrix .
The pvalue for a partial correlation tests the null
hypothesis
,
where
is the (i, j) element in matrix .
The pvalues are returned by getPValues
.
If the degrees of freedom for sigma
, df
, is not known,
the resulting pvalues may be useful for comparison,
but they should not by used as an approximation to the actual probabilities.
Modifier and Type  Class and Description 

static class 
PartialCovariances.InvalidMatrixException
Exception thrown if a computed correlation is greater than one for some pair of variables.

static class 
PartialCovariances.InvalidPartialCorrelationException
Exception thrown if a computed partial correlation is greater than one for some pair of variables.

Constructor and Description 

PartialCovariances(int[] xIndices,
double[][] sigma,
int df)
Creates a
PartialCovariances object from a covariance or correleation matrix
with a mix of dependent and independent variables. 
PartialCovariances(int nIndependent,
double[][] sigma,
int df)
Creates a
PartialCovariances object from a covariance or correleation matrix
with a the independent variables in the initial columns and the dependent
variables in the final columns. 
Modifier and Type  Method and Description 

double[][] 
getPartialCorrelationMatrix()
Returns the partial correlation matrix.

double[][] 
getPartialCovarianceMatrix()
Returns the partial covariance matrix.

int 
getPartialDegreesOfFreedom()
Returns the degrees of freedom in the test that the
partial correlation (covariance) is zero.

double[][] 
getPValues()
Calculates the pvalues for testing the null hypothesis that the
associated partial covariance/correlation is zero.

public PartialCovariances(int[] xIndices, double[][] sigma, int df) throws PartialCovariances.InvalidMatrixException, PartialCovariances.InvalidPartialCorrelationException
PartialCovariances
object from a covariance or correleation matrix
with a mix of dependent and independent variables.xIndices
 is an array containing values indicating the status of
the variable.
If the ith entry is 0 then the ith column of the matrix contains a dependent variable.
If the ith entry is positive then the ith column of the matrix contains an independent variable.
If the ith entry is negative then the ith column of the matrix is not used in the analysis.sigma
 is a correlation or covariance matrix.
The number of rows and columns in sigma
must equal the length
of the array xIndices
.
The matrix must always be symmetric, positive semidefinite.df
 is an int
indicating the number of degrees of freedom
associated with the input matrix. If the number of degrees of freedom in
the matrix varies from element to element, then a conservative choice
for df
is the minimum degrees of freedom for all elements in the matrix.
The value of df
must be at least one.PartialCovariances.InvalidMatrixException
 is thrown if a computed correlation is greater than one for some pair of variables.PartialCovariances.InvalidPartialCorrelationException
 is thrown if a computed partial correlation is greater than one for some pair of variables.
The input matrix to the constructor was not positive semidefinite.public PartialCovariances(int nIndependent, double[][] sigma, int df) throws PartialCovariances.InvalidMatrixException, PartialCovariances.InvalidPartialCorrelationException
PartialCovariances
object from a covariance or correleation matrix
with a the independent variables in the initial columns and the dependent
variables in the final columns.nIndependent
 is the number of "independent" variables to be used in the partial
covariances/correlations. The partial covariances/correlations are the
covariances/correlations between the dependent variables after removing the
linear effect of the independent variables.sigma
 is a correlation or covariance matrix.
The rows/columns must be ordered such that the first nIndependent
rows/columns contain the independent variables, followed by the
row/columns containing the dependent variables.
The matrix must always be symmetric, positive semidefinite.df
 is an int
indicating the number of degrees of freedom
associated with the input matrix. If the number of degrees of freedom in
the matrix varies from element to element, then a conservative choice
for df
is the minimum degrees of freedom for all elements in the matrix.
The value of df
must be at least one.PartialCovariances.InvalidMatrixException
 is thrown if a computed correlation is greater than one for some pair of variables.PartialCovariances.InvalidPartialCorrelationException
 is thrown if a computed partial correlation is greater than one for some pair of variables.
The input matrix to the constructor was not positive semidefinite.public double[][] getPartialCorrelationMatrix()
public double[][] getPartialCovarianceMatrix()
public int getPartialDegreesOfFreedom()
df
minus the
rank of the the independent variables.
number of independent variables, but will be greater than
this value if the independent variables are computationally
linearly related.int
scalar value representing the degrees of
freedom. If this value is not greater than one then there are not
enough degrees of freedom for hypothesis testing.
A warning is also issued in this case.public double[][] getPValues()
sigma
was computed follows
a multivariate normal distribution and that each element in sigma
has df
degrees of freedom.double
containing the
pvalues.
The order of the matrix equals the number of dependent variables.
If the partial degrees of freedom is not greater than one then there are not enough degrees of freedom for hypothesis testing. The returned matrix will be set to all NaN values in this case. A warning is also issued in this case.
Copyright © 19702015 Rogue Wave Software
Built October 13 2015.