epi_stats_contingency_nxn: Generate a Wide-Format Summary Table for Multiple Variables

View source: R/epi_stats_contigency_nxn.R

epi_stats_contingency_nxnR Documentation

Generate a Wide-Format Summary Table for Multiple Variables

Description

This function creates a summary table for a dependent variable and one or more independent variables. It calculates frequencies, reshapes the data into a wide format, and adds totals and percentages dynamically.

Usage

epi_stats_contingency_nxn(df, dep_var, ind_vars)

Arguments

df

A data frame containing the data to analyze.

dep_var

A string specifying the dependent variable (column in df).

ind_vars

A character vector specifying the independent variable(s) (columns in df).

Value

A data frame summarizing the relationships between the dependent variable and the independent variable(s).

Examples

# Example dataset
set.seed(42)
test_data <- data.frame(
  Outcome = sample(c("Yes", "No"), 100, replace = TRUE),
  Group = sample(c("A", "B", "C"), 100, replace = TRUE),
  Gender = sample(c("Male", "Female"), 100, replace = TRUE)
)

# Generate a summary table
result <- epi_stats_contingency_nxn(test_data, dep_var = "Outcome", ind_vars = c("Group", "Gender"))
print(result)


AntonioJBT/episcout documentation built on Feb. 20, 2025, 12:46 a.m.