Longitudinal Alpha Diversity Test in Microbiome Data
Source:R/generate_alpha_per_time_test_long.R
generate_alpha_per_time_test_long.Rd
This function performs alpha diversity testing at multiple time points in longitudinal microbiome data. It applies linear model analyses to assess the diversity of microbial communities over time within different groups or under various conditions.
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 = NULL,
adj.vars = NULL
)
Arguments
- data.obj
A MicrobiomeStat data object containing microbiome data and metadata.
- alpha.obj
An optional list containing pre-calculated alpha diversity indices. If NULL (default), alpha diversity indices will be calculated using mStat_calculate_alpha_diversity function from MicrobiomeStat package.
- alpha.name
character vector containing the names of alpha diversity indices to calculate. Possible values are: "shannon", "simpson", "observed_species", "chao1", "ace", and "pielou".
- depth
An integer specifying the sequencing depth for the "Rarefy" and "Rarefy-TSS" methods. If NULL, no rarefaction is performed.
- time.var
A string representing the time variable in the meta.dat.
- t0.level
A baseline time point for longitudinal analysis, specified as a character or numeric value, e.g., "week_0" or 0.
- ts.levels
A vector of character strings indicating follow-up time points, such as c("week_4", "week_8").
- group.var
Optional; a string specifying the group variable in meta.dat for between-group comparisons.
- adj.vars
Optional; a vector of strings representing covariates in meta.dat for adjustment in the analysis.
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{
# Example 1: Analyzing the ECAM dataset (without providing alpha.obj)
data("ecam.obj")
# Perform the longitudinal alpha diversity test for the ECAM dataset
alpha_test_results_ecam <- generate_alpha_per_time_test_long(
data.obj = ecam.obj,
alpha.name = c("shannon", "simpson", "observed_species", "pielou"),
time.var = "month",
t0.level = unique(ecam.obj$meta.dat$month)[1],
ts.levels = unique(ecam.obj$meta.dat$month)[-1],
group.var = "delivery",
adj.vars = c("diet")
)
# Generate dot plots for the ECAM dataset results
dot_plots_ecam <- generate_alpha_per_time_dotplot_long(
data.obj = ecam.obj,
test.list = alpha_test_results_ecam,
group.var = "delivery",
time.var = "month",
t0.level = unique(ecam.obj$meta.dat$month)[1],
ts.levels = unique(ecam.obj$meta.dat$month)[-1],
base.size = 16,
theme.choice = "bw"
)
# Example 2: Analyzing the Type 2 Diabetes (T2D) dataset (with providing alpha.obj)
data("subset_T2D.obj")
# Calculate alpha diversity indices
alpha.obj <- mStat_calculate_alpha_diversity(
x = subset_T2D.obj$feature.tab,
alpha.name = c("shannon", "simpson", "observed_species", "chao1", "ace", "pielou")
)
# Perform the longitudinal alpha diversity test for the T2D dataset
alpha_test_results_T2D <- generate_alpha_per_time_test_long(
data.obj = subset_T2D.obj,
alpha.obj = alpha.obj,
alpha.name = c("shannon", "simpson", "observed_species", "chao1", "ace", "pielou"),
time.var = "visit_number_num",
t0.level = unique(subset_T2D.obj$meta.dat$visit_number_num)[1],
ts.levels = unique(subset_T2D.obj$meta.dat$visit_number_num)[-1],
group.var = "subject_race",
adj.vars = c("sample_body_site")
)
# Generate dot plots for the T2D dataset results
dot_plots_T2D <- generate_alpha_per_time_dotplot_long(
data.obj = subset_T2D.obj,
test.list = alpha_test_results_T2D,
group.var = "subject_race",
time.var = "visit_number_num",
t0.level = unique(subset_T2D.obj$meta.dat$visit_number_num)[1],
ts.levels = unique(subset_T2D.obj$meta.dat$visit_number_num)[-1],
base.size = 16,
theme.choice = "bw"
)
# Example 3: Analyzing the ECAM dataset without adjustment variables
alpha_test_results_ecam_no_adj <- generate_alpha_per_time_test_long(
data.obj = ecam.obj,
alpha.name = c("shannon", "simpson", "observed_species", "pielou"),
depth = 1000,
time.var = "month",
t0.level = unique(ecam.obj$meta.dat$month)[1],
ts.levels = unique(ecam.obj$meta.dat$month)[-1],
group.var = "delivery",
adj.vars = NULL
)
# Generate dot plots for the ECAM dataset results without adjustment variables
dot_plots_ecam_no_adj <- generate_alpha_per_time_dotplot_long(
data.obj = ecam.obj,
test.list = alpha_test_results_ecam_no_adj,
group.var = "delivery",
time.var = "month",
t0.level = unique(ecam.obj$meta.dat$month)[1],
ts.levels = unique(ecam.obj$meta.dat$month)[-1],
base.size = 16,
theme.choice = "minimal"
)
} # }