Title: | Inference of Causal Links Between a Network and an External Variable |
---|---|
Description: | The 'NetCoupler' algorithm identifies potential direct effects of correlated, high-dimensional variables formed as a network with an external variable. The external variable may act as the dependent/response variable or as an independent/predictor variable to the network. |
Authors: | Luke Johnston [aut, cre, cph] , Clemens Wittenbecher [aut, cph] , Fabian Eichelmann [ctb], Helena Zacharias [ctb], Daniel Ibsen [ctb] |
Maintainer: | Luke Johnston <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-10-31 19:48:03 UTC |
Source: | https://github.com/netcoupler/netcoupler |
as_edge_tbl(network_object)
as_edge_tbl(network_object)
network_object |
Network graph from |
A tibble, with at least two columns:
source_node
: The starting node (variable).
target_node
: The ending node (variable) that links with the source node.
adjacency_weight
: (Optional) The "weight" given to the edge, which
represents the strength of the link between two nodes.
See nc_estimate_links for examples on using NetCoupler.
Classification options for direct, ambigious, and no effect.
classify_options( single_metabolite_threshold = 0.05, network_threshold = 0.1, direct_effect_adjustment = NA )
classify_options( single_metabolite_threshold = 0.05, network_threshold = 0.1, direct_effect_adjustment = NA )
single_metabolite_threshold , network_threshold , direct_effect_adjustment
|
See the |
List with options for the classification.
This is the main function that identifies potential links between external factors and the network. There are two functions to estimate and classify links:
nc_estimate_exposure_links()
: Computes the model estimates for the exposure side.
nc_estimate_outcome_links()
: Computes the model estimates for the exposure side.
nc_estimate_exposure_links( data, edge_tbl, exposure, adjustment_vars = NA, model_function, model_arg_list = NULL, exponentiate = FALSE, classify_option_list = classify_options() ) nc_estimate_outcome_links( data, edge_tbl, outcome, adjustment_vars = NA, model_function, model_arg_list = NULL, exponentiate = FALSE, classify_option_list = classify_options() )
nc_estimate_exposure_links( data, edge_tbl, exposure, adjustment_vars = NA, model_function, model_arg_list = NULL, exponentiate = FALSE, classify_option_list = classify_options() ) nc_estimate_outcome_links( data, edge_tbl, outcome, adjustment_vars = NA, model_function, model_arg_list = NULL, exponentiate = FALSE, classify_option_list = classify_options() )
data |
The data.frame or tibble that contains the variables of interest, including the variables used to make the network. |
edge_tbl |
Output graph object from |
exposure , outcome
|
Character. The exposure or outcome variable of interest. |
adjustment_vars |
Optional. Variables to adjust for in the models. |
model_function |
A function for the model to use (e.g. |
model_arg_list |
Optional. A list containing the named arguments that
will be passed to the model function. A simple example would be
|
exponentiate |
Logical. Whether to exponentiate the log estimates, as computed with e.g. logistic regression models. |
classify_option_list |
A list with classification options for direct, ambigious, or no
effects. Used with the
|
Outputs a tibble that contains the model estimates from either the exposure or outcome side of the network as well as the effect classification. Each row represents the "no neighbour node adjusted" model and has the results for the outcome/exposure to index node pathway. Columns for the outcome are:
outcome
or exposure
: The name of the variable used as the external variable.
index_node
: The name of the metabolite used as the index node from the network.
In combination with the outcome/exposure variable, they represent the individual
model used for the classification.
estimate
: The estimate from the outcome/exposure and index node model.
std_error
: The standard error from the outcome/exposure and index node model.
fdr_p_value
: The False Discovery Rate-adjusted p-value from the
outcome/exposure and index node model.
effect
: The NetCoupler classified effect between the index node and the
outcome/exposure. Effects are classified as "direct" (there is a probable link
based on the given thresholds), "ambigious" (there is a potential link but
not all thresholds were passed), and "none" (no potential link seen).
The tibble output also has an attribute that contains all the models
generated before classification. Access it with attr(output, "all_models_df")
.
vignette("examples")
article has more
details on how to use NetCoupler with different models.
standardized_data <- simulated_data %>% nc_standardize(starts_with("metabolite")) metabolite_network <- simulated_data %>% nc_standardize(starts_with("metabolite"), regressed_on = "age") %>% nc_estimate_network(starts_with("metabolite")) edge_table <- as_edge_tbl(metabolite_network) results <- standardized_data %>% nc_estimate_exposure_links( edge_tbl = edge_table, exposure = "exposure", model_function = lm ) results # Get results of all models used prior to classification
standardized_data <- simulated_data %>% nc_standardize(starts_with("metabolite")) metabolite_network <- simulated_data %>% nc_standardize(starts_with("metabolite"), regressed_on = "age") %>% nc_estimate_network(starts_with("metabolite")) edge_table <- as_edge_tbl(metabolite_network) results <- standardized_data %>% nc_estimate_exposure_links( edge_tbl = edge_table, exposure = "exposure", model_function = lm ) results # Get results of all models used prior to classification
The main NetCoupler network creator.
Uses the input data to estimate the underlying undirected graph.
The default uses the PC algorithm, implemented within NetCoupler
with pc_estimate_undirected_graph()
Defaults to using the PC algorithm to calculate possible edges.
Any missing values in the input data are removed by this function,
since some computations can't handle missingness.
nc_estimate_network(data, cols = everything(), alpha = 0.01)
nc_estimate_network(data, cols = everything(), alpha = 0.01)
data |
Data that would form the underlying network. |
cols |
< |
alpha |
The alpha level to use to test whether an edge exists or not. Default is 0.01. |
Outputs a tidygraph::tbl_graph()
with the start and end nodes, as
well as the edge weights.
See nc_estimate_links for examples on using NetCoupler and pc_estimate_undirected_graph for more details on the PC-algorithm network estimation method.
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)
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"))
# 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"))
Simulated dataset with an underlying Directed Graph structure for the metabolites.
simulated_data
simulated_data
The simulated dataset is a tibble with the following variables:
Two outcome variables (outcome_continuous
and outcome_binary
) along
with survival time (outcome_event_time
) that is used for the
outcome_binary
variable
A generic exposure
variable as continuous
12 metabolite_*
variables
An age
variable used as a confounder