R/tr.R

Defines functions tr

Documented in tr

#' Matrix trace
#' 
#' Calculates the trace of a matrix
#' 
#' For square, symmetric matrices, such as covariance matrices, the trace is sometimes
#' used as a measure of size, e.g., in Pillai's trace criterion for a MLM.
#' 
#' 
#' @param M a matrix
#' @return returns the sum of the diagonal elements of the matrix
#' @author Michael Friendly
#' @keywords array
#' @examples
#' 
#' M <- matrix(sample(1:9), 3,3)
#' tr(M)
#' 
#' @export
tr <- function(M) sum(diag(M))

Try the mvinfluence package in your browser

Any scripts or data that you put into this service are public.

mvinfluence documentation built on Sept. 21, 2022, 9:09 a.m.