two_samp_bin_test: Binary (Response) Variable Compared to Binary (Group)...

Description Usage Arguments Details Value Examples

View source: R/statistical_tests_and_estimates.R

Description

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

Usage

1
2
3
4
5
6
7
8
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.

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.

Value

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

Examples

1
2
3
4
5
6
7
8
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')
two_samp_bin_test(x,y, 'fisher')
two_samp_bin_test(x,y, 'chi.sq')
two_samp_bin_test(x,y, 'mcnemar')

z2thet/MoffittFunctions documentation built on July 17, 2021, 9:51 a.m.