DesignModelMatrix | R Documentation |
This function generates a model matrix for statistical analysis based on metadata. It creates a grouping variable from the specified contrast columns, ensuring proper formatting for downstream analysis.
DesignModelMatrix(meta_df, contrast_columns, sampleIdCol = "cDNA_ID")
meta_df |
A data frame containing sample metadata. |
contrast_columns |
Character vector. Column names in 'meta_df' to be used for defining experimental groups. |
sampleIdCol |
Character. Name of the column in 'meta_df' that contains sample identifiers (default: '"cDNA_ID"'). |
This function:
Merges ('unites') values from 'contrast_columns' into a single 'group' column.
Ensures valid R variable names using 'make.names()'.
Constructs a design matrix using 'stats::model.matrix()', encoding the experimental conditions.
Attaches metadata attributes ('contrast_columns', 'sampleIdCol') to the resulting matrix.
A model matrix where rows correspond to samples and columns correspond to experimental conditions. The matrix includes attributes '"contrast_columns"' and '"sampleIdCol"' for reference.
## Not run:
if(requireNamespace("dplyr", quietly = TRUE) && requireNamespace("tidyr", quietly = TRUE)) {
metadata <- data.frame(
cDNA_ID = c("Sample1", "Sample2", "Sample3"),
Treatment = c("A", "B", "A"),
Batch = c("X", "X", "Y")
)
design_matrix <- DesignModelMatrix(metadata, contrast_columns = c("Treatment", "Batch"))
print(design_matrix)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.