Performs statistical testing for differential expression using results from a fitted devil model. Supports both standard and robust (clustered) variance estimation, with multiple testing correction and customizable fold change thresholds.
test_de(
devil.fit,
contrast,
pval_adjust_method = "BH",
max_lfc = 10,
clusters = NULL,
parallel.cores = NULL
)
A fitted model object from fit_devil(). Must contain beta coefficients, design matrix, and overdispersion parameters.
Numeric vector or matrix specifying the comparison of interest. Length must match number of coefficients in the model. For example, c(0, 1, -1) tests difference between second and third coefficient.
Character. Method for p-value adjustment. Passed to stats::p.adjust(). Common choices:
"BH": Benjamini-Hochberg (default)
"bonferroni": Bonferroni correction
"holm": Holm's step-down method
Numeric. Maximum absolute log2 fold change to report. Larger values are capped at ±max_lfc. Default: 10
Numeric vector or factor. Sample cluster assignments for robust variance estimation. Length must match number of samples. Default: NULL
Integer or NULL. Number of CPU cores for parallel processing. If NULL, uses all available cores. Default: NULL
A tibble with columns:
Character. Gene identifiers from input data
Numeric. Raw p-values from statistical tests
Numeric. Adjusted p-values after multiple testing correction
Numeric. Log2 fold changes, capped at ±max_lfc
The function implements the following analysis pipeline:
Calculates log fold changes using contrast vectors/matrices
Computes test statistics using either standard or robust variance estimation
Calculates p-values using t-distribution with appropriate degrees of freedom
Adjusts p-values for multiple testing
Applies fold change thresholding
The variance estimation can account for sample clustering (e.g., multiple samples from the same patient) using a sandwich estimator for robust inference.