Learn R Programming

CytoProfile (version 0.2.4)

cyt_univariate: Pairwise Univariate Tests Between Two Groups

Description

cyt_univariate supports additional scaling options and explicit choice of statistical test. For each categorical predictor with exactly two levels and each numeric outcome, a two‑sample t‑test or Wilcoxon rank–sum test is performed. Results are returned either as a list of test objects or, if format_output = TRUE, as a tidy data frame with one row per comparison.

Usage

cyt_univariate(
  data,
  scale = NULL,
  method = c("auto", "ttest", "wilcox"),
  verbose = TRUE,
  format_output = FALSE,
  custom_fn = NULL,
  p_adjust_method = NULL
)

Value

If format_output = FALSE, a named list of test objects keyed by "Outcome_Categorical". If format_output = TRUE, a data frame with columns Outcome, Categorical, Comparison, Test, Estimate, Statistic, and P_value.

Arguments

data

A data frame or matrix containing both categorical and numeric variables.

scale

A character specifying a transformation to apply to numeric variables prior to testing. Choices are NULL (no transformation), "log2", "log10", "zscore", or "custom". When set to "custom", supply a function via custom_fn.

method

Character specifying the test to perform. Use "auto" (default) to select between t‑test and Wilcoxon based on Shapiro–Wilk normality tests for each outcome; "ttest" to always use Student’s t‑test; or "wilcox" to always use the Wilcoxon rank–sum test.

verbose

Logical indicating whether to return the results. Provided for backward compatibility but has no effect on printing.

format_output

Logical. If TRUE, returns the results as a tidy data frame; if FALSE (default), returns a list of test objects similar to the original function.

custom_fn

A function to apply when scale = "custom".

p_adjust_method

Character or NULL. Method passed to p.adjust() for correcting p-values across all comparisons (e.g., "BH" for Benjamini-Hochberg). If NULL (default) no adjustment is performed.

Author

Shubh Saraswat

Examples

Run this code
data_df <- ExampleData1[, -c(3)]
data_df <- dplyr::filter(data_df, Group != "ND", Treatment != "Unstimulated")
cyt_univariate(data_df[, c(1:2, 5:6)], scale = "log2",
               method = "auto", format_output = TRUE)

Run the code above in your browser using DataLab