Skip to contents

Performs paired tests comparing alpha diversity changes between baseline and each follow-up time point in longitudinal data.

Usage

generate_alpha_change_per_time_test_long(
  data.obj,
  alpha.obj = NULL,
  alpha.name = NULL,
  depth = NULL,
  time.var,
  t0.level,
  ts.levels,
  subject.var,
  group.var,
  adj.vars = NULL,
  alpha.change.func = "log fold change"
)

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.

alpha.obj

A list containing pre-calculated alpha diversity indices. If NULL and alpha diversity is needed, it will be calculated automatically. Names should match the alpha.name parameter (e.g., "shannon", "simpson"). See mStat_calculate_alpha_diversity.

alpha.name

Character vector specifying which alpha diversity indices to analyze. Options include:

  • "shannon": Shannon diversity index

  • "simpson": Simpson diversity index

  • "observed_species": Observed species richness

  • "chao1": Chao1 richness estimator

  • "ace": ACE richness estimator

  • "pielou": Pielou's evenness

  • "faith_pd": Faith's phylogenetic diversity (requires a tree)

depth

Numeric value or NULL. Rarefaction depth for rarefaction workflows. If NULL, uses the minimum sample depth.

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.

t0.level

Character or numeric value specifying the baseline time point for longitudinal or paired analyses. Should match a value in the time.var column.

ts.levels

Character vector specifying the follow-up time points for longitudinal or paired analyses. Should match values in the time.var column.

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.

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.

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.

alpha.change.func

Function or method for calculating change in alpha diversity between two timepoints. Options include 'log fold change', 'absolute change', or a custom function.

Value

A list of tables, one for each alpha diversity metric, summarizing the results of the statistical tests.

Examples

if (FALSE) { # \dontrun{
library(vegan)
data("subset_pairs.obj")

alpha_test_results <- generate_alpha_change_per_time_test_long(
  data.obj = subset_pairs.obj,
  alpha.name = c("shannon", "simpson"),
  time.var = "Antibiotic",
  t0.level = unique(subset_pairs.obj$meta.dat$Antibiotic)[1],
  ts.levels = unique(subset_pairs.obj$meta.dat$Antibiotic)[-1],
  subject.var = "MouseID",
  group.var = "Sex",
  adj.vars = NULL,
  alpha.change.func = "absolute change"
)

generate_alpha_per_time_dotplot_long(
  data.obj = subset_pairs.obj,
  test.list = alpha_test_results,
  group.var = "Sex",
  time.var = "Antibiotic",
  t0.level = unique(subset_pairs.obj$meta.dat$Antibiotic)[1],
  ts.levels = unique(subset_pairs.obj$meta.dat$Antibiotic)[-1],
  base.size = 16,
  theme.choice = "bw"
)
} # }