tab_ci {tabxplor}R Documentation

Add confidence intervals to a tab

Description

Add confidence intervals to a tab

Usage

tab_ci(
  tabs,
  ci = "auto",
  comp = NULL,
  conf_level = 0.95,
  color = "no",
  visible = FALSE,
  method_cell = "wilson",
  method_diff = "ac"
)

Arguments

tabs

A tibble of class tab made with tab_plain or tab_many.

ci

The type of ci to calculate. Set to "cell" to calculate absolute confidence intervals. Set to "diff" to calculate the confidence intervals of the difference between a cell and the relative total cell (or the reference cell, when diff is not "tot" in tab_plain or tab_num). By default, "diff" ci are calculated for means and row and col percentages, "cell" ci for frequencies ("all", "all_tabs").

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.

conf_level

The confidence level, as a single numeric between 0 and 1. Default to 0.95 (95%).

color

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

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

  • "diff_ci": color pct and means based on cells differences from totals or first cells, removing coloring when the confidence interval of this difference is higher than the difference itself

  • "after_ci": idem, but cut off the confidence interval from the difference

visible

By default confidence intervals are calculated and used to set colors, but not printed. Set to TRUE to print them in the result.

method_cell

Character string specifying which method to use with percentages for ci = "cell". This can be one out of: "wald", "wilson", "wilsoncc", "agresti-coull", "jeffreys", "modified wilson", "modified jeffreys", "clopper-pearson", "arcsine", "logit", "witting", "pratt", "midp", "lik" and "blaker". Defaults to "wilson". See BinomCI.

method_diff

Character string specifying which method to use with percentages for ci = "diff". This can be one out of: "wald", "waldcc", "ac", "score", "scorecc", "mn", "mee", "blj", "ha", "hal", "jp". Defaults to "ac", Wald interval with the adjustment according to Agresti, Caffo for difference in proportions and independent samples. See BinomDiffCI.

Value

A tibble of class tab, colored based on differences (from totals/first cells) and confidence intervals.

Examples

# A typical workflow with tabxplor step-by-step functions :

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"),
    pct = "row", comp = "all") %>%
    tab_ci("diff", color = "after_ci")
  

[Package tabxplor version 1.1.3 Index]