Skip to contents

Helper functions to implement various tests on the difference between two proportions.

Usage

prop_chisq(tbl)

prop_cmh(ary)

prop_schouten(tbl)

prop_fisher(tbl)

Arguments

tbl

(matrix)
matrix with two groups in rows and the binary response (TRUE/FALSE) in columns.

ary

(array, 3 dimensions)
array with two groups in rows, the binary response (TRUE/FALSE) in columns, and the strata in the third dimension.

Functions

  • prop_chisq(): performs Chi-Squared test. Internally calls stats::prop.test().

  • prop_cmh(): performs stratified Cochran-Mantel-Haenszel test. Internally calls stats::mantelhaen.test(). Note that strata with less than two observations are automatically discarded.

  • prop_schouten(): performs the Chi-Squared test with Schouten correction.

  • prop_fisher(): performs the Fisher's exact test. Internally calls stats::fisher.test().

See also

[prop_diff_test())] for implementation of these helper functions.

[prop_diff_test())]: R:prop_diff_test())

For information on the Schouten correction (Schouten, 1980), visit https://onlinelibrary.wiley.com/doi/abs/10.1002/bimj.4710220305.

Examples

# Non-stratified proportion difference test

## Data
A <- 20
B <- 20
set.seed(1)
rsp <- c(
  sample(c(TRUE, FALSE), size = A, prob = c(3 / 4, 1 / 4), replace = TRUE),
  sample(c(TRUE, FALSE), size = A, prob = c(1 / 2, 1 / 2), replace = TRUE)
)
grp <- c(rep("A", A), rep("B", B))
tbl <- table(grp, rsp)

## Chi-Squared test
# Internal function - prop_chisq
if (FALSE) {
prop_chisq(tbl)
}

# Stratified proportion difference test

## Data
rsp <- sample(c(TRUE, FALSE), 100, TRUE)
grp <- factor(rep(c("A", "B"), each = 50))
strata <- factor(rep(c("V", "W", "X", "Y", "Z"), each = 20))
tbl <- table(grp, rsp, strata)

## Cochran-Mantel-Haenszel test
# Internal function - prop_cmh
if (FALSE) {
prop_cmh(tbl)
}

## Chi-Squared test + Schouten correction.
# Internal function - prop_schouten
if (FALSE) {
prop_schouten(tbl)
}

## Fisher's exact test
# Internal function - prop_fisher
if (FALSE) {
prop_fisher(tbl)
}