Learn R Programming

cglasso (version 1.1.2)

plot: Plot for ‘glasso’ and ‘cglasso’ Object

Description

The method functions ‘plot.glasso’ and ‘plot.mglasso’ produce plots to study the sequence of models estimated by glasso, mglasso or cglasso.

Usage

# S3 method for glasso
plot(x, typeplot = c("path", "graph"),
     gof, diag = FALSE, nrho, weighted = FALSE,
     isolated = FALSE, …)

# S3 method for mglasso plot(x, typeplot = c("path", "graph"), gof, diag = FALSE, nrho, weighted = FALSE, isolated = FALSE, …)

Arguments

x

a fitted model object.

typeplot

a string specifying the produced plot.

gof

an object with class ‘gof’. See examples below.

diag

flag specifying whether the diagonal elements of the concentration matrix are plotted.

nrho

availables only if ‘typeplot = graph’: integer specifying the model used to procude the ‘igraph’ object. This argument is overwritten if ‘gof’ is available. See examples below.

weighted

argument availables only if ‘typeplot = graph’. Flag specifying whether to create a weighted graph.

isolated

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

additional arguments passed to the method function ‘plot.default’.

Value

If typeplot = "graph" then the igraph object is returned (see example below).

Details

The plot produced by the method functions ‘plot.glasso’ and ‘plot.mglasso’ depends on the argument ‘typeplot’.

If ‘typeplot = path’, the regularization paths are produced; in this case, if an object with class ‘gof’ is passed by the argument ‘gof’, then a vertical dashed line is added to identify the optimal \(\rho\)-value.

If ‘typeplot = graph’, the method functions ‘plot.glasso’ and ‘plot.mglasso’ produce the undirected graph associated to the model specified by the argument ‘nrho’. If an object with class ‘gof’ is passed by ‘gof’, the undirected graph of the model selected by the function ‘aic’, ‘bic’ or ‘ebic’ is produced.

See Also

glasso, mglasso and cglasso.

Examples

Run this code
# NOT RUN {
library("cglasso")
set.seed(123)

#################
# cglasso model #
#################
n <- 100L
p <- 5L
mu <- rep.int(0L, times = p)
X <- rdatacggm(n = n, mu = mu, probr = 0.05)
out <- cglasso(X = X, nrho = 100L)
out_aic <- aic(out)

# plotting the regularization paths + 'gof' object
plot(out, typeplot = "path")
plot(out, typeplot = "path", gof = out_aic)

# plotting the graph associated to the fitted model
# specified by 'nrho'
out_graph <- plot(out, typeplot = "graph", nrho = 10L)
out_graph
# plotting the graph associated to the fitted model
# specified by 'gof'
out_graph <- plot(out, typeplot = "graph", gof = out_aic)
out_graph

#################
# mglasso model #
#################
R <- event(X)
X <- as.matrix(X)
X[R == 1L] <- NA
out <- mglasso(X = X, nrho = 100L)
out_aic <- aic(out)

# plotting the regularization paths + 'gof' object
plot(out, typeplot = "path")
plot(out, typeplot = "path", gof = out_aic)

# plotting the graph associated to the fitted model
# specified by 'nrho'
out_graph <- plot(out, typeplot = "graph", nrho = 10L)
out_graph
# plotting the graph associated to the fitted model
# specified by 'gof'
out_graph <- plot(out, typeplot = "graph", gof = out_aic)
out_graph

#################
# glasso model #
#################
X <- MASS::mvrnorm(n = n, mu = mu, Sigma = diag(p))
out <- glasso(X, nrho = 100L)
out_aic <- aic(out)

# plotting the regularization paths + 'gof' object
plot(out, typeplot = "path")
plot(out, typeplot = "path", gof = out_aic)

# plotting the graph associated to the fitted model
# specified by 'nrho'
out_graph <- plot(out, typeplot = "graph", nrho = 10L)
out_graph
# plotting the graph associated to the fitted model
# specified by 'gof'
out_graph <- plot(out, typeplot = "graph", gof = out_aic)
out_graph
# }

Run the code above in your browser using DataLab