Creates comprehensive tables for categorical or continuous variables with formatting, statistical tests, prevalence ratios (PR), odds ratios (OR), and column stratification.
Usage
tb(
data,
...,
m = FALSE,
d = 1,
format = TRUE,
style = "n_pct",
style.rp = "{rp} ({lower} - {upper})",
style.or = "{or} ({lower} - {upper})",
test = FALSE,
subset = NULL,
strat = NULL,
rp = FALSE,
or = FALSE,
ref = NULL,
conf.level = 0.95,
var.type = NULL,
stat.cont = "median"
)Arguments
- data
A data.frame or atomic vector.
- ...
Variables to be tabulated. Accepts variable names and/or flags (
m,p,row,col,rp,or) for controlling output format.- m
Logical. Include missing values (NA) in the table. Default:
FALSE.- d
Integer. Decimal places for percentages and statistics. Default:
1.- format
Logical. Render a formatted grid output. Default:
TRUE.- style
Character. Format for displaying counts and percentages. Options:
"n_pct"(default),"pct_n", or a custom template with{n}and{p}placeholders, e.g."{n} [{p}%]".- style.rp
Character. Format string for Prevalence Ratio. Default:
"{rp} ({lower} - {upper})".- style.or
Character. Format string for Odds Ratio. Default:
"{or} ({lower} - {upper})".- test
Logical or Character. Performs statistical test on 2x2+ tables.
TRUEfor automatic selection, or one of"chisq","fisher","mcnemar".- subset
Logical expression for row filtering.
- strat
Variable for column stratification. Disables PR/OR calculations.
- rp
Logical. Calculate Prevalence Ratios (PR). Default:
FALSE.- or
Logical. Calculate Odds Ratios (OR). Default:
FALSE.- ref
Character or numeric. Reference level for PR/OR calculations.
- conf.level
Numeric. Confidence level for intervals (0–1). Default:
0.95.- var.type
Named character vector specifying variable types, e.g.
c(age = "continuous").- stat.cont
Character.
"mean"(Mean/SD) or"median"(Median/IQR). Default:"median".