This function will extract an estimated matrix, and will either return a single matrix for single group models or a list of such matrices for multiple group models.
getmatrix(x, matrix, group, threshold = FALSE, alpha = 0.01,
adjust = c("none", "holm", "hochberg", "hommel",
"bonferroni", "BH", "BY", "fdr"), mode = c("tested",
"all"), diag = TRUE, time)A matrix of parameter estimates, or a list of such matrices for multiple group models.
A psychonetrics model.
String indicating the matrix to be extracted. For ri_clpm / ri_clpn models this may also be a block name such as "omega_zeta_within" or "omega_zeta_between"; see Details.
Integer indicating the group for the matrix to be extracted.
Logical. Should the matrix be thresholded (non-significant values set to zero? Can also be a value with an absolute threshold below which parameters are set to zero.)
Significance level to use.
p-value adjustment method to use. See p.adjust.
Mode for adjusting for multiple comparisons. Should all parameters be considered as the total number of tests or only the tested parameters (parameters of interest)?
Set to FALSE to set diagonal elements to zero.
Only for ri_clpm / ri_clpn models: the wave whose block should be returned, either an integer or a column name of the design matrix. See Details.
Sacha Epskamp
RI-CLPM / RI-CLPN blocks. A model made with ri_clpm or ri_clpn is built on the lvm framework, so its model matrices span all waves at once: the \(m\) within-person components of each of the \(T\) waves, followed by the \(m\) random intercepts. The quantities of interest are the \(m \times m\) blocks of those matrices, which can be addressed directly with the same matrix names that panelvar and panelgvar use, together with the time argument:
getmatrix(x, "beta", time = t) -- the temporal (cross-lagged) network of the transition from wave \(t\) to wave \(t+1\), with rows the outcome and columns the predictor, exactly as in panelvar.
getmatrix(x, "PDC", time = t) -- the partial directed correlations of that transition (rows = from, columns = to), the form that feeds directly into qgraph. The RI-CLPM has no PDC parameters of its own, so these are derived from the temporal block and the innovation precision of the target wave \(t+1\); for a fully stationary model this reproduces the panelvar PDC exactly.
getmatrix(x, "omega_zeta_within", time = t) -- the contemporaneous network of wave \(t\). Note that at time = 1 this is the exogenous wave-1 block, which the RI-CLPM leaves free, and not an innovation structure. The other parameterizations (sigma_, kappa_, lowertri_, rho_, SD_, delta_zeta_within) work the same way, and the plain name plus time (e.g. "omega_zeta") is accepted as a shorthand.
getmatrix(x, "omega_zeta_between") -- the between-person (random intercept) network. No time is given or accepted, since the random intercepts do not vary over waves.
getmatrix(x, "nu", time = t) (or "nu_within") -- the wave-specific intercepts, and getmatrix(x, "nu_between") -- the random-intercept means that ri_clpm_stationary(x, "intercepts") frees.
Blocks are returned with the variable names of the design matrix as row and column names. Omitting time returns a named list with one block per wave; waves whose parameters were equated by ri_clpm_stationary are collapsed into one entry, so a stationary structure yields a single block rather than several identical copies. Supplying a plain matrix name without time (for example getmatrix(x, "beta")) returns the full latent-sized matrix as in earlier versions.
Thresholding is applied to the full matrix and the block is then cut out of the result, so a thresholded block is exactly the corresponding submatrix of the thresholded full matrix and the multiple-comparison adjustment is unaffected by which block is requested. diag = FALSE, in contrast, applies to the block, so that it removes the autoregressive effects of a temporal block (which do not lie on the diagonal of the full beta matrix).
# Load bfi data from psych package:
library("psychTools")
data(bfi)
# Also load dplyr for the pipe operator:
library("dplyr")
# Let's take the agreeableness items, and gender:
ConsData <- bfi %>%
select(A1:A5, gender) %>%
na.omit # Let's remove missingness (otherwise use Estimator = "FIML)
# Define variables:
vars <- names(ConsData)[1:5]
# Let's fit a full GGM:
mod <- ggm(ConsData, vars = vars, omega = "full")
# Run model:
mod <- mod %>% runmodel
# Obtain network:
mod %>% getmatrix("omega")
Run the code above in your browser using DataLab