
Alpha Diversity Association Test (Single Time Point)
Source:R/generate_alpha_test_single.R
generate_alpha_test_single.RdPerforms association tests for alpha diversity indices using linear models for cross-sectional data or a single time point.
Usage
generate_alpha_test_single(
data.obj,
alpha.obj = NULL,
alpha.name = NULL,
depth = NULL,
time.var = NULL,
t.level = NULL,
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_objor importers likemStat_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.
- t.level
Character string specifying the time level/value to subset data to, if a time variable is provided. Default NULL does not subset data.
- 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.
Value
A list containing the association tests for each alpha diversity index. Each element in the list corresponds to a different alpha diversity index, and contains a dataframe with the linear model's coefficients, standard errors, t values, and p values.
Examples
if (FALSE) { # \dontrun{
data("subset_T2D.obj")
# Example where alpha diversity indices are calculated beforehand
alpha.obj <- mStat_calculate_alpha_diversity(subset_T2D.obj$feature.tab,
c("shannon", "observed_species", "ace"))
generate_alpha_test_single(data.obj = subset_T2D.obj,
alpha.obj = alpha.obj,
alpha.name = c("shannon", "observed_species", "ace"),
time.var = "visit_number",
t.level = NULL,
group.var = "subject_race",
adj.vars = "subject_gender")
# Example where alpha diversity indices are calculated within the function
generate_alpha_test_single(data.obj = subset_T2D.obj,
time.var = "visit_number",
t.level = unique(subset_T2D.obj$meta.dat$visit_number)[4],
alpha.name = c("shannon", "observed_species"),
group.var = "subject_race",
adj.vars = "subject_gender")
data("peerj32.obj")
generate_alpha_test_single(data.obj = peerj32.obj,
time.var = "time",
t.level = "1",
alpha.name = c("shannon", "observed_species"),
group.var = "group",
adj.vars = "sex")
generate_alpha_test_single(data.obj = peerj32.obj,
time.var = "time",
t.level = "1",
alpha.name = c("shannon", "observed_species"),
group.var = "group",
adj.vars = NULL)
} # }