matW: Between and within covariance matrices

View source: R/matW.R

matWR Documentation

Between and within covariance matrices

Description

Calculation of within (matW) and between (matB) covariance matrices for classes of row observations of a data set.

Usage


matW(X, y)

matB(X, y)

Arguments

X

A n x p matrix or data frame.

y

A vector of length n defining the class membership of the observations.

Details

The denominator in the variance calculations is n.

Value

A matrix.

Examples


n <- 8
p <- 3
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10, sd = 3), ncol = p, byrow = TRUE)
y <- sample(1:2, size = n, replace = TRUE)
set.seed(NULL)
X
y

matW(X, y)

matB(X, y)
  
matB(X, y)$B

matW(X, y)$W + matB(X, y)$B
(n - 1) / n * cov(X)


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.