
Adjust Confounders in a mass_dataset Object
Source:R/method_adjust_confounder.R
adjust_confounder.RdThis function adjusts for confounders in the expression data of a mass_dataset object.
The function takes a list of confounders from the sample_info data and performs a
linear regression adjustment on the expression data for each specified confounder.
Value
A modified mass_dataset object with adjusted expression data where confounders
have been accounted for.
Details
This function performs a linear model regression for each feature in the expression data
against the specified confounders from the sample information. The residuals of the model
are used as the adjusted expression data. If any NA values are present in the confounders
or if the confounder names are not found in the sample_info, the function will stop
and return an error.
Errors
The function will stop if
confounder_name_listis empty.The function will stop if any of the confounder names in
confounder_name_listare not present in thesample_info.The function will stop if any NA values are present in the specified confounders.
Examples
data("expression_data")
data("sample_info")
data("variable_info")
sample_info$batch <- rep(c(1, 2), length.out = nrow(sample_info))
sample_info$age <- seq_len(nrow(sample_info)) + 20
object <- create_mass_dataset(
expression_data = expression_data,
sample_info = sample_info,
variable_info = variable_info
)
adjusted_object <- adjust_confounder(
object = object,
confounder_name_list = c("batch", "age")
)
#> Warning: number of columns of result is not a multiple of vector length (arg 1)
head(extract_expression_data(adjusted_object))
#> Blank_3 Blank_4 QC_1 QC_2 PS4P1 PS4P2 PS4P3 PS4P4
#> M136T55_2_POS NA NA NA NA NA NA NA NA
#> M79T35_POS NA NA NA NA NA NA NA NA
#> M307T548_POS NA NA NA NA NA NA NA NA
#> M183T224_POS NA NA NA NA NA NA NA NA
#> M349T47_POS NA NA NA NA NA NA NA NA
#> M182T828_POS NA NA NA NA NA NA NA NA