Aggregates feature counts and metadata by subject and optional strata.
Usage
mStat_aggregate_data(
data.obj,
subject.var,
strata.var = NULL,
meta.handle.conflict = c("first", "stop", "summarise")
)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.- 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.
- strata.var
Character string specifying the column name in meta.dat for stratification. When provided, analyses and visualizations will be performed separately within each stratum (e.g., by site, batch, or sex).
- meta.handle.conflict
Character string specifying how to handle metadata conflicts:
"first": Use first record (default)
"stop": Error on conflicts
"summarise": Mean for numeric, first for character/factor
Examples
if (FALSE) { # \dontrun{
# Prepare data for the function
data(peerj32.obj)
# Call the function with the default subject variable "subject"
aggregated_data <- mStat_aggregate_data(
data.obj = peerj32.obj,
subject.var = "subject",
strata.var = NULL
)
# Example with a different subject variable name
# Let's pretend the subject ID column is called "participant"
# peerj32.obj$meta.dat$participant <- peerj32.obj$meta.dat$subject
# aggregated_data_2 <- mStat_aggregate_data(
# data.obj = peerj32.obj,
# subject.var = "participant",
# strata.var = "group"
# )
} # }
