Learn R Programming

rchemo (version 0.1-3)

matW: Between and within covariance matrices

Description

Calculation of within (matW) and between (matB) covariance matrices for classes of observations.

Usage

matW(X, y)

matB(X, y)

Value

For (matW):

W

within covariance matrix.

Wi

list of covariance matrices for each class.

lev

classes

ni

number of observations in each per class

For (matB):

B

between covariance matrix.

ct

matrix of class centers.

lev

classes

ni

number of observations in each per class

Arguments

X

Data (\(n, p\)) on whch are calculated the covariances.

y

Class membership (\(n, 1\)).

Details

The denominator in the variance calculations is \(n\).

Examples

Run this code

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