nc_standardize | R Documentation |
experimental
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.
nc_standardize(data, cols = everything(), regressed_on = NULL)
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. |
Outputs a tibble object, with the original metabolic variables now standardized.
nc_estimate_links for more detailed examples or the vignette("NetCoupler")
.
# 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.