| Title: | Covariate-Varying Networks |
|---|---|
| Description: | Inferring high-dimensional Gaussian graphical networks that change with multiple discrete covariates. Louis Dijkstra, Arne Godt, Ronja Foraita (2024) <doi:10.48550/arXiv.2407.19978>. |
| Authors: | Louis Dijkstra [aut] (ORCID: <https://orcid.org/0000-0003-1476-6202>), Ronja Foraita [aut, cre] (ORCID: <https://orcid.org/0000-0003-2216-6653>), Lukas Burk [ctb] (ORCID: <https://orcid.org/0000-0001-7528-3795>), Leibniz Inst Prev Res & Epidemiology - BIPS [cph, fnd] (ROR: <https://ror.org/02c22vc57>), Deutsche Forschungsgemeinschaft (DFG) [fnd] |
| Maintainer: | Ronja Foraita <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1 |
| Built: | 2026-05-15 09:23:22 UTC |
| Source: | https://github.com/bips-hb/CVN |
Inferring high-dimensional Gaussian graphical networks that change with multiple discrete covariates.
Maintainer: Ronja Foraita [email protected] (ORCID)
Authors:
Louis Dijkstra (ORCID)
Other contributors:
Lukas Burk (ORCID) [contributor]
Leibniz Inst Prev Res & Epidemiology - BIPS (ROR) [copyright holder, funder]
Deutsche Forschungsgemeinschaft (DFG) [funder]
Dijkstra L, Godt A, Foraita R Inferring High-Dimensional Dynamic Networks Changing with Multiple Covariates (2024), Arxiv, https://arxiv.org/abs/2407.19978.
Useful links:
Report bugs at https://github.com/bips-hb/CVN/issues
data(grid) W <- create_weight_matrix(type = "grid", k=3, l=3, plot = FALSE) cvn <- CVN(grid, W, lambda1 = 1, lambda2 = 1:2, n_cores = 1, eps = 1e-2, maxiter = 1000, verbose = TRUE)data(grid) W <- create_weight_matrix(type = "grid", k=3, l=3, plot = FALSE) cvn <- CVN(grid, W, lambda1 = 1, lambda2 = 1:2, n_cores = 1, eps = 1e-2, maxiter = 1000, verbose = TRUE)
Function to combine single CVNs. Handy, if CVNs are computed in parallel using foreach loop and n_cores = 1
combine_cvn(cvn_list, minimal = TRUE)combine_cvn(cvn_list, minimal = TRUE)
cvn_list |
a list of CVNs, each of size 1 (one lambda/gamma pair) |
minimal |
logical; stripped CVN (default = TRUE) |
a CVN of size length(cvn_list)
data(grid) #' Choice of the weight matrix W. Each of 2 covariates has 3 categories #' (uniform random) W_grid <- create_weight_matrix("grid", k = 3, l = 3) fit1 <- CVN(data = grid, W = W_grid, lambda1 = 1, lambda2 = 0.5, gamma_ebic = 0.75, n_cores = 1, eps = 1e-2, maxiter = 200, minimal = TRUE) fit2 <- CVN(data = grid, W = W_grid, lambda1 = 2, lambda2 = 0.75, gamma_ebic = 0.75, n_cores = 1, eps = 1e-2, maxiter = 200, minimal = TRUE) (fit <- combine_cvn(list(fit1, fit2)))data(grid) #' Choice of the weight matrix W. Each of 2 covariates has 3 categories #' (uniform random) W_grid <- create_weight_matrix("grid", k = 3, l = 3) fit1 <- CVN(data = grid, W = W_grid, lambda1 = 1, lambda2 = 0.5, gamma_ebic = 0.75, n_cores = 1, eps = 1e-2, maxiter = 200, minimal = TRUE) fit2 <- CVN(data = grid, W = W_grid, lambda1 = 2, lambda2 = 0.75, gamma_ebic = 0.75, n_cores = 1, eps = 1e-2, maxiter = 200, minimal = TRUE) (fit <- combine_cvn(list(fit1, fit2)))
Combine an interpolated CVN to an original CVN
combine_cvn_interpolated(cvn, cvn_interpolated)combine_cvn_interpolated(cvn, cvn_interpolated)
cvn |
A CVN fit with |
cvn_interpolated |
A interpolated CVN from a fitted CVN model with |
A 'cvn_interpolated' object (see interpolate).
path <- system.file("cvnfit.rda", package = "CVN") load(path) interpolate <- interpolate(fit, c(0,0,0,0,0,0,0,0.5,0.5), truncate = 0.05) fit10 <- combine_cvn_interpolated(fit, interpolate)path <- system.file("cvnfit.rda", package = "CVN") load(path) interpolate <- interpolate(fit, c(0,0,0,0,0,0,0,0.5,0.5), truncate = 0.05) fit10 <- combine_cvn_interpolated(fit, interpolate)
data.frame for the Edges for visNetwork
In order to visualize a graph, we need to create a
data.frame that can be used by the visNetwork package.
This function returns the needed data.frame given a
adjacency matrix.
create_edges_visnetwork(adj_matrix)create_edges_visnetwork(adj_matrix)
adj_matrix |
A symmetric adjacency matrix |
Data frame that be used as input for visNetwork
nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)
visNetwork packageCreates a data frame that can be used for the
visNetwork package.
create_nodes_visnetwork(n_nodes, labels = 1:n_nodes)create_nodes_visnetwork(n_nodes, labels = 1:n_nodes)
n_nodes |
Number of nodes in the graph |
labels |
The labels for the individual nodes
(Default: |
Data frame with two columns: id and title
nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)
This function generates different weight matrices for two external covariates, .
There are several types:
full All graphs are fully connected with weight 1
glasso All graphs are disconnected with weight 0. This mimics the GLASSO, where each graph is estimated independently
grid A weight matrix for a grid
uniform-random Fully-connected, but the entries are drawn from a uniform distribution
create_weight_matrix( type = c("full", "glasso", "grid", "uniform-random"), k, l, plot = FALSE )create_weight_matrix( type = c("full", "glasso", "grid", "uniform-random"), k, l, plot = FALSE )
type |
The type of weight matrix |
k |
Number of categories in the first external covariate |
l |
Number of categories in the second external covariate |
plot |
If TRUE, the weight matrix is plotted (default: FALSE) |
Weight matrix
W <- create_weight_matrix(type="grid", k=3, l=2)W <- create_weight_matrix(type="grid", k=3, l=2)
Estimates a covariate-varying network model (CVN), i.e.,
Gaussian graphical models that change with (multiple) external covariate(s).
The smoothing between the graphs is specified by the -dimensional
weight matrix . The function returns the estimated precision matrices
for each graph.
CVN( data, W, lambda1 = 1:2, lambda2 = 1:2, gamma1 = NULL, gamma2 = NULL, rho = 1, eps = 1e-04, maxiter = 100, truncate = 1e-05, rho_genlasso = 1, eps_genlasso = 1e-10, maxiter_genlasso = 100, truncate_genlasso = 1e-04, n_cores = min(length(lambda1) * length(lambda2), detectCores() - 1), normalized = FALSE, warmstart = TRUE, minimal = FALSE, gamma_ebic = 0.5, verbose = TRUE )CVN( data, W, lambda1 = 1:2, lambda2 = 1:2, gamma1 = NULL, gamma2 = NULL, rho = 1, eps = 1e-04, maxiter = 100, truncate = 1e-05, rho_genlasso = 1, eps_genlasso = 1e-10, maxiter_genlasso = 100, truncate_genlasso = 1e-04, n_cores = min(length(lambda1) * length(lambda2), detectCores() - 1), normalized = FALSE, warmstart = TRUE, minimal = FALSE, gamma_ebic = 0.5, verbose = TRUE )
data |
A list with matrices, each entry associated with a single graph. The number of columns should be the same for each matrix. Number of observations can differ |
W |
The |
lambda1 |
Vector with different |
lambda2 |
Vector with different |
gamma1 |
A vector of |
gamma2 |
A vector of |
rho |
The |
eps |
If the relative difference between two update steps is
smaller than |
maxiter |
Maximum number of iterations (Default: |
truncate |
All values of the final |
rho_genlasso |
The |
eps_genlasso |
If the relative difference between two update steps is
smaller than |
maxiter_genlasso |
Maximum number of iterations for solving
the generalized LASSO problem (Default: |
truncate_genlasso |
All values of the final |
n_cores |
Number of cores used (Default: max. number of cores - 1, or the total number penalty term pairs if that is less) |
normalized |
Data is normalized if |
warmstart |
If |
minimal |
If |
gamma_ebic |
Gamma value for the eBIC (Default: 0.5) |
verbose |
Verbose (Default: |
A CVN object containing the estimates for all the graphs
for each different value of . General results for
the different values of can be found in the data frame
results. It consists of multiple columns, namely:
id |
The id. This corresponds to the indices of the lists |
lambda1 |
|
lambda2 |
|
gamma1 |
|
gamma2 |
|
converged |
whether algorithm converged or not |
value |
value of the negative log-likelihood function |
n_iterations |
number of iterations of the ADMM |
aic |
Akaike information criterion |
bic |
Bayesian information criterion |
ebic |
Extended Bayesian information criterion |
edges_median |
Median number of edges across the m estimated graphs |
edges_iqr |
Interquartile range of edges across the m estimated graphs |
The estimates of the precision matrices and the corresponding adjacency matrices
for the different values of can be found
Theta |
A list with the estimated precision matrices |
adj_matrices |
A list with the estimated adjacency matrices corresponding to the
estimated precision matrices in |
In addition, the input given to the CVN function is stored in the object as well:
Sigma |
Empirical covariance matrices |
m |
Number of graphs |
p |
Number of variables |
n_obs |
Vector of length |
data |
The |
W |
The |
maxiter |
Maximum number of iterations for the ADMM |
rho |
The |
eps |
The stopping criterion |
truncate |
Truncation value for |
maxiter_genlasso |
Maximum number of iterations for the generalized LASSO |
rho_genlasso |
The |
eps_genlasso |
The stopping criterion |
truncate_genlasso |
Truncation value for |
n_lambda_values |
Total number of |
normalized |
If |
warmstart |
If |
minimal |
If |
hits_border_aic |
If |
hits_border_bic |
If |
gamma_ebic |
Gamma value used to calculate eBIC |
When estimating the graph for different values of
and , we use the graph estimated (if available)
for other and values closest to them.
data(grid) #' Choice of the weight matrix W. Each of 2 covariates has 3 categories #' (uniform random) W <- create_weight_matrix("uniform-random", k = 3, l = 3) # lambdas: lambda1 = 1 # can also be lambda1 = 1:2 lambda2 = 1 (fit <- CVN(data = grid, W = W, lambda1 = lambda1, lambda2 = lambda2, n_cores = 1, eps = 1e-2, maxiter = 200, # fast but imprecise verbose = TRUE))data(grid) #' Choice of the weight matrix W. Each of 2 covariates has 3 categories #' (uniform random) W <- create_weight_matrix("uniform-random", k = 3, l = 3) # lambdas: lambda1 = 1 # can also be lambda1 = 1:2 lambda2 = 1 (fit <- CVN(data = grid, W = W, lambda1 = lambda1, lambda2 = lambda2, n_cores = 1, eps = 1e-2, maxiter = 200, # fast but imprecise verbose = TRUE))
Function that gives an overview about the number of edges in each subgraph over all fitted CVN models.
cvn_edge_summary(cvn)cvn_edge_summary(cvn)
cvn |
A |
A data.frame showing the number of edges in each subgraph, the number of edges present in all graphs (core edges) and the number of edges that are unique for a subgraph
data(grid) W <- create_weight_matrix("grid", 3, 3) # lambdas: lambda1 = c(1, 1.5) lambda2 = .2 fit <- CVN(grid, W, lambda1 = lambda1, lambda2 = lambda2, n_cores = 1) # Edge summary for a list of CVN models cvn_edge_summary(fit) # Edge summary for a single CVN fit2 <- extract_cvn(fit, id = 2) cvn_edge_summary(fit2)data(grid) W <- create_weight_matrix("grid", 3, 3) # lambdas: lambda1 = c(1, 1.5) lambda2 = .2 fit <- CVN(grid, W, lambda1 = lambda1, lambda2 = lambda2, n_cores = 1) # Edge summary for a list of CVN models cvn_edge_summary(fit) # Edge summary for a single CVN fit2 <- extract_cvn(fit, id = 2) cvn_edge_summary(fit2)
cvn objectDetermines a given information criteria for a cvn object,
see CVN.
determine_information_criterion_cvn(cvn, gamma = 0.5)determine_information_criterion_cvn(cvn, gamma = 0.5)
cvn |
A CVN object, see |
gamma |
The gamma value for the eBIC (default: 0.5) |
path <- system.file("cvnfit.rda", package = "CVN") load(path) determine_information_criterion_cvn(fit, gamma = 0.7)path <- system.file("cvnfit.rda", package = "CVN") load(path) determine_information_criterion_cvn(fit, gamma = 0.7)
Function that extracts one CVN if the CVN object contains more than one. Its helpful when just one tuning parameter constellation wants to be, e.g., plotted.
extract_cvn(cvn, id)extract_cvn(cvn, id)
cvn |
A CVN object, see |
id |
Integer; Which id from the CVN object should be extracted |
A CVN object
## Not run: # Example code of usage (not run because of longer running time) data(grid) W <- create_weight_matrix("grid", 3, 3) fit <- CVN(grid, W, n_cores = 1, lambda1 = c(0.5, 1), lambda2 = c(0.1, 0.5)) (fit2 <- extract_cvn(fit, id = 2)) ## End(Not run)## Not run: # Example code of usage (not run because of longer running time) data(grid) W <- create_weight_matrix("grid", 3, 3) fit <- CVN(grid, W, n_cores = 1, lambda1 = c(0.5, 1), lambda2 = c(0.1, 0.5)) (fit2 <- extract_cvn(fit, id = 2)) ## End(Not run)
Finds the 'core graph', i.e., those edges that are present in all of the estimated graphs
find_core_graph(cvn)find_core_graph(cvn)
cvn |
A |
A list of adjacency matrix, one for each value of (lambda1, lambda2)
path <- system.file("cvnfit.rda", package = "CVN") load(path) find_core_graph(fit)path <- system.file("cvnfit.rda", package = "CVN") load(path) find_core_graph(fit)
Function that finds edges that are only present in one subgraph of the CVN model.
find_unique_edges(cvn)find_unique_edges(cvn)
cvn |
A |
A list of adjacency matrix, one for each value of (lambda1, lambda2), showing the edges that are unique for each single subgraph.
path <- system.file("cvnfit.rda", package = "CVN") load(path) ue <- find_unique_edges(fit) # Graph 3 has unique edges ue[[1]][[3]]path <- system.file("cvnfit.rda", package = "CVN") load(path) ue <- find_unique_edges(fit) # Graph 3 has unique edges ue[[1]][[3]]
Solving Generalized LASSO with fixed
Solves efficiently the generalized LASSO problem of the form
where and are -dimensional vectors and
is a -matrix where .
We solve this optimization problem using an adaption of the ADMM
algorithm presented in Zhu (2017).
genlassoRcpp(Y, W, m, eta1, eta2, a, rho, max_iter, eps, truncate)genlassoRcpp(Y, W, m, eta1, eta2, a, rho, max_iter, eps, truncate)
Y |
The |
W |
The weight matrix |
m |
The number of graphs |
eta1 |
Equals |
eta2 |
Equals |
a |
Value added to the diagonal of |
rho |
The ADMM's parameter |
max_iter |
Maximum number of iterations |
eps |
Stopping criterion. If differences
are smaller than |
truncate |
Values below |
The estimated vector
Louis Dijkstra
Zhu, Y. (2017). An Augmented ADMM Algorithm With Application to the Generalized Lasso Problem. Journal of Computational and Graphical Statistics, 26(1), 195–204. https://doi.org/10.1080/10618600.2015.1114491
Data generated for 9 graphs in total, organized in a grid of
(3x3). Each data set has 10 variables drawn from a multinormal distribution given
9 adjacency matrices reflecting a graph structure that follows an Erdös-Rényi graph
with probability 0.5. The number of edges that are removed or added
in each step of the x- and y direction is 2.
data(grid)data(grid)
cvn ObjectReturns the structural Hamming distances
hamming_distance(cvn, verbose = TRUE)hamming_distance(cvn, verbose = TRUE)
cvn |
A |
verbose |
If |
A list of symmetric matrices. Each matrix contains the structural
Hamming distances between the different graphs. Each item in the
list corresponds to one pair
Returns the structural Hamming distance between multiple graphs
hamming_distance_adj_matrices(adj_matrices)hamming_distance_adj_matrices(adj_matrices)
adj_matrices |
A list of adjacency matrices |
Matrix of Hamming distances
path <- system.file("cvnfit.rda", package = "CVN") load(path) hamming_distance_adj_matrices(fit$adj_matrices[[1]])path <- system.file("cvnfit.rda", package = "CVN") load(path) hamming_distance_adj_matrices(fit$adj_matrices[[1]])
Returns a heatmap of the weight matrix
hd_weight_matrix( W, title = "", legend_label = "weight", add_counts_to_cells = TRUE, add_ticks_labels = TRUE, t = -6, r = -8 )hd_weight_matrix( W, title = "", legend_label = "weight", add_counts_to_cells = TRUE, add_ticks_labels = TRUE, t = -6, r = -8 )
W |
Weight matrix |
title |
Title plot (Default is none) |
legend_label |
Title of the legend (Default: "weight") |
add_counts_to_cells |
If |
add_ticks_labels |
If |
t |
Distance between tick labels and x-axis (Default: -6) |
r |
Distance between tick labels and y-axis (Default: -8) |
A heatmap plot
W_uniform <- round(create_weight_matrix(type="uniform-random", 3, 2), 2) hd_weight_matrix(W_uniform, title = "2 external covariates with 3 and 2 categories respectively")W_uniform <- round(create_weight_matrix(type="uniform-random", 3, 2), 2) hd_weight_matrix(W_uniform, title = "2 external covariates with 3 and 2 categories respectively")
Estimates a graph for which there are no observation based on a previously fitted CVN model
interpolate(cvn, weights, truncate = NULL)interpolate(cvn, weights, truncate = NULL)
cvn |
A CVN fit with |
weights |
A vector of length |
truncate |
Truncation value. When a value in the precision matrix is
considered 0. If |
A 'cvn_interpolated' object, which is a list with
adj_matrices |
A list of adjacency matrix. One for each pair
of |
m |
Number of graphs |
p |
Number of variables |
weights |
The weights used for interpolation |
truncate |
Truncation value |
n_lambda_values |
Total number of |
results. It consists of two columns:
lambda1 |
|
lambda2 |
|
path <- system.file("cvnfit.rda", package = "CVN") load(path) interpolate <- interpolate(fit, c(0,0,0,0,0,0,0,0.5,0.5), truncate = 0.05) fit10 <- combine_cvn_interpolated(fit, interpolate) fit10 <- visnetwork_cvn(fit10) if (requireNamespace("htmltools", quietly = TRUE)) { htmltools::browsable(htmltools::tagList( htmltools::div(style = "display: grid; grid-template-columns: repeat(3, 1fr); column-gap: 1px; row-gap: -10px", fit10$plots[[1]][8:10]))) } else { fit10$plots[[1]][8:10] }path <- system.file("cvnfit.rda", package = "CVN") load(path) interpolate <- interpolate(fit, c(0,0,0,0,0,0,0,0.5,0.5), truncate = 0.05) fit10 <- combine_cvn_interpolated(fit, interpolate) fit10 <- visnetwork_cvn(fit10) if (requireNamespace("htmltools", quietly = TRUE)) { htmltools::browsable(htmltools::tagList( htmltools::div(style = "display: grid; grid-template-columns: repeat(3, 1fr); column-gap: 1px; row-gap: -10px", fit10$plots[[1]][8:10]))) } else { fit10$plots[[1]][8:10] }
for inner-ADMM for the -update stepThe -update step requires
us to solve a special Generalized LASSO problem of the form
where and are -dimensional vectors and
is a -matrix where .
We solve this optimization problem using an adaption of the ADMM
algorithm presented in Zhu (2017).
This algorithm requires the choice of a matrix such that
is positive semidefinite. In order to optimize the ADMM,
we choose the matrix to be diagonal with a fixed value .
This function determines the smallest value of such that
is indeed positive semidefinite. We do this be determining
the largest eigenvalue
matrix_A_inner_ADMM(W, eta1, eta2)matrix_A_inner_ADMM(W, eta1, eta2)
W |
Weight matrix |
eta1, eta2
|
The values |
Value of
Louis Dijkstra
Zhu, Y. (2017). An Augmented ADMM Algorithm With Application to the
Generalized Lasso Problem. Journal of Computational and Graphical Statistics,
26(1), 195–204.
doi:10.1080/10618600.2015.1114491
Returns a heat map of the distance matrix for a particular CVN
plot_hamming_distances( distance_matrix, absolute = TRUE, limits = c(NA, NA), title = "", legend_label = "Hamming Distance", add_counts_to_cells = TRUE, add_ticks_labels = TRUE, t = -6, r = -8 )plot_hamming_distances( distance_matrix, absolute = TRUE, limits = c(NA, NA), title = "", legend_label = "Hamming Distance", add_counts_to_cells = TRUE, add_ticks_labels = TRUE, t = -6, r = -8 )
distance_matrix |
Symmetric matrix with distances |
absolute |
If |
limits |
The limits for the values of the Hamming distance |
title |
Title plot (Default is none) |
legend_label |
Title of the legend (Default: "Hamming Distance") |
add_counts_to_cells |
If |
add_ticks_labels |
If |
t |
Distance between tick labels and x-axis (Default: -6) |
r |
Distance between tick labels and y-axis (Default: -8) |
A heatmap plot
path <- system.file("cvnfit.rda", package = "CVN") load(path) hd <- hamming_distance(fit, verbose = FALSE) plot_hamming_distances(hd$distance[[1]])path <- system.file("cvnfit.rda", package = "CVN") load(path) hd <- hamming_distance(fit, verbose = FALSE) plot_hamming_distances(hd$distance[[1]])
Creates all the heatmaps for a CVN, a heatmap for each
pair of
plot_hamming_distances_cvn( cvn, absolute = TRUE, same_range = TRUE, titles = rep("", cvn$n_lambda_values), legend_label = "Hamming Distance", add_counts_to_cells = TRUE, add_ticks_labels = TRUE, t = -6, r = -8, verbose = TRUE )plot_hamming_distances_cvn( cvn, absolute = TRUE, same_range = TRUE, titles = rep("", cvn$n_lambda_values), legend_label = "Hamming Distance", add_counts_to_cells = TRUE, add_ticks_labels = TRUE, t = -6, r = -8, verbose = TRUE )
cvn |
A |
absolute |
If |
same_range |
If |
titles |
Title of the plots (Default is none) |
legend_label |
Title of the legend (Default: "Hamming Distance") |
add_counts_to_cells |
If |
add_ticks_labels |
If |
t |
Distance between tick labels and x-axis (Default: -6) |
r |
Distance between tick labels and y-axis (Default: -8) |
verbose |
If |
List of plots
path <- system.file("cvnfit.rda", package = "CVN") load(path) plot_hamming_distances_cvn(fit)path <- system.file("cvnfit.rda", package = "CVN") load(path) plot_hamming_distances_cvn(fit)
Returns a heat map of the AIC or BIC for a fitted CVN
plot_information_criterion( cvn, criterion = c("bic", "aic", "ebic"), use_gammas = TRUE, show_minimum = TRUE, title = "", xlabel = NULL, ylabel = NULL, legend_label = NULL, limits = c(NA, NA) )plot_information_criterion( cvn, criterion = c("bic", "aic", "ebic"), use_gammas = TRUE, show_minimum = TRUE, title = "", xlabel = NULL, ylabel = NULL, legend_label = NULL, limits = c(NA, NA) )
cvn |
Fitted CVN, see |
criterion |
The information criterion, must be either |
use_gammas |
If |
show_minimum |
If |
title |
Title plot (Default is none) |
xlabel |
Label for the |
ylabel |
Label for the |
legend_label |
Title for the legend. Default depends on |
limits |
The limits for the values of the Hamming distance |
A heatmap plot
data(grid) m <- 9 W <- create_weight_matrix(type="grid", 3, 3) cvn <- CVN(grid, W, lambda1 = 1:2, lambda2 = .5, n_cores = 1) cvn$results # The smaller the IC value, the better the fit. plot_information_criterion(cvn, criterion = "aic") plot_information_criterion(cvn, criterion = "bic") plot_information_criterion(cvn, criterion = "ebic")data(grid) m <- 9 W <- create_weight_matrix(type="grid", 3, 3) cvn <- CVN(grid, W, lambda1 = 1:2, lambda2 = .5, n_cores = 1) cvn$results # The smaller the IC value, the better the fit. plot_information_criterion(cvn, criterion = "aic") plot_information_criterion(cvn, criterion = "bic") plot_information_criterion(cvn, criterion = "ebic")
This function requires the igraph package to be installed.
plot_weight_matrix(W, k, l)plot_weight_matrix(W, k, l)
W |
The weight matrix which equals an adjacency matrix |
k |
Number of categories in the first external covariate |
l |
Number of categories in the second external covariate |
An igraph object
# Requires to have the igraph package to be installed W <- create_weight_matrix(type = "full", k = 2, l = 3) plot_weight_matrix(W, k=2, l=3)# Requires to have the igraph package to be installed W <- create_weight_matrix(type = "full", k = 2, l = 3) plot_weight_matrix(W, k=2, l=3)
Custom plot method for CVN objects.
## S3 method for class 'cvn' plot(x, ...)## S3 method for class 'cvn' plot(x, ...)
x |
|
... |
Additional arguments to pass to |
CVN
path <- system.file("cvnfit.rda", package = "CVN") load(path) fit <- plot(fit) fit$plots[[1]][[4]]path <- system.file("cvnfit.rda", package = "CVN") load(path) fit <- plot(fit) fit$plots[[1]][[4]]
Print contents of CVN object
## S3 method for class 'cvn' print(x, ...)## S3 method for class 'cvn' print(x, ...)
x |
Object of class 'CVN' |
... |
Additional arguments to pass |
path <- system.file("cvnfit.rda", package = "CVN") load(path) print(fit)path <- system.file("cvnfit.rda", package = "CVN") load(path) print(fit)
Returns the relative difference between precision matrix
(parameter Theta_new) and (parameter Theta_old).
relative_difference_precision_matrices(Theta_new, Theta_old)relative_difference_precision_matrices(Theta_new, Theta_old)
Theta_new |
A list with matrices with the updated values of |
Theta_old |
A list with matrices with the old values of |
This is used for checking whether the stopping condition has been met.
The relative difference between and
visNetwork
A subset of edges can be assign a different thickness or color.
set_attributes_to_edges_visnetwork( edges, subset_edges, width = c(NA, NA), color = c(NULL, NULL) )set_attributes_to_edges_visnetwork( edges, subset_edges, width = c(NA, NA), color = c(NULL, NULL) )
edges |
A data.frame create by |
subset_edges |
A list with the elements |
width |
Vector with two values. The first is assigned to the
edges in the subset given by |
color |
Vector with two values. The first is assigned to the
edges in the subset given by |
A data frame that can be used by the visNetwork package
nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)
Function that removes most of the items to make the CVN object more memory sufficient. This is especially important when the graphs are rather larger
strip_cvn(cvn)strip_cvn(cvn)
cvn |
Object of class 'CVN' |
Reduced CVN where Theta, data and Sigma
are removed
-update StepA C implementation of the -update step. We
solve a generalized LASSO problem repeatedly for each of the
individual edges
updateZRcpp(m, p, Theta, Y, W, eta1, eta2, a, rho, max_iter, eps, truncate)updateZRcpp(m, p, Theta, Y, W, eta1, eta2, a, rho, max_iter, eps, truncate)
m |
The number of graphs |
p |
The number of variables |
Theta |
A list of matrices with the |
Y |
A list of matrices with the |
W |
The weight matrix |
eta1 |
Equals |
eta2 |
Equals |
a |
Value added to the diagonal of |
rho |
The ADMM's parameter |
max_iter |
Maximum number of iterations |
eps |
Stopping criterion. If differences
are smaller than |
truncate |
Values below |
The estimated vector
Louis Dijkstra
visNetwork plotCreates a visNetwork plot given a list of
nodes and edges. The nodes data frame can be
created with create_nodes_visnetwork;
the edges with create_edges_visnetwork.
In order to highlight edges, you can use
set_attributes_to_edges_visnetwork.
visnetwork( nodes, edges, node_titles = nodes$id, title = "", igraph_layout = "layout_in_circle" )visnetwork( nodes, edges, node_titles = nodes$id, title = "", igraph_layout = "layout_in_circle" )
nodes |
A data frame with rows equal to the number of nodes with columns "id" and "title".
Can be created with |
edges |
A data frame with columns "from" and "to. Each row represents an edge between two nodes (integer) |
node_titles |
Vector with title of the nodes (Default: |
title |
A list with |
igraph_layout |
igraph layout (default: layout_in_circle) |
A visNetwork plot
nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)nodes <- create_nodes_visnetwork(n_nodes = 5, labels = LETTERS[1:5]) adj_matrix <- matrix(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0), ncol = 5) edges <- create_edges_visnetwork(adj_matrix) shared_edges <- data.frame(from = c(1,2), to = c(4, 3)) edges <- set_attributes_to_edges_visnetwork(edges, subset_edges = shared_edges, width = c(3, .5), color = c("red", "blue")) visnetwork(nodes, edges)
visNetwork plots for a CVN objectCreates all visNetwork plots, see visnetwork,
for all graphs in a cvn object
visnetwork_cvn( cvn, node_titles = 1:cvn$p, titles = lapply(1:cvn$n_lambda_values, function(i) sapply(1:cvn$m, function(j) "")), show_core_graph = TRUE, width = c(3, 1), color = c("red", "blue"), igraph_layout = "layout_in_circle", verbose = TRUE )visnetwork_cvn( cvn, node_titles = 1:cvn$p, titles = lapply(1:cvn$n_lambda_values, function(i) sapply(1:cvn$m, function(j) "")), show_core_graph = TRUE, width = c(3, 1), color = c("red", "blue"), igraph_layout = "layout_in_circle", verbose = TRUE )
cvn |
A |
node_titles |
Vector with title of the nodes (Default: |
titles |
A list with |
show_core_graph |
Shall the core graph be visualized (Default = TRUE) |
width |
Edge width of the core graph |
color |
String vector with two colors. The first color marks the edges in the core graph (Default: c("red", "blue")) |
igraph_layout |
igraph layout (default: layout_in_circle) |
verbose |
Verbose (Default: |
The cvn input which is extended by the list element 'plots'
## Not run: path <- system.file("cvnfit.rda", package = "CVN") load(path) fit_plot <- visnetwork_cvn(fit) fit_plot$plots[[1]][[1]] ## End(Not run)## Not run: path <- system.file("cvnfit.rda", package = "CVN") load(path) fit_plot <- visnetwork_cvn(fit) fit_plot$plots[[1]][[1]] ## End(Not run)