Learn R Programming

rENA (version 0.3.0)

compute_SB: 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)

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.

Examples

Run this code
# Example usage:
A <- matrix(rnorm(20), nrow = 5, ncol = 4)
g <- factor(c("A", "B", "A", "B", "A"))
SB <- rENA:::compute_SB(A, g)

Run the code above in your browser using DataLab