Learn R Programming

tabxplor (version 1.1.0)

tab_chi2: Add Chi2 summaries to a tab

Description

Add Chi2 summaries to a tab

Usage

tab_chi2(
  tabs,
  calc = c("ctr", "p", "var", "counts"),
  comp = NULL,
  color = c("no", "auto", "all", "all_pct")
)

Arguments

tabs

A tibble of class tab, made with tab_plain or tab_many.

calc

By default all elements of the Chi2 summary are calculated : contributions to variance, pvalue, variance and unweighted count. You can choose which are computed by selecting elements in the vector c("ctr", "p", "var", "counts").

comp

Comparison level. When tab_vars are present, should the contributions to variance be calculated for each subtable/group (by default, comp = "tab") ? Should they be calculated for the whole table (comp = "all") ? comp must be set once and for all the first time you use tab_plain, tab_num or tab_chi2 with rows, or tab_ci.

color

The type of colors to print, as a single string.

  • "no": by default, no colors are printed

  • "all": color all cells based on their contribution to variance (except for mean columns, from numeric variables)

  • "all_pct": color all percentages cells based on their contribution to variance

  • "auto": only color columns with counts, pct = "all" or pct = "all_tabs"

Value

A tibble of class tab, with Chi2 summaries as metadata, possibly colored based on contributions of cells to variance.

Examples

Run this code
# NOT RUN {
# A typical workflow with tabxplor step-by-step functions :
# }
# NOT RUN {
data <- dplyr::starwars %>%
  tab_prepare(sex, hair_color, gender, rare_to_other = TRUE,
              n_min = 5, na_drop_all = sex)

data %>%
  tab_plain(sex, hair_color, gender, tot = c("row", "col")) %>%
  tab_chi2(calc = c("p", "ctr"), color = TRUE)
  
# }

Run the code above in your browser using DataLab