nc_standardize {NetCoupler} | R Documentation |
Standardize the metabolic variables.
Description
Can standardize by either 1) log()
-transforming and then applying scale()
(mean-center and scaled by standard deviation), or 2) if regressed_on
variables are given, then log-transforming, running a linear regression to obtain
the stats::residuals()
, and finally scaled. Use regressed_on
to try to
remove influence of potential confounding.
Usage
nc_standardize(data, cols = everything(), regressed_on = NULL)
Arguments
data |
Data frame. |
cols |
Metabolic variables that will make up the network. |
regressed_on |
Optional. A character vector of variables to regress the metabolic variables on. Use if you want to standardize the metabolic variables on variables that are known to influence them, e.g. sex or age. Calculates the residuals from a linear regression model. |
Value
Outputs a tibble object, with the original metabolic variables now standardized.
See Also
nc_estimate_links for more detailed examples or the vignette("NetCoupler")
.
Examples
# Don't regress on any variable
simulated_data %>%
nc_standardize(starts_with("metabolite_"))
# Extract residuals by regressing on a variable
simulated_data %>%
nc_standardize(starts_with("metabolite_"), "age")
# Works with factors too
simulated_data %>%
dplyr::mutate(Sex = as.factor(sample(rep(c("F", "M"), times = nrow(.) / 2)))) %>%
nc_standardize(starts_with("metabolite_"), c("age", "Sex"))