to_graph {cglasso} | R Documentation |
‘to_graph
’ function is used to create an undirected graph from a fitted model object.
to_graph(object, nrho = 1L, weighted = FALSE, isolated = FALSE)
object |
a fitted model object. |
nrho |
integer specifying the model used to create the undireced graph. Default is |
weighted |
flag specifying whether to create a weighted graph from the adjacency matrix. Default is |
isolated |
flag specifying whether the isolated vertices are removed from the graph. Default is |
The adjacency matrix ‘object$Adj[, , nrho]
’ is passed to graph_from_adjacency_matrix
, available in the R package igraph, to create the undirected graph estimated by the glasso, mglasso, cglasso model or using the function mle
. If ‘weighted = TRUE
’ then the precision matrix ‘object$Tht[, , nrho]
’ is used to create a weighted undirected graph. In this case, an edge associated to a negative partial correlation coefficient is plotted using a dashed line (see examples below).
‘to_graph
’ returns an igraph object.
Luigi Augugliaro (luigi.augugliaro@unipa.it)
Augugliaro, L., Abbruzzo, A. and Vinciotti, V. (2018). l1-Penalized gaussian graphical model. Biostatistics (to appear).
glasso
, codemglasso and codecglasso. For more details about the object of class ‘igraph
’, the interested reader is referred to the package igraph.
library("cglasso") set.seed(123) ################# # cglasso model # ################# n <- 100L p <- 10L mu <- rep.int(0L, times = p) X <- rdatacggm(n = n, mu = mu, probr = 0.05) out <- cglasso(X) out # creating the undirected graph associated to the fitted # model number 3 graph_cglasso <- to_graph(out, nrho = 3L) graph_cglasso V(graph_cglasso) E(graph_cglasso) plot(graph_cglasso, layout = layout_in_circle(graph_cglasso)) # creating the weighted graph associated to the fitted # model number 3 graph_cglasso <- to_graph(out, nrho = 3L, weighted = TRUE) graph_cglasso E(graph_cglasso) E(graph_cglasso)$weight plot(graph_cglasso, layout = layout_in_circle(graph_cglasso)) ################# # mglasso model # ################# R <- event(X) X <- as.matrix(X) X[R == 1L] <- NA out <- mglasso(X) out # creating the undirected graph associated to the fitted # model number 3 graph_mglasso <- to_graph(out, nrho = 3L) graph_mglasso V(graph_mglasso) E(graph_mglasso) plot(graph_mglasso, layout = layout_in_circle(graph_mglasso)) # creating the weighted graph associated to the fitted # model number 3 graph_mglasso <- to_graph(out, nrho = 3L, weighted = TRUE) graph_mglasso E(graph_mglasso) E(graph_mglasso)$weight plot(graph_mglasso, layout = layout_in_circle(graph_mglasso)) ################# # glasso model # ################# n <- 100L p <- 10L X <- matrix(rnorm(n * p), nrow = n, ncol = p) out <- glasso(X) out # creating the undirected graph associated to the fitted # model number 3 graph_cglasso <- to_graph(out, nrho = 3L) graph_cglasso V(graph_cglasso) E(graph_cglasso) plot(graph_cglasso, layout = layout_in_circle(graph_cglasso)) # creating the weighted graph associated to the fitted # model number 3 graph_cglasso <- to_graph(out, nrho = 3L, weighted = TRUE) graph_cglasso E(graph_cglasso) E(graph_cglasso)$weight plot(graph_cglasso, layout = layout_in_circle(graph_cglasso))