Skip to contents

Computes taxa abundance changes between two time points and tests for differential change between groups using linear models (lm) or ANOVA.

Usage

generate_taxa_change_test_pair(
  data.obj,
  subject.var,
  time.var = NULL,
  group.var,
  ref.level = NULL,
  adj.vars = NULL,
  change.base = NULL,
  feature.change.func = "relative change",
  feature.level,
  prev.filter = 0,
  abund.filter = 0,
  feature.dat.type = c("count", "proportion", "other"),
  winsor.qt = 0.97
)

Arguments

data.obj

A MicrobiomeStat data object, which is a list containing at minimum the following components:

  • feature.tab: A matrix of feature abundances (taxa/genes as rows, samples as columns)

  • meta.dat: A data frame of sample metadata (samples as rows)

Optional components include:

  • feature.ann: A matrix/data frame of feature annotations (e.g., taxonomy)

  • tree: A phylogenetic tree object (class "phylo")

  • feature.agg.list: Pre-aggregated feature tables by taxonomy

Data objects can be created using converters like mStat_convert_phyloseq_to_data_obj or importers like mStat_import_qiime2_as_data_obj.

subject.var

Character string specifying the column name in meta.dat that uniquely identifies each subject or sample unit. Required for longitudinal and paired designs to track repeated measurements.

time.var

Character string specifying the column name in meta.dat containing the time variable. Required for longitudinal and paired analyses. Supports character/factor labels (e.g., "baseline", "week4") and numeric values. Some trend/volatility methods require numeric or coercible-to-numeric time values.

group.var

Character string specifying the column name in meta.dat containing the grouping variable (e.g., treatment, condition, phenotype). Used for between-group comparisons.

ref.level

Character specifying the reference level for group comparisons. If NULL, uses the first level alphabetically.

adj.vars

Character vector specifying column names in meta.dat to be used as covariates for adjustment in statistical models. These variables will be included as fixed effects.

change.base

Character or numeric specifying the baseline time point. If NULL, uses the first unique value from time.var.

feature.change.func

Method for calculating change: "relative change", "log fold change", "absolute change", or a custom function.

feature.level

Character vector specifying the taxonomic or annotation level(s) for analysis. Should match column names in feature.ann, such as "Phylum", "Family", "Genus", etc. Use "original" to analyze at the original feature level without aggregation.

prev.filter

Numeric value between 0 and 1. Features with prevalence (proportion of non-zero samples) below this threshold will be excluded from analysis. Default is usually 0 (no filtering).

abund.filter

Numeric value. Features with mean abundance below this threshold will be excluded from analysis. Default is usually 0 (no filtering).

feature.dat.type

Character string specifying the data type of feature.tab. One of:

  • "count": Raw count data (will be normalized)

  • "proportion": Relative abundance data (should sum to 1 per sample)

  • "other": Pre-transformed data (no transformation applied)

winsor.qt

Numeric (0-1) specifying the quantile for winsorization. Default 0.97.

Value

A nested list structure where:

  • First level: Named by feature.level (e.g., "Phylum", "Genus")

  • Second level: Named by tested comparisons between groups

    • Elements named as "Level vs Reference (Reference)"

    • If group.var has >2 levels, includes ANOVA results

  • Each element is a data.frame with the following columns:

    • Variable: Feature/taxon name

    • Coefficient: Effect size of the change between time points (interpretation depends on feature.change.func: for "log fold change", represents difference in log2 abundances; for "relative change", represents relative difference; for "absolute change", represents absolute difference)

    • SE: Standard error of the coefficient from the linear model

    • P.Value: Raw p-value from standard linear model (lm)

    • Adjusted.P.Value: FDR-adjusted p-value using Benjamini-Hochberg method

    • Mean.Abundance: Mean abundance of the feature across all samples

    • Prevalence: Proportion of samples where the feature is present (non-zero)

This function analyzes CHANGE SCORES (differences between two time points) rather than raw abundances, using standard linear models rather than LinDA mixed-effects models.

Examples

if (FALSE) { # \dontrun{
data(peerj32.obj)
generate_taxa_change_test_pair(
  data.obj = peerj32.obj,
  subject.var = "subject",
  time.var = "time",
  group.var = "group",
  adj.vars = "sex",
  change.base = "1",
  feature.change.func = "log fold change",
  feature.level = c("Genus"),
  prev.filter = 0.1,
  abund.filter = 1e-4,
  feature.dat.type = "count"
)

data(subset_pairs.obj)
generate_taxa_change_test_pair(
  data.obj = subset_pairs.obj,
  subject.var = "MouseID",
  time.var = "Antibiotic",
  group.var = "Sex",
  adj.vars = NULL,
  change.base = "Baseline",
  feature.change.func = "log fold change",
  feature.level = c("Genus"),
  prev.filter = 0.1,
  abund.filter = 1e-4,
  feature.dat.type = "count"
)
} # }