Skip to contents

Create a frequency table with chi-square statistic, p-value, cramer's v.

Usage

stat_two_cat(df, grp_var, vars, filter = "")

Arguments

df

A single data.frame

grp_var

A character variable from a data.frame

vars

One or more variables from a data.frame

filter

A character single value (default = ”), that will be the value to filter the variables

Value

A gt table.

Examples



mtcars %>%
 dplyr::mutate(vs = paste0("vs = ",vs)) %>%
 stat_two_cat(grp_var = vs,vars = c(am,cyl))
#> Warning: Supplying `...` without names was deprecated in tidyr 1.0.0.
#>  Please specify a name for each selection.
#>  Did you want `data = -name`?
#>  The deprecated feature was likely used in the relper package.
#>   Please report the issue to the authors.
#> Warning: There were 2 warnings in `dplyr::mutate()`.
#> The first warning was:
#>  In argument: `chi_square = purrr::map(.x = data, .f =
#>   ~stats::chisq.test(.$grp_var, .$value))`.
#> Caused by warning in `stats::chisq.test()`:
#> ! Chi-squared approximation may be incorrect
#>  Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
#> Warning: There was 1 warning in `dplyr::mutate()`.
#>  In argument: `dplyr::across(.fns = ~dplyr::if_else(is.na(.), "-",
#>   as.character(.)))`.
#> Caused by warning:
#> ! Using `across()` without supplying `.cols` was deprecated in dplyr 1.1.0.
#>  Please supply `.cols` instead.
Levels vs = 0 vs = 1 Statistic P-value Cramer's V
am - - - 0.3475 0.5555 0.1042
0 66.67% (12/18) 50.00% (7/14) - - -
1 33.33% (6/18) 50.00% (7/14) - - -
cyl - - - 21.3399 <0.001 0.8166
4 5.56% (1/18) 71.43% (10/14) - - -
6 16.67% (3/18) 28.57% (4/14) - - -
8 77.78% (14/18) - - - -