Learn R Programming

biotools (version 3.1)

cov2pcov: Partial Covariance Matrix

Description

Compute a matrix of partial (co)variances for a group of variables with respect to another.

Take \(\Sigma\) as the covariance matrix of dimension p. Now consider dividing \(\Sigma\) into two groups of variables. The partial covariance matrices are calculate by: $$ \Sigma_{11.2} = \Sigma_{11} - \Sigma_{12} \Sigma_{22}^{-1} \Sigma_{21} $$ $$ \Sigma_{22.1} = \Sigma_{22} - \Sigma_{21} \Sigma_{11}^{-1} \Sigma_{12} $$

Usage

cov2pcov(m, vars1, vars2 = seq(1, ncol(m))[-vars1])

Arguments

m

a square numeric matrix.

vars1

a numeric vector indicating the position (rows or columns in m) of the set of variables at which to compute the partial covariance matrix.

vars2

a numeric vector indicating the position (rows or columns in m) of the set of variables at which to adjust the partial covariance matrix.

Value

A square numeric matrix.

See Also

cov

Examples

Run this code
# NOT RUN {
(Cl <- cov(longley))
cov2pcov(Cl, 1:2)

# End (Not run)
# }

Run the code above in your browser using DataLab