Skip to contents

Performs alpha diversity testing at each time point in longitudinal data using linear models to compare groups.

Usage

generate_alpha_per_time_test_long(
  data.obj,
  alpha.obj = NULL,
  alpha.name = NULL,
  depth = NULL,
  time.var,
  t0.level,
  ts.levels,
  group.var,
  adj.vars = NULL
)

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.

group.var

Required. Character string specifying the grouping variable in metadata.

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.

Value

A list where each element corresponds to a different time point and contains the results of alpha diversity tests for that time point.

Examples

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

alpha_test_results_pairs <- generate_alpha_per_time_test_long(
  data.obj = subset_pairs.obj,
  alpha.name = c("shannon", "simpson"),
  time.var = "Antibiotic",
  t0.level = "Baseline",
  ts.levels = "Week 2",
  group.var = "Sex",
  adj.vars = NULL
)

generate_alpha_per_time_dotplot_long(
  data.obj = subset_pairs.obj,
  test.list = alpha_test_results_pairs,
  group.var = "Sex",
  time.var = "Antibiotic",
  t0.level = "Baseline",
  ts.levels = "Week 2",
  base.size = 16,
  theme.choice = "bw"
)

data("ecam.obj")

alpha_test_results_ecam <- generate_alpha_per_time_test_long(
  data.obj = ecam.obj,
  alpha.name = c("shannon", "simpson"),
  time.var = "month_num",
  t0.level = "0",
  ts.levels = c("1", "2"),
  group.var = "delivery",
  adj.vars = "diet"
)

generate_alpha_per_time_dotplot_long(
  data.obj = ecam.obj,
  test.list = alpha_test_results_ecam,
  group.var = "delivery",
  time.var = "month_num",
  t0.level = "0",
  ts.levels = c("1", "2"),
  base.size = 16,
  theme.choice = "bw"
)
} # }