get_expected_counts {MDDC}R 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)


[Package MDDC version 1.1.0 Index]