get_expected_counts: Compute the Expected Count Matrix from a Contingency Table

View source: R/RcppExports.R

get_expected_countsR Documentation

Compute the Expected Count Matrix from a Contingency Table

Description

This function computes the expected counts matrix E_{ij} from a given I \times J contingency table using the formula:

E_{ij} = \frac{n_{i.} n_{.j}}{n_{..}}

where n_{i.} is the sum of the i-th row, n_{.j} is the sum of the j-th column, and n_{..} is the total sum of the table.

Usage

get_expected_counts(continTable)

Arguments

continTable

A numeric matrix representing the I \times J contingency table.

Value

A numeric matrix of the same dimension as continTable, containing the expected counts for each cell (i, j) of the contingency table. The expected counts are based on the row and column marginal sums of the contingency table.

Examples

# Create a 6 by 4 contingency table
set.seed(42)
dat_mat <- matrix(rpois(6*4, 20), nrow=6)
dat_mat

# Assign row and column names
contin_table <- check_and_fix_contin_table(dat_mat)
contin_table

# Compute the expected counts of the contingency table
get_expected_counts(contin_table)


MDDC documentation built on April 11, 2025, 5:45 p.m.