A wrapper around qgraph that draws one or more model matrices of a psychonetrics model as networks, in the spirit of the plot method for estimateNetwork objects in the bootnet package: the same overwritten defaults (cut = 0, theme = "colorblind", layout = "spring", parallelEdge = TRUE) and everything else passed on to qgraph through .... Which matrices are plotted, and how, is derived from the model, so that a plain plot(mod) gives a sensible picture for every model family.
# S3 method for psychonetrics
plot(x, matrix, ..., time, group,
threshold = FALSE, alpha = 0.01,
adjust = c("none", "holm", "hochberg", "hommel",
"bonferroni", "BH", "BY", "fdr"),
mode = c("tested", "all"),
covariances = FALSE, labels, layout = "spring",
cut = 0, theme = "colorblind", parallelEdge = TRUE,
titles = TRUE, equalLayout = TRUE, verbose = TRUE)Invisibly, the qgraph object of the plot, or a named list of such objects when more than one panel is drawn.
A psychonetrics model.
A character vector of matrices to plot; each element becomes a panel, in the given order. Unlike getmatrix, more than one matrix may be given. When omitted, a default is chosen from the model family (see Details).
Arguments passed to qgraph (or to qgraph.loadings for a factor loading matrix, or to semPaths for a latent variable model). Anything given here overrides the defaults set by this method.
Only for ri_clpm / ri_clpn models: the wave whose block should be plotted, either an integer or a column name of the design matrix. When omitted, every wave gets its own panel. See getmatrix.
The group(s) to plot, as labels or numbers. Defaults to all groups, one row of panels per group.
Logical (or a numeric absolute threshold), as in getmatrix: should non-significant edges be set to zero?
Significance level used when threshold = TRUE.
p-value adjustment method used when threshold = TRUE. See p.adjust.
Mode for adjusting for multiple comparisons, as in getmatrix.
Logical. By default, covariance matrices are drawn as correlation networks and precision matrices as partial correlation networks, so that the edge widths are comparable across differently scaled variables. Set to TRUE to draw the unstandardized matrix instead, with self-loops showing the diagonal (the variances, respectively the diagonal of the precision matrix).
Node labels. Defaults to the variable names of the model. May be a character vector (used for every panel) or a list with one element per panel.
The qgraph layout. Defaults to "spring".
The qgraph cut value. Defaults to 0 (no cut), as in bootnet.
The qgraph theme. Defaults to "colorblind".
Should reciprocal directed edges be drawn as parallel lines? Defaults to TRUE.
TRUE (default) to title each panel with what it shows, FALSE for no titles, or a character vector with one title per panel.
Logical. When several panels share the same nodes, should they be constrained to a common layout (through averageLayout) so that they are visually comparable? Defaults to TRUE. Ignored when layout is given as a matrix.
Logical, should messages about how a matrix is being drawn be printed?
Sacha Epskamp
Default matrices. When matrix is omitted, the matrices are chosen from the model family, in the parameterization that was estimated:
varcov family (ggm, precision, corr, ...): the (co)variance matrix itself, one panel.
Ising and BlumeCapel: the network omega, one panel.
var1 / gvar: two panels, the temporal and the contemporaneous network.
panelvar / panelgvar, dlvm1, ml_var1 and ml_lvm: three panels, the temporal, the contemporaneous (within-person) and the between-person network.
tsdlvm1: the temporal and the contemporaneous network.
ml_varcov: the within-person and the between-person network.
meta_varcov: the pooled (co)variance matrix.
ri_clpm / ri_clpn: the temporal, contemporaneous and between-person blocks (see getmatrix); one panel per wave, with waves that were equated by ri_clpm_stationary collapsed into one.
lnm, rnm and lrnm: the latent and/or residual network.
Any other lvm model has no natural network representation, so the full path diagram is drawn with semPaths from the semPlot package (via tolavaan). Give a matrix to plot a model matrix as a network instead.
If the model uses the "PDC" temporal parameterization, the temporal panel shows PDC rather than beta.
How each matrix is drawn. The type of graph follows from the matrix:
omega (Gaussian graphical model): an undirected network of partial correlations.
kappa (precision): an undirected network. Standardized to partial correlations unless covariances = TRUE.
sigma (covariance): a network with two arrowheads per edge. Standardized to correlations unless covariances = TRUE, in which case the variances are added as self-loops.
rho (correlation): a network with two arrowheads per edge.
beta and PDC (temporal): a directed network, with the autoregressive effects drawn as self-loops.
lambda (factor loadings): a reflective measurement diagram, drawn with qgraph.loadings.
lowertri and exo_cholesky (Cholesky decompositions) have no network interpretation and raise an error; plot the corresponding (co)variance or partial correlation matrix instead.
Diagonal scaling matrices (delta, SD), mean vectors (mu, nu, tau) and the Ising inverse temperature (beta) are not networks and raise an error.
getmatrix, CIplot, qgraph
# \donttest{
# Simulate data from a chain graph:
set.seed(1)
omega <- matrix(0, 5, 5)
for (i in 1:4) omega[i, i + 1] <- omega[i + 1, i] <- 0.35
Sigma <- cov2cor(solve(diag(5) - omega))
data <- as.data.frame(MASS::mvrnorm(500, rep(0, 5), Sigma))
names(data) <- paste0("V", 1:5)
# Fit a GGM and plot it:
mod <- runmodel(ggm(data))
plot(mod)
# Only the significant edges:
plot(mod, threshold = TRUE)
# The same data as a covariance model: drawn as a correlation network ...
mod2 <- runmodel(varcov(data, type = "cov"))
plot(mod2)
# ... or as covariances, with the variances as self-loops:
plot(mod2, covariances = TRUE)
# qgraph arguments are passed through:
plot(mod, layout = "circle", vsize = 12, labels = paste0("x", 1:5))
# }
Run the code above in your browser using DataLab