...
 
Commits (2)
......@@ -9,6 +9,7 @@ export(spd.logmap)
export(spd.expmap)
export(spddot)
export(spd.whiten)
export(spd.correlation)
importFrom(expm,expm)
importFrom(expm,logm)
......
#' Compute (partial) correlations
#'
#' Transforms an SPD matrix into a matrix of partial correlations
#'
#' @param x An SPD matrix to be whitened
#' @param method A string specifying either "correlation" (default) orf
#' "partial" correlation.
#' @return A symmetric, positive-definite matrix.
spd.correlation <- function(x, method = 'correlation'){
if (!'spd.mat' %in% input.type(x)){
stop('x must be a positive definite matrix')
}
# Correlation matrix
s <- diag(1/sqrt(diag(x)))
x <- s %*% x %*% s
if (method == 'correlation'){
return(x)
} else if (method == 'partial'){
x.inv <- solve(x)
sc <- diag(x.inv) %o% diag(x.inv)
return(x.inv / sqrt(sc))
} else {
stop('Unrecognized method')
}
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spd-correlation.R
\name{spd.correlation}
\alias{spd.correlation}
\title{Compute (partial) correlations}
\usage{
spd.correlation(x, method = "correlation")
}
\arguments{
\item{x}{An SPD matrix to be whitened}
\item{method}{A string specifying either "correlation" (default) orf
"partial" correlation.}
}
\value{
A symmetric, positive-definite matrix.
}
\description{
Transforms an SPD matrix into a matrix of partial correlations
}