Learn R Programming

dentomedical (version 0.2.0)

sum_posthoc: Summarize Variables with Post-hoc Tests: Mutiple comparisons

Description

Produces a summary table of numeric or categorical variables grouped by a factor, optionally performing global tests (ANOVA or Kruskal-Wallis) and post-hoc comparisons (Tukey or Dunn test). Numeric variables can be summarized using mean (SD) or median (IQR). Returns a flextable suitable for reporting.

Usage

sum_posthoc(
  data,
  by,
  variables = NULL,
  digits = 2,
  format_lt = "

Value

A flextable containing the summary table, global p-values, and post-hoc results.

Arguments

data

A data frame containing the variables to summarize.

by

The grouping variable for comparisons (factor or character).

variables

A character vector of variable names to summarize. If NULL, all variables except by are used.

digits

Number of decimal places for numeric summaries (default: 2).

format_lt

Character string to display very small p-values, e.g., "<0.001" (default: "<0.001").

na.rm

Logical. If TRUE, removes missing values before computations (default: TRUE).

statistic

Summary statistic for numeric variables. Options: "auto" (default), "mean_sd", "med_iqr".

test_type

Global test type. Options: "auto" (default), "anova", "kruskal".

Examples

Run this code
sum_posthoc(
  data = iris,
  by = "Species",
  variables = c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width"),
  digits = 2,
  statistic = "auto",
  test_type = "auto"
)

Run the code above in your browser using DataLab