Either Barnard, Fisher's, or Chi-sq test performed for unpaired data and McNemar's test for paired data

two_samp_bin_test(x, y, method = NA, alternative = c("two.sided",
  "less", "greater"), verbose = FALSE)

Arguments

x

vector with only 2 levels (can include NA values).

y

vector with only 2 levels (can include NA values unless method = 'mcnemar').

method

what test to run ("barnard", "fisher" ,"chi.sq" , "mcnemar"). No default so user must enter one of the four selections

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter. Only "two.sided" available for method = 'chi.sq' or 'mcnemar'

verbose

a logical variable indicating if warnings and messages should be displayed.

...

parameters to pass to wilcox_test or t.test functions. For example the testing direction (alternative) in either call or the var.equal in the t.test function.

Value

p-value for comparing x at the different levels of y.

Details

For one sided tests if y is a factor variable the level order is respected, otherwise the levels will set to alphabetical order (i.e. if alternative = less then testing a < b ).

If method = 'mcnemar' assumes the first observations of the first group matches the first observation of the second group, and so on. Also if method = 'mcnemar' then y must have the same number of samples for each level.

Examples

set.seed(5432322) x <- c(sample(0:1,10,replace = TRUE, prob = c(.75,.25)), sample(0:1,10,replace = TRUE, prob = c(.25,.75))) y <- c(rep('a', 10), rep('b', 10)) two_samp_bin_test(x,y, method = 'barnard')
#> [1] 0.02709198
two_samp_bin_test(x,y, 'fisher')
#> [1] 0.05727554
two_samp_bin_test(x,y, 'chi.sq')
#> Warning: Chi-squared approximation may be incorrect
#> [1] 0.06076124
two_samp_bin_test(x,y, 'mcnemar')
#> [1] 0.07363827