Skip to content

Calculated whether 2x2 table is enriched for a particular group using Hypergeometric Distribution and the Fisher's Exact test for count data.

Usage

enrich_test(x, alternative = c("two.sided", "enrich", "deplete"))

Arguments

x

A \(2x2\) confusion matrix (or contingency table) containing the binary decisions for each contingency. Can also be a (named) list containing each of the 4 contingencies. See above.

alternative

character(1). Whether to check for "two.sided" (both Enrich/Deplete) or specifically one or the other ("enrich" or "deplete").

Value

Both the comparison to the Hypergeometric Distribution and The Fisher Exact Test for Count Data with confidence intervals

Details

Can also pass a named list containing:

n11

The corresponding [1, 1] position of the table/matrix.

n1_

The sum of the top row of the table.

n_1

The sum of the first column of the table.

n

The sum of the table.

Note

Similar result to Fisher Exact test

Author

Stu Field

Examples

c_mat <- matrix(c(4, 2, 3, 11), ncol = 2)
enrich_test(c_mat)
#> ── Counts Table ──────────────────────────────────────────────────────────
#>     yes no
#> yes   4  3
#> no    2 11
#> 
#> ── Tests ─────────────────────────────────────────────────────────────────
#> # A tibble: 6 × 4
#>   Test                `p-value` Preferred CI95            
#>   <chr>                   <dbl> <chr>     <chr>           
#> 1 1 sided                0.0777 ․         ․               
#> 2 2 sided double         0.155  ․         ․               
#> 3 1 sided mid            0.0424 ․         ․               
#> 4 2 sided double mid     0.0849 ․         ․               
#> 5 Fisher's Exact         0.122  ․         (0.601, 107.532)
#> 6 2 sided min lik mid    0.0867 ★         ․               
#> ══════════════════════════════════════════════════════════════════════════
en_list <- list(n11 = 4, n1_ = 7, n_1 = 6, n = 20)
enrich_test(en_list)
#> ── Counts Table ──────────────────────────────────────────────────────────
#>     yes no
#> yes   4  3
#> no    2 11
#> 
#> ── Tests ─────────────────────────────────────────────────────────────────
#> # A tibble: 6 × 4
#>   Test                `p-value` Preferred CI95            
#>   <chr>                   <dbl> <chr>     <chr>           
#> 1 1 sided                0.0777 ․         ․               
#> 2 2 sided double         0.155  ․         ․               
#> 3 1 sided mid            0.0424 ․         ․               
#> 4 2 sided double mid     0.0849 ․         ․               
#> 5 Fisher's Exact         0.122  ․         (0.601, 107.532)
#> 6 2 sided min lik mid    0.0867 ★         ․               
#> ══════════════════════════════════════════════════════════════════════════