Skip to contents

Performs beta diversity change tests at each time point relative to baseline.

Usage

generate_beta_change_per_time_test_long(
  data.obj = NULL,
  dist.obj = NULL,
  time.var,
  t0.level = NULL,
  ts.levels = NULL,
  subject.var,
  group.var,
  adj.vars = NULL,
  dist.name = c("BC", "Jaccard"),
  ...
)

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.

dist.obj

A list of pre-calculated distance matrices. If NULL and distances are needed, they will be calculated automatically. List names should match dist.name (e.g., "BC" for Bray-Curtis). See mStat_calculate_beta_diversity.

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

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.

dist.name

Character vector specifying which distance metrics to use. Options depend on available methods:

  • "BC": Bray-Curtis dissimilarity

  • "Jaccard": Jaccard distance

  • "UniFrac": Unweighted UniFrac (requires tree)

  • "GUniFrac": Generalized UniFrac (requires tree)

  • "WUniFrac": Weighted UniFrac (requires tree)

  • "JS": Jensen-Shannon divergence

...

Additional arguments passed to underlying functions.

Value

A list of test results, structured to facilitate further analysis and visualization.

See also

Related functions in MicrobiomeStat for data preparation and beta diversity calculation, such as mStat_calculate_beta_diversity, mStat_calculate_PC, and data conversion functions like mStat_convert_DGEList_to_data_obj.

Examples

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

result_pairs <- generate_beta_change_per_time_test_long(
  data.obj = subset_pairs.obj,
  dist.obj = NULL,
  time.var = "Antibiotic",
  t0.level = "Baseline",
  ts.levels = "Week 2",
  subject.var = "MouseID",
  group.var = "Sex",
  adj.vars = NULL,
  dist.name = "BC"
)

generate_beta_per_time_dotplot_long(
  data.obj = subset_pairs.obj,
  test.list = result_pairs,
  group.var = "Sex",
  time.var = "Antibiotic",
  t0.level = "Baseline",
  ts.levels = "Week 2"
)

data("ecam.obj")
dist.obj <- mStat_calculate_beta_diversity(ecam.obj, "BC")
result_ecam <- generate_beta_change_per_time_test_long(
  data.obj = ecam.obj,
  dist.obj = dist.obj,
  time.var = "month_num",
  t0.level = "0",
  ts.levels = c("1", "2"),
  subject.var = "subject.id",
  group.var = "delivery",
  adj.vars = NULL,
  dist.name = "BC"
)

generate_beta_per_time_dotplot_long(
  data.obj = ecam.obj,
  test.list = result_ecam,
  group.var = "delivery",
  time.var = "month_num",
  t0.level = "0",
  ts.levels = c("1", "2"),
  base.size = 15
)
} # }