Learn R Programming

dentomedical (version 0.2.0)

sum_stat_p_strata: Summarize Variables with Optional Stratification and Statistical Tests

Description

Produces summary tables for numeric and categorical variables in a dataset, optionally stratified by a grouping variable. Numeric variables are summarized with mean (SD) or median (IQR), and categorical variables with counts and percentages. Appropriate statistical tests (t-test, Wilcoxon, ANOVA, Kruskal-Wallis, Chi-square, or Fisher's Exact) are performed depending on the variable type, number of groups, and user-specified options.

Usage

sum_stat_p_strata(
  data,
  by,
  strata = NULL,
  statistic = "mean_sd",
  test_type = "auto",
  paired = FALSE
)

Value

A flextable object containing the summary table with optional p-values, counts, percentages, and numeric summaries. Footnotes describe the statistics used and tests performed.

Arguments

data

A data frame containing the variables to summarize.

by

The main grouping variable for comparison.

strata

Optional stratification variable. Summaries are produced within each stratum.

statistic

Statistic to report for numeric variables: "mean_sd" (default) or "med_iqr".

test_type

Statistical test to use. Options: "auto" (default, selects appropriate test), "t.test", "wilcox", "anova", "kruskal", "fisher", or "chisq".

paired

Logical. If TRUE, paired t-tests are used when applicable (default: FALSE).

Examples

Run this code
# Example : Summary of CO2 dataset by Type, stratified by Treatment
sum_stat_p_strata(data = CO2, by = "Type", strata = "Treatment")

Run the code above in your browser using DataLab