Learn R Programming

cglasso (version 1.1.2)

to_graph: Create Undirected Graphs

Description

to_graph’ function is used to create an undirected graph from a fitted model object.

Usage

to_graph(object, nrho = 1L, weighted = FALSE, isolated = FALSE)

Arguments

object

a fitted model object.

nrho

integer specifying the model used to create the undireced graph. Default is 1L.

weighted

flag specifying whether to create a weighted graph from the adjacency matrix. Default is FALSE.

isolated

flag specifying whether the isolated vertices are removed from the graph. Default is FALSE, i.e. the isolated vertices are removed.

Value

to_graph’ returns an igraph object.

Details

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).

References

Augugliaro, L., Abbruzzo, A. and Vinciotti, V. (2018). \(\ell_1\)-Penalized gaussian graphical model. Biostatistics (to appear).

See Also

glasso, codemglasso and codecglasso. For more details about the object of class ‘igraph’, the interested reader is referred to the package igraph.

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab