This function calculates the between-group scatter matrix (SB) for a given numeric matrix and grouping variable.
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.
Value
A numeric matrix representing the between-group scatter matrix (SB).
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.
Examples
# Example usage:
A <- matrix(rnorm(20), nrow = 5, ncol = 4)
g <- factor(c("A", "B", "A", "B", "A"))
SB <- rENA:::compute_SB(A, g)