get_expected_counts | R Documentation |
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.
get_expected_counts(continTable)
continTable |
A numeric matrix representing the |
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.