freq_test: Hypothesis Testing For Frequency Tables

Description Usage Arguments Value Examples

View source: R/freq_test.R

Description

The freq_test function is an S3 generic. It currently has methods for conducting hypothesis tests on one-way and two-way frequency tables. Further, it is made to work in a dplyr pipeline with the freq_table function.

Usage

1
2
3
4
5
6
7
freq_test(x, ...)

## S3 method for class 'freq_table_one_way'
freq_test(x, ...)

## S3 method for class 'freq_table_two_way'
freq_test(x, method = "pearson", ...)

Arguments

x

A tibble of class freq_table_one_way or freq_table_two_way.

...

Other parameters to be passed on.

method

Options for this parameter control the method used to calculate p-values.

For the freq_table_two_way class, the options are "pearson" (default) - to use Pearson's chi-square test of independence, and "fisher" - to use Fisher's exact test.

Value

A tibble.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(tidyverse)
library(bfuncs)

data(mtcars)

# Test equality of proportions

mtcars %>%
  group_by(am) %>%
  freq_table() %>%
  freq_test() %>%
  select(var:percent, p_chi2_pearson)

#>  # A tibble: 2 x 6
#>      var   cat     n n_total percent p_chi2_pearson
#>    <chr> <dbl> <int>   <int>   <dbl>          <dbl>
#>  1    am     0    19      32   59.38      0.2888444
#>  2    am     1    13      32   40.62      0.2888444

# Chi-square test of independence

mtcars %>%
  group_by(am, vs) %>%
  freq_table() %>%
  freq_test() %>%
  select(row_var:n, percent_row, p_chi2_pearson)

#> # A tibble: 4 x 7
#>   row_var row_cat col_var col_cat     n percent_row p_chi2_pearson
#>     <chr>   <dbl>   <chr>   <dbl> <int>       <dbl>          <dbl>
#> 1      am       0      vs       0    12       63.16      0.3409429
#> 2      am       0      vs       1     7       36.84      0.3409429
#> 3      am       1      vs       0     6       46.15      0.3409429
#> 4      am       1      vs       1     7       53.85      0.3409429

brad-cannell/bfuncs documentation built on July 21, 2019, 10:45 a.m.