Calculation of within (matW
) and between (matB
) covariance matrices for classes of observations.
matW(X, y)matB(X, y)
For (matW
):
within covariance matrix.
list of covariance matrices for each class.
classes
number of observations in each per class
For (matB
):
between covariance matrix.
matrix of class centers.
classes
number of observations in each per class
Data (
Class membership (
The denominator in the variance calculations is
n <- 8 ; p <- 3
X <- matrix(rnorm(n * p), ncol = p)
y <- sample(1:2, size = n, replace = TRUE)
X
y
matW(X, y)
matB(X, y)
matW(X, y)$W + matB(X, y)$B
(n - 1) / n * cov(X)
Run the code above in your browser using DataLab