compute_SB: Compute Between-Group Scatter Matrix

View source: R/gmr.R

compute_SBR Documentation

Compute Between-Group Scatter Matrix

Description

This function calculates the between-group scatter matrix (SB) for a given numeric matrix and grouping variable.

Usage

compute_SB(A, g)

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.

Value

A numeric matrix representing the between-group scatter matrix (SB).

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)

rENA documentation built on Nov. 5, 2025, 5:50 p.m.