
Beta Diversity Trend Test for Longitudinal Data
Source:R/generate_beta_trend_test_long.R
generate_beta_trend_test_long.RdPerforms linear mixed effects models to test longitudinal trends in beta diversity.
Usage
generate_beta_trend_test_long(
data.obj,
dist.obj = NULL,
subject.var,
time.var,
group.var = NULL,
adj.vars = NULL,
dist.name = c("BC"),
...
)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.
- 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 internal functions.
Value
A list containing the result of the trend test for each specified beta diversity index. The result includes a tibble with the coefficients extracted from the mixed-effects model fitted for each distance.
Details
The function starts by validating the input data, followed by processing the time variable and calculating the beta diversity if necessary. Adjustments are made based on the provided adjusting variables, and the mixed-effects model is fitted to the long-format data. The coefficients of the model are extracted and returned for each beta diversity index specified.
Note
A warning message will be displayed to ensure that the time variable is coded as numeric. Non-numeric coding may lead to issues in the trend test computation.
Examples
if (FALSE) { # \dontrun{
data(ecam.obj)
generate_beta_trend_test_long(
data.obj = ecam.obj,
dist.obj = NULL,
subject.var = "studyid",
time.var = "month",
group.var = "diet",
adj.vars = c("antiexposedall","delivery"),
dist.name = c("BC", "Jaccard")
)
generate_beta_trend_test_long(
data.obj = ecam.obj,
dist.obj = NULL,
subject.var = "studyid",
time.var = "month",
group.var = NULL,
adj.vars = NULL,
dist.name = c("BC", "Jaccard")
)
data(subset_T2D.obj)
generate_beta_trend_test_long(
data.obj = subset_T2D.obj,
dist.obj = NULL,
subject.var = "subject_id",
time.var = "visit_number_num",
group.var = "subject_race",
adj.vars = c("subject_gender"),
dist.name = c("BC", "Jaccard")
)
generate_beta_trend_test_long(
data.obj = subset_T2D.obj,
dist.obj = NULL,
subject.var = "subject_id",
time.var = "visit_number_num",
group.var = NULL,
adj.vars = NULL,
dist.name = c("BC", "Jaccard")
)
} # }