This function calculates the between-group scatter matrix (SB) for a given numeric matrix and grouping variable.
Usage
compute_SB(A, g)
Value
A numeric matrix representing the between-group scatter matrix (SB).
Arguments
A
A numeric matrix of dimensions m x n, where rows represent observations and columns represent features.
g
A grouping variable of length m, either a factor or a character vector, indicating group membership for each observation.
Details
The function computes the total mean of the matrix A and the mean for each group defined by g.
It then calculates the between-group scatter matrix by summing the outer product of the mean differences, weighted by the group sizes.