Learn R Programming

MicrobTiSDA (version 0.1.0)

Data.trans: Transform Microbial Composition Data.

Description

This function applies the modified centered log-ratio (MCLR) transformation function mclr.transform to a data matrix (e.g., OTU/ASV counts). When a grouping variable is provided the transformation is applied separately for each group defined in the metadata.

Usage

Data.trans(Data, metadata, Group_var)

Value

An object of class "TransformedData" containing the transformed count table.

Arguments

Data

A data frame or matrix of microbial compositional data, with rows representing microbial features (OTUs/ASVs) and columns representing samples. If the function Data.interpolate is preformed, the first element of the output object of Data.interpolate should be extract as the input of this function.

metadata

A data frame. Containing information about all samples, including at least the grouping of all samples as well as individual information (Group and ID), the sampling Time point for each sample, and other relevant information.

Group_var

A string or a vector. This specifies the grouping variables, which should match the column names in the metadata used to designate sample groups, and for pre-processing OTU data of each group or individual separately. For instance, to split the OTU table based on the "Group" variable, set Group_var = "Group"; to split the data based on the "Group" and "Diet" (if in metadata)categorical variables to study the interaction between different grouping variables, set Group_var = c("Group","Diet").

Author

Shijia Li

Details

The function transforms the input data using the MCLR method. If no grouping variable is provided (i.e. Group_var is NULL), the transformation is applied to the entire dataset. If a single grouping variable is specified, the data is partitioned into subsets corresponding to the unique groups in the metadata, and the transformation is applied to each subset separately; the results are then combined using row binding. For multiple grouping variables, a composite grouping factor is created using the interaction of the specified variables, and the transformation is applied to each composite group in a similar manner.

Examples

Run this code
# \donttest{
# Create example data matrix (5 features x 10 samples)
set.seed(123)
Data <- matrix(sample(1:100, 50, replace = TRUE), nrow = 5)
rownames(Data) <- paste0("Feature", 1:5)
colnames(Data) <- paste0("Sample", 1:10)

# Create example metadata with a grouping variable
metadata <- data.frame(Group = rep(c("A", "B"), each = 5))
rownames(metadata) <- paste0("Sample", 1:10)

# Apply MCLR transformation to the entire dataset
transformed_data <- Data.trans(Data, metadata, Group_var = NULL)

# Apply MCLR transformation separately for each group
transformed_data_by_group <- Data.trans(Data, metadata, Group_var = "Group")
# }

Run the code above in your browser using DataLab