
Test Beta Diversity Change Between Time Points
Source:R/generate_beta_change_test_pair.R
generate_beta_change_test_pair.RdTests within-subject beta diversity changes between two time points using linear models. Supports group comparisons and covariate adjustment.
Usage
generate_beta_change_test_pair(
data.obj,
dist.obj = NULL,
subject.var,
time.var = NULL,
group.var,
adj.vars = NULL,
change.base = 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_objor importers likemStat_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.- 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.
- 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 time point.
- 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
Value
A named list containing linear modeling results for each beta diversity metric.
Each list element corresponds to one of the distance metrics specified in dist.name.
It contains a coefficient table from fitting a linear model with the beta diversity change as
response and the group_var and adj_vars as predictors.
If group_var has multiple levels, ANOVA results are also included after the coefficients.
Column names include:
Term, Estimate, Std.Error, Statistic, P.Value
Examples
if (FALSE) { # \dontrun{
# Load packages
library(vegan)
# Load data
data(peerj32.obj)
generate_beta_change_test_pair(
data.obj = peerj32.obj,
dist.obj = NULL,
subject.var = "subject",
time.var = "time",
group.var = "group",
adj.vars = NULL,
change.base = "1",
dist.name = c('BC', 'Jaccard')
)
generate_beta_change_test_pair(
data.obj = peerj32.obj,
dist.obj = NULL,
subject.var = "subject",
time.var = "time",
group.var = "group",
adj.vars = "sex",
change.base = "1",
dist.name = c('BC', 'Jaccard')
)
data("subset_pairs.obj")
generate_beta_change_test_pair(
data.obj = subset_pairs.obj,
dist.obj = NULL,
subject.var = "MouseID",
time.var = "Antibiotic",
group.var = "Sex",
adj.vars = NULL,
change.base = "Baseline",
dist.name = c('BC', 'Jaccard')
)
} # }