| Title: | Differential Analysis of Omics Data Based on the Tweedie Distribution |
|---|---|
| Description: | A toolkit for differential analysis of omics data. Implements a CPLM-based statistical workflow built on the Tweedie distribution. Unlike traditional single-omics tools, Tweedieverse is technology-agnostic and can be applied to both count and continuous measurements arising from diverse high-throughput technologies (e.g. transcript abundances from bulk and single-cell RNA-Seq studies in the form of UMI counts or non-UMI counts, microbiome taxonomic and functional profiles in the form of counts or relative abundances, and compound abundance levels or peak intensities from metabolomics and other mass spectrometry-based experiments, among others). The software includes multiple customization options such as the inclusion of random effects and multiple covariates along with several data exploration capabilities and visualization modules in a unified estimation umbrella. |
| Authors: | Nalin Arora [aut, cre] (ORCID: <https://orcid.org/0009-0009-1340-688X>), Ziyu Liu [ctb], Ali Rahnavard [ctb, cph] (ORCID: <https://orcid.org/0000-0002-9710-0248>), Himel Mallick [aut, cph] (ORCID: <https://orcid.org/0000-0003-4956-2429>), William Nickols [ctb] (MaAsLin 3 median-comparison code), Jacob Nearing [ctb] (MaAsLin 3 median-comparison code), Harvard School of Public Health [cph] (MaAsLin 3 components) |
| Maintainer: | Nalin Arora <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.99.2 |
| Built: | 2026-12-04 21:55:24 UTC |
| Source: | https://github.com/bioc/Tweedieverse |
Adjust Tweedieverse(or any other differential analysis methods) coefficient estimates and p-values by testing each taxon against the *median* effect for the same metadata variable - a simple post-hoc strategy to curb false discoveries driven by the compositional nature of microbiome count data (after the approach adopted in **MaAsLin 3**).
median_comparison_tweedie( df, p_cutoff = 0.95, subtract_median = FALSE, n_sims = 10000, median_threshold = 0, seed = NULL )median_comparison_tweedie( df, p_cutoff = 0.95, subtract_median = FALSE, n_sims = 10000, median_threshold = 0, seed = NULL )
df |
A 'data.frame' returned by **Tweedieverse** or any other differential analysis methods containing (at minimum) the columns 'taxon', 'metadata', 'effect_size', 'pval', 'stderr', and 'qval'. |
p_cutoff |
Numeric. Upper bound on the original p-value to include an effect in the median calculation (default '0.95' = all non-missing). |
subtract_median |
Logical. If 'TRUE', subtracts the group median from every coefficient before returning it in 'coef_median'; otherwise the original 'effect_size' is copied unchanged (default 'FALSE'). |
n_sims |
Integer. Number of Monte-Carlo simulations used to estimate the covariance between each coefficient and the group median (default '10 000'). |
median_threshold |
Numeric. Absolute difference below which a coefficient is considered effectively equal to the median and assigned 'pval_median = 1' (default '0'). |
seed |
Optional non-negative integer seed for the simulations. Default is NULL, which uses the current random-number stream. A supplied seed is scoped with withr and restores the preceding random-number state when this function exits. |
For every distinct value in 'metadata' the algorithm
keeps coefficients with 'pval < p_cutoff' and computes their median;
simulates 'n_sims' draws of coefficients using a normal approximation ('N(effect_size, stderr^2)') and records the empirical distribution of the simulated medians;
derives a variance-inflated *offset* that accounts for the covariance between each coefficient and the group median;
performs a two-sided Z-test of 'H0 : beta_i = offset_i', returning the resulting p-value in 'pval_median'.
The input 'df' with two new columns:
Median-centred coefficient (or the original 'effect_size' if 'subtract_median = FALSE').
Two-sided p-value from the median-comparison test.
The procedure is heuristic and relies on normal approximations. Results may be unstable for very small sample sizes or when 'stderr' values are zero or missing.
The simulation and covariance-adjustment code is adapted from MaAsLin 3 by William Nickols and Jacob Nearing, distributed under the MIT license. Copyright 2025 Harvard School of Public Health. The upstream notice is included in the package's COPYRIGHTS file.
[MaAsLin 3 GitHub](https://github.com/biobakery/maaslin3)
toy <- data.frame( taxon = c("tax1", "tax2"), metadata = c("grp", "grp"), effect_size = c(0.4, 0.2), pval = c(0.01, 0.2), stderr = c(0.1, 0.1), qval = c(0.02, 0.25) ) median_comparison_tweedie(toy, n_sims = 100)toy <- data.frame( taxon = c("tax1", "tax2"), metadata = c("grp", "grp"), effect_size = c(0.4, 0.2), pval = c(0.01, 0.2), stderr = c(0.1, 0.1), qval = c(0.02, 0.25) ) median_comparison_tweedie(toy, n_sims = 100)
Compute Shannon entropy for a vector.
tweedie_entropy(target)tweedie_entropy(target)
target |
A vector of values. |
Missing values are excluded from category counts but included in the denominator to preserve the package's metadata-filtering convention. Empty and entirely missing vectors return zero.
A numeric entropy value.
Shannon CE (1948). A Mathematical Theory of Communication. Bell System Technical Journal, 27, 379-423. doi:10.1002/j.1538-7305.1948.tb01338.x.
tweedie_entropy(c("A", "A", "B", "B", "C"))tweedie_entropy(c("A", "A", "B", "B", "C"))
A compact ggplot2 theme used by Tweedieverse visualization functions.
tweedie_theme()tweedie_theme()
A list of ggplot2 theme elements.
tweedie_theme()tweedie_theme()
Fit a per-feature Tweedie generalized linear model to omics features.
Tweedieverse( input_features, input_metadata = NULL, output = NULL, assay_name = "counts", abd_threshold = 0, prev_threshold = 0.1, var_threshold = 0, entropy_threshold = 0, base_model = "CPLM", link = "log", tweedie_p = NULL, p0_transform = "NONE", p0_transform_pseudocount = 1, fixed_effects = NULL, random_effects = NULL, domain = "microbiome", normalization = NULL, adjust_offset = TRUE, scale_factor = NULL, max_significance = 0.05, correction = "BH", Maaslin2_run = TRUE, median_comparison = FALSE, median_subtraction = FALSE, run_presence_absence_model = FALSE, method_args = NULL, method.args = NULL, standardize = TRUE, BPPARAM = BiocParallel::SerialParam(), optimizer = "nlminb", na.action = na.exclude, plot_heatmap = FALSE, plot_scatter = FALSE, heatmap_first_n = 50, reference = NULL, min_presence_absence_count = 3L, return_all = FALSE, median_comparison_seed = NULL )Tweedieverse( input_features, input_metadata = NULL, output = NULL, assay_name = "counts", abd_threshold = 0, prev_threshold = 0.1, var_threshold = 0, entropy_threshold = 0, base_model = "CPLM", link = "log", tweedie_p = NULL, p0_transform = "NONE", p0_transform_pseudocount = 1, fixed_effects = NULL, random_effects = NULL, domain = "microbiome", normalization = NULL, adjust_offset = TRUE, scale_factor = NULL, max_significance = 0.05, correction = "BH", Maaslin2_run = TRUE, median_comparison = FALSE, median_subtraction = FALSE, run_presence_absence_model = FALSE, method_args = NULL, method.args = NULL, standardize = TRUE, BPPARAM = BiocParallel::SerialParam(), optimizer = "nlminb", na.action = na.exclude, plot_heatmap = FALSE, plot_scatter = FALSE, heatmap_first_n = 50, reference = NULL, min_presence_absence_count = 3L, return_all = FALSE, median_comparison_seed = NULL )
input_features |
A domain-appropriate Bioconductor container, such as
|
input_metadata |
Optional R data frame of metadata. Samples are expected
to have
matching sample names with |
output |
The output folder to write results. |
assay_name |
If the input is provided as one of the accepted
Bioconductor objects,
this argument selects the name of the assay slot in the input object that
contains the omics measurements.
For |
abd_threshold |
If prevalence-abundance filtering is desired, only
features that are present (or detected)
in at least |
prev_threshold |
If prevalence-abundance filtering is desired, only
features that are present (or detected)
in at least |
var_threshold |
If variance filtering is desired, only features that
have variances greater than
|
entropy_threshold |
Metadata columns are retained when their entropy,
computed by
|
base_model |
The per-feature base model. Only "CPLM" is supported. |
link |
A specification of the GLM link function. Default is "log". Must be one of "log", "identity", "sqrt", or "inverse". |
tweedie_p |
Numeric Tweedie variance power. Default is |
p0_transform |
Transformation to apply to a copy of the filtered feature
table when the
resolved Tweedie index is |
p0_transform_pseudocount |
Numeric pseudocount used for
|
fixed_effects |
Metadata variable(s) describing the fixed effects coefficients. |
random_effects |
Metadata variable(s) describing the random effects part of the model. |
domain |
Domain used to choose the default size-factor normalization.
Must be one of
|
normalization |
Size-factor strategy used only to compute the model
offset. The input feature
table is never normalized or transformed. If |
adjust_offset |
If TRUE (default), an offset term will be included as
the logarithm of the
size factor estimated by |
scale_factor |
Name of a numerical metadata variable containing
user-supplied sample size
factors. When supplied, this overrides |
max_significance |
The q-value threshold for significance. Default is 0.05. |
correction |
The correction method for computing the q-value (see
|
Maaslin2_run |
Logical. For |
median_comparison |
If TRUE, coefficients will be tested against a null
value corresponding to the median coefficient for a covariate in the
|
median_subtraction |
If TRUE, coefficients minus median will be used for compositionality adjustment. |
run_presence_absence_model |
If TRUE, also fit a DAssemble-style
presence-absence logistic regression model
alongside the selected abundance model, including the MaAsLin2 path used by
default for |
method_args |
Optional named list of method-specific arguments. For
|
method.args |
Alias for |
standardize |
Should continuous metadata be standardized? Default is TRUE. Bypassed for categorical variables. |
BPPARAM |
|
optimizer |
The optimization routine to be used for estimating the
parameters of the Tweedie model.
Possible choices are |
na.action |
How to handle missing values? See |
plot_heatmap |
Logical. If TRUE (default is FALSE), generate a heatmap
of the (top |
plot_scatter |
Logical. If TRUE (default is FALSE), generate scatter/box plots of individual associations. |
heatmap_first_n |
In heatmap, plot top N features with significant associations (default is 50). |
reference |
The factor to use as a reference for a variable with more than two levels provided as a string of 'variable,reference' semi-colon delimited for multiple variables (default is NULL). |
min_presence_absence_count |
Minimum number of detected samples and minimum number of undetected samples required for the presence-absence fit. Default is 3 for each. For retained features below either minimum, the presence-absence p-value is missing and the joint p-value uses the abundance p-value directly. |
return_all |
Logical. If TRUE, return the full result table before the significance threshold is applied, including when output is NULL. Default is FALSE, which returns associations passing max_significance. |
median_comparison_seed |
Optional non-negative integer seed for the median-comparison simulations. Default is NULL, which uses the current random-number stream. A supplied seed is scoped with withr and restores the preceding random-number state after the median-comparison calculation. |
For single-omics input, a data frame containing coefficient
estimates, p-values,
and q-values (multiplicity-adjusted p-values) is returned. For
MultiAssayExperiment
input, a named list of omics-specific result data frames is returned.
With return_all = TRUE, each table contains the results before
filtering by max_significance.
Himel Mallick, [email protected]
set.seed(123) features <- as.data.frame(matrix(rpois(24, lambda = 5), nrow = 12, ncol = 2)) colnames(features) <- c("feature1", "feature2") rownames(features) <- paste0("sample", seq_len(nrow(features))) metadata <- data.frame( group = rep(c("A", "B"), each = 6), row.names = rownames(features) ) experiment <- SummarizedExperiment::SummarizedExperiment( assays = list(counts = t(as.matrix(features))), colData = metadata ) fit <- Tweedieverse( input_features = experiment, output = NULL, fixed_effects = "group", median_comparison = FALSE, BPPARAM = BiocParallel::SerialParam() ) head(fit) maaslin2_median_fit <- Tweedieverse( input_features = experiment, output = NULL, fixed_effects = "group", tweedie_p = 0, Maaslin2_run = TRUE, median_comparison = TRUE, median_subtraction = TRUE, BPPARAM = BiocParallel::SerialParam() ) # For Bioconductor-container workflow examples, see: # vignette("Tweedieverse", package = "Tweedieverse")set.seed(123) features <- as.data.frame(matrix(rpois(24, lambda = 5), nrow = 12, ncol = 2)) colnames(features) <- c("feature1", "feature2") rownames(features) <- paste0("sample", seq_len(nrow(features))) metadata <- data.frame( group = rep(c("A", "B"), each = 6), row.names = rownames(features) ) experiment <- SummarizedExperiment::SummarizedExperiment( assays = list(counts = t(as.matrix(features))), colData = metadata ) fit <- Tweedieverse( input_features = experiment, output = NULL, fixed_effects = "group", median_comparison = FALSE, BPPARAM = BiocParallel::SerialParam() ) head(fit) maaslin2_median_fit <- Tweedieverse( input_features = experiment, output = NULL, fixed_effects = "group", tweedie_p = 0, Maaslin2_run = TRUE, median_comparison = TRUE, median_subtraction = TRUE, BPPARAM = BiocParallel::SerialParam() ) # For Bioconductor-container workflow examples, see: # vignette("Tweedieverse", package = "Tweedieverse")
Create a heatmap summarizing association statistics from Tweedieverse results.
Tweedieverse_heatmap( output_results, title = NA, cell_value = "qval", data_label = "data", metadata_label = "metadata", border_color = "grey93", color = colorRampPalette(c("darkblue", "grey90", "darkred")), col_rotate = 90, first_n = 50, write_to = NA )Tweedieverse_heatmap( output_results, title = NA, cell_value = "qval", data_label = "data", metadata_label = "metadata", border_color = "grey93", color = colorRampPalette(c("darkblue", "grey90", "darkred")), col_rotate = 90, first_n = 50, write_to = NA )
output_results |
Tweedieverse result data frame or path to a TSV file. |
title |
Optional plot title. |
cell_value |
Which value to display ('"qval"', '"pval"', or '"coef"'). |
data_label |
Label for feature axis. |
metadata_label |
Label for metadata axis. |
border_color |
Heatmap border color. |
color |
Color palette function. |
col_rotate |
Rotation angle for column labels. |
first_n |
Number of top features to include. |
write_to |
Optional output directory for serialized plot objects. |
A 'pheatmap' object or 'NULL' when insufficient data are available.
toy <- data.frame( feature = c("tax1", "tax2", "tax1", "tax2"), metadata = c("grp", "grp", "time", "time"), value = c("A", "B", "A", "B"), pval = c(0.01, 0.05, 0.02, 0.03), qval = c(0.02, 0.08, 0.03, 0.04), coef = c(1.2, -0.7, 0.9, -0.4) ) Tweedieverse_heatmap(toy, first_n = 2)toy <- data.frame( feature = c("tax1", "tax2", "tax1", "tax2"), metadata = c("grp", "grp", "time", "time"), value = c("A", "B", "A", "B"), pval = c(0.01, 0.05, 0.02, 0.03), qval = c(0.02, 0.08, 0.03, 0.04), coef = c(1.2, -0.7, 0.9, -0.4) ) Tweedieverse_heatmap(toy, first_n = 2)