Title: | Modeling Moderated Networks |
---|---|
Description: | Methods for modeling moderator variables in cross-sectional, temporal, and multi-level networks. Includes model selection techniques and a variety of plotting functions. Implements the methods described by Swanson (2020) <https://www.proquest.com/openview/d151ab6b93ad47e3f0d5e59d7b6fd3d3>. |
Authors: | Trevor Swanson [aut, cre] |
Maintainer: | Trevor Swanson <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.9.0.9000 |
Built: | 2025-03-01 03:36:21 UTC |
Source: | https://github.com/tswanson222/modnets |
Composite scores on the Big 5 personality dimensions and gender. Adapted from
the bfi
data in the psychTools
package.
bfiDat
bfiDat
A data frame with six variables representing composite scores
for participants across the Big 5 personality dimensions as well as gender.
A
is Agreeableness, C
is conscientiousness, E
is
extraversion, N
is neuroticism, and O
is openness to
experience. For a given participant, each value represents the mean of 5
self report items from the associated scale. Response values range from
0
to 6
. In total, 7 negatively-worded items were reverse
scored before calculating scale composites. gender
is a binary
variable coded such that 0 = Males
, and 1 = Females
.
The items are from the IPIP (Goldberg, 1999). The data are from the SAPA project (Revelle, Wilt and Rosenthal, 2010) , collected Spring, 2010 ( https://www.sapa-project.org/).
Goldberg, L.R. (1999) A broad-bandwidth, public domain, personality inventory measuring the lower-level facets of several five-factor models. In Mervielde, I. and Deary, I. and De Fruyt, F. and Ostendorf, F. (eds) Personality psychology in Europe. 7. Tilburg University Press. Tilburg, The Netherlands.
Revelle, W., Wilt, J., and Rosenthal, A. (2010) Individual Differences in Cognition: New Methods for examining the Personality-Cognition Link In Gruszka, A. and Matthews, G. and Szymura, B. (Eds.) Handbook of Individual Differences in Cognition: Attention, Memory and Executive Control, Springer.
Follows closely to the methods of bootstrapping found in the bootnet
package. An essential goal behind this function is to expand the methods in
bootnet
to encompass moderated networks.
bootNet( data, m = NULL, nboots = 10, lags = NULL, caseDrop = FALSE, rule = "OR", ci = 0.95, caseMin = 0.05, caseMax = 0.75, caseN = 10, threshold = FALSE, fits = NULL, type = "g", saveMods = TRUE, verbose = TRUE, fitCoefs = FALSE, size = NULL, nCores = 1, cluster = "mclapply", block = FALSE, maxiter = 10, directedDiag = FALSE, beepno = NULL, dayno = NULL, ... )
bootNet( data, m = NULL, nboots = 10, lags = NULL, caseDrop = FALSE, rule = "OR", ci = 0.95, caseMin = 0.05, caseMax = 0.75, caseN = 10, threshold = FALSE, fits = NULL, type = "g", saveMods = TRUE, verbose = TRUE, fitCoefs = FALSE, size = NULL, nCores = 1, cluster = "mclapply", block = FALSE, maxiter = 10, directedDiag = FALSE, beepno = NULL, dayno = NULL, ... )
data |
Dataframe or matrix. |
m |
Numeric or character string. Indicates which variable should be treated as a moderator (if any). |
nboots |
Number of bootstrapped samples. |
lags |
Numeric or logical, to indicate whether or not a temporal network
is being estimated. Maximum of 1 lag – meaningful values are either 1 or
|
caseDrop |
Logical. Determines whether to do a caseDrop bootstrap procedure or not. |
rule |
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The |
ci |
Numeric, between 0 and 1. The level of the confidence intervals estimated. Defaults at .95 |
caseMin |
Numeric. The minimum proportion of the sample that should be
taken when |
caseMax |
Numeric. The maximum proportion of the sample that should be
taken when |
caseN |
Numeric. The number of samples to draw at each sample size
tested when |
threshold |
Logical or numeric. If |
fits |
A list of all fitted models, if available. Not likely to be used. |
type |
See |
saveMods |
Logical. Determines whether or not to return all of the
fitted models – that is, all the models fit to each bootstrapped sample.
Defaults to |
verbose |
Logical. Determines whether a progress bar should be shown, as well as whether messages should be shown. |
fitCoefs |
Logical, refers to the argument in the
|
size |
Numeric. Size of sample to use for bootstrapping. Not recommended. |
nCores |
If a logical or numeric value is provided, then the
bootstrapping procedure will be parallelized across multiple CPUs. If
numeric, this will specify the number of cores to use for the procedure. If
|
cluster |
Character string to indicate which type of parallelization
function to use, if |
block |
Logical or numeric. If specified, then this indicates that
|
maxiter |
The maximum number of iterations for the algorithm to go
through before stopping. In some circumstances, iterated versions of the
model based on subsamples of the data may not be possible to fit. In these
cases, |
directedDiag |
logical |
beepno |
Character string or numeric value to indicate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
dayno |
Character string or numeric value to indicate which variable (if
any) encodes the survey number within a single day. Must be used in
conjunction with |
... |
Additional arguments. |
Can be used to perform bootstrapped network estimation, as well as perform a
case-drop bootstrap. Details on these two methods can be found in the help
page for the bootnet::bootnet
function.
The defining feature of bootNet
that differentiates it from the
resample
function when sampMethod = "bootstrap"
is that
the same model is fit at every iteration in bootNet
. The only
time that models may differ across iterations is if a threshold
is
specified. When threshold = FALSE
, then the saturated model is fit to
each bootstrapped sample. Alternatively, bootstrapping can be performed with
respect to a specific constrained model. In this case, the constrained model
(variable selection model; output of varSelect
or
resample
) can be supplied to the type
argument, and thus
this function provides a way to estimate the posterior distributions of the
nodes based on a constrained model.
In addition to expanding bootnet
to handle moderated networks, there
are also some additional features such as the capacity to perform the block
bootstrap for temporal networks via the block
argument. The block
bootstrap is highly recommended for resampling temporal networks.
Another feature of this function is that it can be used on outputs from the
resample
function. This can be used as a way to evaluate the
iterations of resample
beyond just using it for variable
selection.
A bootNet
object
Importantly, if output from the resample
function is used as
input for the bootNet
function, and the user wishes to use
the model selected by the resample
function as the comparison
to the bootstrapped results, you must add the fit0
argument to this
function. Use the fitted object in the resample
output as the
input for the undocumented fit0
argument for the
bootNet
function.
summary.bootNet, fitNetwork, varSelect,
resample, plotBoot, plotNet, net,
netInts
boot1 <- bootNet(ggmDat, 'M') summary(boot1) boot2 <- bootNet(gvarDat, 'M', lags = 1) mod1 <- varSelect(gvarDat, 'M', lags = 1) boot3 <- bootNet(gvarDat, 'M', lags = 1, type = mod1, caseDrop = TRUE) summary(boot3)
boot1 <- bootNet(ggmDat, 'M') summary(boot1) boot2 <- bootNet(gvarDat, 'M', lags = 1) mod1 <- varSelect(gvarDat, 'M', lags = 1) boot3 <- bootNet(gvarDat, 'M', lags = 1, type = mod1, caseDrop = TRUE) summary(boot3)
bootNet
objectsCurrently only works for GGMs, including the between-subjects network
returned in the mlGVAR
output.
## S3 method for class 'bootNet' summary(object, centrality = TRUE, ...) cscoef(object, cor = 0.7, ci = 0.95, first = TRUE, verbose = TRUE)
## S3 method for class 'bootNet' summary(object, centrality = TRUE, ...) cscoef(object, cor = 0.7, ci = 0.95, first = TRUE, verbose = TRUE)
object |
|
centrality |
Logical. Determines whether or not strength centrality and expected influence should be computed for output. |
... |
Additional arguments. |
cor |
Numeric value to indicate the correlation stability value to be computed. |
ci |
Numeric. Confidence interval level for CS coefficient. |
first |
Logical. Whether or not to count the first instance that a CS
statistic dips below the requisite threshold. Often times the value of this
will not affect the results. When it does, if |
verbose |
Logical. Whether to write out the full statement of the CS
coefficient in output. Set to |
Outputs correlation-stability (CS) coefficients for the case-drop bootstrap.
A table of descriptives for bootNet
objects, or
correlation-stability coefficients for the case-drop bootstrap.
boot1 <- bootNet(ggmDat, 'M') summary(boot1) boot2 <- bootNet(gvarDat, 'M', lags = 1) mod1 <- varSelect(gvarDat, 'M', lags = 1) boot3 <- bootNet(gvarDat, 'M', lags = 1, type = mod1, caseDrop = TRUE) summary(boot3)
boot1 <- bootNet(ggmDat, 'M') summary(boot1) boot2 <- bootNet(gvarDat, 'M', lags = 1) mod1 <- varSelect(gvarDat, 'M', lags = 1) boot3 <- bootNet(gvarDat, 'M', lags = 1, type = mod1, caseDrop = TRUE) summary(boot3)
Mimics the qgraph::centrality_auto
and
qgraph::clustcoef_auto
functions. The
purpose of amending these functions was to make them compatible with outputs
from the modnets
package. The main use of these functions is as the
engines for the centTable
and clustTable
functions.
centAuto(x, which.net = "temporal", weighted = TRUE, signed = TRUE) clustAuto(x, thresholdWS = 0, thresholdON = 0)
centAuto(x, which.net = "temporal", weighted = TRUE, signed = TRUE) clustAuto(x, thresholdWS = 0, thresholdON = 0)
x |
Output from one of the primary |
which.net |
Only applies to SUR networks, as well as those fit with the
|
weighted |
Logical. If |
signed |
Logical. Determines whether to ignore the signs of edges or not. Primarily affects the output for expected influence statistics. |
thresholdWS |
Numeric threshold for the WS values. |
thresholdON |
Numeric threshold for the Zhang values. |
Returns several node centrality statistics, edge-betweenness centrality, and shortest path lengths. Betweenness and Closeness centrality are computed for all types of networks, as well as edge-betweenness values and shortest path lengths. For GGMs, Strength centrality and Expected Influence are also computed. For SUR networks, InStrength, OutStrength, InExpectedInfluence, and OutExpectedInfluence are computed instead.
The key distinction between these functions and the
qgraph::centrality_auto
and
qgraph::clustcoef_auto
functions is that
centrality and clustering values can be computed for the matrix of
interactions within a temporal network.
A list containing node centrality statistics, edge-betweenness values, and shortest path lengths.
centTable, clustTable, centPlot,
clustPlot, plotCentrality,
qgraph::centrality_auto,
qgraph::clustcoef_auto
x <- fitNetwork(ggmDat, 'M') clustAuto(x) centAuto(x, 'interactions')
x <- fitNetwork(ggmDat, 'M') clustAuto(x) centAuto(x, 'interactions')
Mimics the output of the
qgraph::centralityTable
and
qgraph::clusteringTable
functions. The
purpose of revising these function was to make them compatible with outputs
from the modnets
package.
centTable( Wmats, scale = TRUE, which.net = "temporal", labels = NULL, relative = FALSE, weighted = TRUE, signed = TRUE ) clustTable(Wmats, scale = TRUE, labels = NULL, relative = FALSE, signed = TRUE)
centTable( Wmats, scale = TRUE, which.net = "temporal", labels = NULL, relative = FALSE, weighted = TRUE, signed = TRUE ) clustTable(Wmats, scale = TRUE, labels = NULL, relative = FALSE, signed = TRUE)
Wmats |
Output from one of the primary |
scale |
Logical. Determines whether to standardize values within each measure (i.e., convert to z-scores). |
which.net |
Only applies to SUR networks, as well as those fit with the
|
labels |
Character vector to input the names of the nodes. If left
|
relative |
Logical. Determines whether to scale values within each measure relative to the largest value within that measure. |
weighted |
Logical. If |
signed |
Logical. Determines whether to ignore the signs of edges or not. Primarily affects the output for expected influence statistics. |
For centTable
, centrality values can be computed for the matrix
of interactions within a temporal network.
A table containing the names of nodes, measures of node centrality, and their corresponding centrality values or clustering coefficients.
centAuto, clustAuto, centPlot,
clustPlot, plotCentrality,
qgraph::centralityTable,
qgraph::clusteringTable
x <- fitNetwork(gvarDat, 'M', lags = TRUE) clustTable(x) centTable(x, which.net = 'interactions')
x <- fitNetwork(gvarDat, 'M', lags = TRUE) clustTable(x) centTable(x, which.net = 'interactions')
Mimics the qgraph::centralityPlot
and
qgraph::clusteringPlot
functions. The
purpose of revising this function was to make it compatible with outputs from
the modnets
package.
centPlot( Wmats, scale = c("z-scores", "raw", "raw0", "relative"), which.net = "temporal", include = "all", labels = NULL, orderBy = NULL, decreasing = FALSE, plot = TRUE, verbose = TRUE, weighted = TRUE, signed = TRUE ) clustPlot( Wmats, scale = c("z-scores", "raw", "raw0", "relative"), include = "all", labels = NULL, orderBy = NULL, decreasing = FALSE, plot = TRUE, signed = TRUE, verbose = TRUE ) plotCentrality( Wmats, which.net = "temporal", scale = TRUE, labels = NULL, plot = TRUE, centrality = "all", clustering = "Zhang" )
centPlot( Wmats, scale = c("z-scores", "raw", "raw0", "relative"), which.net = "temporal", include = "all", labels = NULL, orderBy = NULL, decreasing = FALSE, plot = TRUE, verbose = TRUE, weighted = TRUE, signed = TRUE ) clustPlot( Wmats, scale = c("z-scores", "raw", "raw0", "relative"), include = "all", labels = NULL, orderBy = NULL, decreasing = FALSE, plot = TRUE, signed = TRUE, verbose = TRUE ) plotCentrality( Wmats, which.net = "temporal", scale = TRUE, labels = NULL, plot = TRUE, centrality = "all", clustering = "Zhang" )
Wmats |
Output from one of the primary |
scale |
If |
which.net |
Only applies to SUR networks, as well as those fit with the
|
include |
Character vector of which centrality measures to plot.
|
labels |
Character vector listing the node names. If |
orderBy |
Character string specifying which measure to order values by. |
decreasing |
Logical. Only relevant if |
plot |
Logical. Determines whether to plot the output or not. |
verbose |
Logical. Determines whether to return a message about the plot (messages are only shown if values are scaled). |
weighted |
See |
signed |
See |
centrality |
Character vector of centrality measures to plot. Defaults
to |
clustering |
Character vector of clustering measures to plot. Defaults
to |
The only utility of the plotCentrality
function is as an easy
way to combine centrality measures and clustering coefficients into a single
plot.
A plot of centrality values or clustering coefficients for several measures.
centTable, clustTable, centAuto,
clustAuto, qgraph::centralityPlot,
qgraph::clusteringPlot
x <- fitNetwork(ggmDat) centPlot(x) clustPlot(x) plotCentrality(x)
x <- fitNetwork(ggmDat) centPlot(x) clustPlot(x) plotCentrality(x)
lmerVAR
modelsAffords ANOVAs to compare two or three lmerVAR
models. It is
necessary to supply at least two different models for comparison, although a
third can also be supplied if desired.
compareVAR(m1, m2, m3 = NULL, anova = NULL, type = "tempMods")
compareVAR(m1, m2, m3 = NULL, anova = NULL, type = "tempMods")
m1 |
Output from |
m2 |
Output from another run of |
m3 |
Output from a third run of |
anova |
If |
type |
Character string. Either |
Performs individual nodewise model comparisons across multiple
lmerVAR
models.
Table of ANOVA results comparing two or three models.
fit1 <- lmerVAR(mlgvarDat, temporal = "fixed", contemp = "orthogonal") fit2 <- lmerVAR(mlgvarDat, temporal = "orthogonal", contemp = "orthogonal") compareVAR(fit1, fit2)
fit1 <- lmerVAR(mlgvarDat, temporal = "fixed", contemp = "orthogonal") fit2 <- lmerVAR(mlgvarDat, temporal = "orthogonal", contemp = "orthogonal") compareVAR(fit1, fit2)
Creates a plot of the relationships between two variables at different levels of the moderator. Only works for relationships that include an interaction.
condPlot( out, to, from, swap = FALSE, avg = FALSE, compare = NULL, hist = FALSE, xlab = NULL, mods = NULL, nsims = 500, xn = NULL, getCIs = FALSE, discrete = FALSE, ylab = NULL, main = NULL, midline = TRUE )
condPlot( out, to, from, swap = FALSE, avg = FALSE, compare = NULL, hist = FALSE, xlab = NULL, mods = NULL, nsims = 500, xn = NULL, getCIs = FALSE, discrete = FALSE, ylab = NULL, main = NULL, midline = TRUE )
out |
Output from |
to |
Outcome variable, specified with character string or numeric value. |
from |
Predictor variable, specified with character string or numeric value. |
swap |
Logical. Serves to switch the arguments for |
avg |
Logical. If |
compare |
Two values can be supplied to indicate levels of the moderator to be compared. |
hist |
Logical. Determines whether to show a histogram of the data distribution at the bottom of the plot. |
xlab |
Character string for labeling the x-axis. |
mods |
This argument will be removed. Model output is automatically
detected based on |
nsims |
Number of iterations to simulate the posterior distribution. |
xn |
Numeric value to indicate how many values of the moderator should be evaluated. |
getCIs |
Logical. Only applies when |
discrete |
Logical. Determines whether to treat the moderator as a discrete or continuous variable. |
ylab |
Character string for labeling the y-axis. |
main |
Character string for labeling the title of the plot. |
midline |
Logical. Only applies when |
A plot of the conditional effects of one variable on another given different levels of the moderator.
fit <- fitNetwork(ggmDat, 'M') condPlot(fit, to = 'V5', from = 'V4') condPlot(fit, to = 2, from = 3, avg = TRUE)
fit <- fitNetwork(ggmDat, 'M') condPlot(fit, to = 'V5', from = 'V4') condPlot(fit, to = 2, from = 3, avg = TRUE)
The main function that ties everything together for both cross-sectional and idiographic (temporal) network models, moderated or otherwise.
fitNetwork( data, moderators = NULL, type = "gaussian", lags = NULL, seed = NULL, folds = 10, gamma = 0.5, which.lam = "min", rule = "OR", threshold = FALSE, scale = FALSE, std = TRUE, center = TRUE, covariates = NULL, verbose = FALSE, exogenous = TRUE, mval = NULL, residMat = "sigma", medges = 1, pcor = FALSE, maxiter = 100, getLL = TRUE, saveMods = TRUE, binarize = FALSE, fitCoefs = FALSE, detrend = FALSE, beepno = NULL, dayno = NULL, ... )
fitNetwork( data, moderators = NULL, type = "gaussian", lags = NULL, seed = NULL, folds = 10, gamma = 0.5, which.lam = "min", rule = "OR", threshold = FALSE, scale = FALSE, std = TRUE, center = TRUE, covariates = NULL, verbose = FALSE, exogenous = TRUE, mval = NULL, residMat = "sigma", medges = 1, pcor = FALSE, maxiter = 100, getLL = TRUE, saveMods = TRUE, binarize = FALSE, fitCoefs = FALSE, detrend = FALSE, beepno = NULL, dayno = NULL, ... )
data |
|
moderators |
Numeric or character vector indicating which variables (if any) to use as moderators. |
type |
Primarily used to supply a variable selection object, such as
those created with |
lags |
Logical or numeric, to indicate whether to fit a SUR model or
not. Set to |
seed |
Only useful if |
folds |
Can be used to specify the number of folds in cross-validation
when |
gamma |
Only useful if |
which.lam |
Only useful if |
rule |
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The |
threshold |
Determines whether to employ a p-value threshold on the
model. If |
scale |
Determines whether to standardize all variables or not. |
std |
Only applies to SUR networks. Logical. Provides input to the
|
center |
Determines whether to mean-center variables or not. |
covariates |
Either a numeric value or character string – this could also be a vector – to indicate which variables (if any) should be treated as covariates in the model. |
verbose |
Logical. Determines whether to return information about the progress of the model fitting – especially when variable selection is employed – as well as prints the amount of time it takes to fit the model to the console. |
exogenous |
Logical. Indicates whether moderator variables should be
treated as exogenous or not. If they are exogenous, they will not be
modeled as outcomes/nodes in the network. If the number of moderators
reaches |
mval |
Numeric value to set the moderator variable to when computing model coefficients. Useful to create conditional networks – i.e., those whose values are conditioned on specific values of the moderator. Excellent when the moderator is a categorical variable, or when it's desired to have model estimates at +/- 1 SD around the mean of the moderator. These values must be supplied explicitly. Can only specify a single value for a given model. |
residMat |
Character string indicating which type of residual covariance
matrix to compute for SUR models. Options include |
medges |
Only relevant when |
pcor |
Logical. Determines whether to operationalize the adjacency matrix as the partial correlation matrix of the data, or to use nodewise estimation. Only relevant for unmoderated networks. |
maxiter |
See argument of |
getLL |
Logical. Determines whether to return log-likelihood statistics
with model results. Recommended to keep |
saveMods |
Logical. Determines whether to save the |
binarize |
Logical. Determines whether to convert the output to a binary, unweighted network. Only relevant for GGMs. |
fitCoefs |
Determines whether to use the |
detrend |
Logical. Determines whether to remove linear trends from time series variables. Only applies to temporal networks. |
beepno |
Character string or numeric value to indicate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
dayno |
Character string or numeric value to indicate which variable (if
any) encodes the survey number within a single day. Must be used in
conjunction with |
... |
Additional arguments. |
For GGMs, nodewise estimation is utilized to fit models to each node, and
then aggregate results into the final network. For temporal networks that
represent data for a single subject, SUR estimation based on feasible
generalized least squares (FGLS) is used. Also incorporates the variable
selection functions to integrate model selection and estimation. Nodewise
estimation is used for all GGMs, and SUR estimation is used for temporal
networks. See systemfit
package for more information on the latter,
particularly via the systemfit::systemfit
function.
A ggm or SUR network
fit1 <- fitNetwork(ggmDat) fit2 <- fitNetwork(ggmDat, 'M', type = 'varSelect', criterion = 'BIC') fit3 <- fitNetwork(gvarDat, 'M', lags = 1)
fit1 <- fitNetwork(ggmDat) fit2 <- fitNetwork(ggmDat, 'M', type = 'varSelect', criterion = 'BIC') fit3 <- fitNetwork(gvarDat, 'M', lags = 1)
Requires that either fitobj
or SURfit
is included in the object
from fitNetwork
. Returns a list of nodewise model coefficients,
including confidence intervals computed from the estimated standard errors.
getFitCIs(fit, allNames = NULL, alpha = 0.05)
getFitCIs(fit, allNames = NULL, alpha = 0.05)
fit |
Output from |
allNames |
Character vector containing all the predictor names. Do not change, as these are automatically detected. |
alpha |
Type 1 error rate. The complement of the confidence level. |
The select
column in the output indicates whether the variable would
be selected given the supplied alpha level.
List of tables containing model coefficients along with confidence intervals
x <- fitNetwork(ggmDat) getFitCIs(x)
x <- fitNetwork(ggmDat) getFitCIs(x)
Data generated from simNet
, with five variables that serve as
nodes in the GGM and a sixth that serves as a moderator.
ggmDat
ggmDat
A 5000 x 6
data frame with five variables as nodes in a GGM
and a sixth as a moderator. Attributes contain values for the data
generating model. b1
contains the pairwise network, while b2
contains the interaction matrix. intercepts
contain the population
means of the five node variables. m
contains the population mean of
the moderator. m1
contains the main effect coefficients for the
moderator predicting each of the five nodes.
Data generated from simNet
, with five variables that serve as
nodes in the GVAR model and a sixth that serves as a moderator. The data were
generated by setting lag = 1
to specify a single-subject lag-1 model.
The data were simulated from a graphical vector autoregressive model (GVAR).
gvarDat
gvarDat
A 5000 x 6
data frame with five variables as nodes in a GVAR
and a sixth as a moderator. Attributes contain values for the data
generating model.
In the case of using simNet
with lags = 1
, that function
essentially serves as a wrapper for mlGVARsim
which
automatically sets nPerson = 1
.
Allows one to plot the confidence intervals associated with interaction terms. Provides an easy way to look at whether there are any significant interactions, and if so which interactions are important.
intsPlot(out, y = "all", nsims = 500, alpha = 0.05)
intsPlot(out, y = "all", nsims = 500, alpha = 0.05)
out |
GGM moderated network output from |
y |
Character string. The name of the outcome variable for which to
create the plot. If |
nsims |
The number of simulations to estimate the posterior distribution of the difference between high and low levels of the confidence interval. |
alpha |
Alpha level that is used to compute confidence intervals. |
The default setting y = "all"
shows all interaction terms associated
with the model. But the user can also home-in on specific variables to see
what interactions might be relevant. When y = "all"
, the axis labels
should be explained. These follow the format of predictor:outcome
. The
title reflects the name of the moderator variable. For instance, if a
variable named "M"
moderates the relationship between "X"
and
"Y"
, where "X"
predicts "Y"
, the title of the plot will
list the variable "M"
as the moderator, and the label (shown on the
y-axis), will read "X:Y"
. When y != "all"
(that is, a specific
value for y
is provided), then the title will still reflect the
moderator, but the labels will simply show which predictor interacts with
that moderator to predict the outcome.
A plot showing the spread of different interactions.
fit <- fitNetwork(ggmDat, 'M') plot(fit, 'ints', y = 'all')
fit <- fitNetwork(ggmDat, 'M') plot(fit, 'ints', y = 'all')
Proper estimation of mixed-effects GVAR models. This is an alternative
fitting procedure to that provided by the mlGVAR
function. The
key differences are that this function can take significantly longer to fit,
and it may fail when trying to fit especially large models.
lmerVAR( data, m = NULL, temporal = "default", contemp = "default", idvar = "ID", intvars = NULL, center = TRUE, scale = TRUE, centerWithin = TRUE, scaleWithin = FALSE, exogenous = TRUE, covariates = NULL, fix = NULL, verbose = TRUE, beepno = NULL, dayno = NULL, deleteMissing = TRUE )
lmerVAR( data, m = NULL, temporal = "default", contemp = "default", idvar = "ID", intvars = NULL, center = TRUE, scale = TRUE, centerWithin = TRUE, scaleWithin = FALSE, exogenous = TRUE, covariates = NULL, fix = NULL, verbose = TRUE, beepno = NULL, dayno = NULL, deleteMissing = TRUE )
data |
|
m |
Character vector or numeric vector indicating the moderator(s), if
any. Can also specify |
temporal |
Only affects the model for the temporal network and
between-subjects network (which is derived from the temporal network).
Options are |
contemp |
Options are |
idvar |
Character string to indicate which variable contains the participant identification numbers. |
intvars |
Character vector to indicate which interaction terms to include in the model. Not necessary, but useful to add significant customization and explicitly state which interactions to include in the model. |
center |
Logical. Determines whether to mean-center the variables. |
scale |
Logical. Determines whether to standardize the variables. |
centerWithin |
Following the application of |
scaleWithin |
Following the application of |
exogenous |
Logical. Indicates whether moderator variables should be
treated as exogenous or not. If they are exogenous, they will not be
modeled as outcomes/nodes in the network. If the number of moderators
reaches |
covariates |
See corresponding argument in |
fix |
Character vector to indicate which variables to only create fixed effects terms for. |
verbose |
Logical. Determines whether to output progress bars and messages in the console during the fitting process. |
beepno |
Character string or numeric value to indicate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
dayno |
Character string or numeric value to indicate which variable (if
any) encodes the survey number within a single day. Must be used in
conjunction with |
deleteMissing |
Logical. Determines whether to automatically perform listwise deletion if there are any missing values in the dataset. |
In the process of adding further documentation. More details to come. The method is referred to as the "two-step multilevel VAR" (Epskamp et al., 2018).
A lmerVAR
mixed-effects model with corresponding networks.
Epskamp, S., Waldorp, L. J., Mottus, R., & Borsboom, B. (2018). The gaussian graphical model in cross-sectional and time-series data. Multivariate Behavioral Research. 53, 453-580.
# The options were chosen so that the function would take less time to run x <- lmerVAR(mlgvarDat, 'M', temporal = "fixed", contemp = "orthogonal")
# The options were chosen so that the function would take less time to run x <- lmerVAR(mlgvarDat, 'M', temporal = "fixed", contemp = "orthogonal")
Computes log-likelihood, AIC, and BIC for a whole network, or for each node in the network. Also compares two or more networks using a likelihood ratio test (LRT).
modLL( net0, net1 = NULL, nodes = FALSE, lrt = NULL, all = FALSE, d = 4, alpha = 0.05, orderBy = NULL, decreasing = TRUE ) SURll( net0, net1 = NULL, nodes = FALSE, lrt = NULL, all = FALSE, d = 4, alpha = 0.05, s = "res", orderBy = NULL, decreasing = TRUE, sysfits = FALSE ) modTable( net0, nodes = FALSE, orderBy = TRUE, d = 4, alpha = 0.05, decreasing = TRUE, names = NULL, rmsea = FALSE ) SURtable( net0, nodes = FALSE, orderBy = TRUE, d = 4, alpha = 0.05, decreasing = TRUE, names = NULL, rmsea = FALSE, s = "res" )
modLL( net0, net1 = NULL, nodes = FALSE, lrt = NULL, all = FALSE, d = 4, alpha = 0.05, orderBy = NULL, decreasing = TRUE ) SURll( net0, net1 = NULL, nodes = FALSE, lrt = NULL, all = FALSE, d = 4, alpha = 0.05, s = "res", orderBy = NULL, decreasing = TRUE, sysfits = FALSE ) modTable( net0, nodes = FALSE, orderBy = TRUE, d = 4, alpha = 0.05, decreasing = TRUE, names = NULL, rmsea = FALSE ) SURtable( net0, nodes = FALSE, orderBy = TRUE, d = 4, alpha = 0.05, decreasing = TRUE, names = NULL, rmsea = FALSE, s = "res" )
net0 |
Output from one of the main |
net1 |
For |
nodes |
Logical. Determines whether to compute omnibus or nodewise
statistics and tests. If |
lrt |
Logical. Determines whether to conduct an LRT or not. If
|
all |
Logical. If |
d |
Number of decimal places to round outputted statistics to. |
alpha |
Alpha level for LRTs. Defaults to .05. |
orderBy |
Can be one of |
decreasing |
Logical. Determines whether to organize output from highest
to lowest, or vice versa, in accordance with the value of |
s |
Character string indicating which type of residual covariance matrix
to compute for SUR models. Options include |
sysfits |
Logical, only relevant to |
names |
Character vector containing the names of the models being
compared. Only relevant to the |
rmsea |
Logical. Relevant to |
Fits LRT to a list of network models to compare them all against each other.
Obtain all possible LRTs comparing a list of SUR models. Can include tests
comparing RMSEA values. The nodes
argument determines whether to
perform these computations in an omnibus or nodewise fashion.
One key thing to note is that when using modTable
or
SURtable
, the LRT column indicates the number of times that
each network was selected over others with respect to the pairwise LRTs.
A table or list of results depending on which function is used.
data <- na.omit(psychTools::msq[, c('hostile', 'lonely', 'nervous', 'sleepy', 'depressed')]) ##### Use modLL() for GGMs ggm1 <- fitNetwork(data[, -5]) ggm2 <- fitNetwork(data, covariates = 5) ggm3 <- fitNetwork(data, moderators = 5) modLL(ggm1) modLL(ggm2) modLL(ggm1, ggm2) modLL(ggm1, ggm2, nodes = TRUE) modLL(list(ggm1 = ggm1, ggm2 = ggm2)) modLL(list(GGM1 = ggm1, GGM2 = ggm2), nodes = TRUE) ggms <- list(ggm1, ggm2, ggm3) modLL(ggms) modTable(ggms) modTable(ggms, names = c("GGM1", "GGM2", "GGM3")) names(ggms) <- c("GGM1", "GGM2", "GGM3") modTable(ggms) modLL(ggms) ##### Use SURll() for SUR networks sur1 <- fitNetwork(data[, -5], lags = TRUE) sur2 <- fitNetwork(data, covariates = 5, lags = TRUE) sur3 <- fitNetwork(data, moderators = 5, lags = TRUE) SURll(sur1) SURll(sur2) SURll(sur1, sur2) SURll(sur1, sur2, nodes = TRUE) SURll(list(SUR1 = sur1, SUR2 = sur2), nodes = TRUE) surs <- list(sur1, sur2, sur3) SURll(surs) SURtable(surs, names = c('SUR1', "SUR2", "SUR3")) names(surs) <- c("SUR1", "SUR2", "SUR3") SURll(surs) SURtable(surs)
data <- na.omit(psychTools::msq[, c('hostile', 'lonely', 'nervous', 'sleepy', 'depressed')]) ##### Use modLL() for GGMs ggm1 <- fitNetwork(data[, -5]) ggm2 <- fitNetwork(data, covariates = 5) ggm3 <- fitNetwork(data, moderators = 5) modLL(ggm1) modLL(ggm2) modLL(ggm1, ggm2) modLL(ggm1, ggm2, nodes = TRUE) modLL(list(ggm1 = ggm1, ggm2 = ggm2)) modLL(list(GGM1 = ggm1, GGM2 = ggm2), nodes = TRUE) ggms <- list(ggm1, ggm2, ggm3) modLL(ggms) modTable(ggms) modTable(ggms, names = c("GGM1", "GGM2", "GGM3")) names(ggms) <- c("GGM1", "GGM2", "GGM3") modTable(ggms) modLL(ggms) ##### Use SURll() for SUR networks sur1 <- fitNetwork(data[, -5], lags = TRUE) sur2 <- fitNetwork(data, covariates = 5, lags = TRUE) sur3 <- fitNetwork(data, moderators = 5, lags = TRUE) SURll(sur1) SURll(sur2) SURll(sur1, sur2) SURll(sur1, sur2, nodes = TRUE) SURll(list(SUR1 = sur1, SUR2 = sur2), nodes = TRUE) surs <- list(sur1, sur2, sur3) SURll(surs) SURtable(surs, names = c('SUR1', "SUR2", "SUR3")) names(surs) <- c("SUR1", "SUR2", "SUR3") SURll(surs) SURtable(surs)
Fits a graphical vector autoregressive model to data containing multiple time points measured for multiple individuals.
mlGVAR( data, m = NULL, selectFUN = NULL, subjectNets = FALSE, idvar = "ID", exogenous = TRUE, center = TRUE, scale = TRUE, fixedType = "g", betweenType = "g", centerWithin = TRUE, scaleWithin = FALSE, rule = "OR", threshold = "none", verbose = TRUE, pcor = FALSE, fixedArgs = NULL, betweenArgs = NULL, bm = FALSE, beepno = NULL, dayno = NULL, deleteMissing = TRUE, ... )
mlGVAR( data, m = NULL, selectFUN = NULL, subjectNets = FALSE, idvar = "ID", exogenous = TRUE, center = TRUE, scale = TRUE, fixedType = "g", betweenType = "g", centerWithin = TRUE, scaleWithin = FALSE, rule = "OR", threshold = "none", verbose = TRUE, pcor = FALSE, fixedArgs = NULL, betweenArgs = NULL, bm = FALSE, beepno = NULL, dayno = NULL, deleteMissing = TRUE, ... )
data |
|
m |
Character vector or numeric vector indicating the moderator(s), if
any. Can also specify |
selectFUN |
Choose a variable selection function. Can specify either
|
subjectNets |
If |
idvar |
Character string to indicate which variable contains the participant identification numbers. |
exogenous |
Logical. Indicates whether moderator variables should be
treated as exogenous or not. If they are exogenous, they will not be
modeled as outcomes/nodes in the network. If the number of moderators
reaches |
center |
Logical. Determines whether to mean-center the variables. |
scale |
Logical. Determines whether to standardize the variables. |
fixedType |
If logical, then any variable selection procedure specified
by |
betweenType |
If logical, then any variable selection procedure
specified by |
centerWithin |
Following the application of |
scaleWithin |
Following the application of |
rule |
Only applies to the between-subject network when a threshold is
supplied. The |
threshold |
Logical or numeric. If |
verbose |
Logical. Determines whether to output progress bars and messages in the console during the fitting process. |
pcor |
See corresponding argument in the |
fixedArgs |
A named list of arguments for the variable selection function can be provided here, specifically those that are meant to be applied to the SUR network estimation. |
betweenArgs |
A named list of arguments for the variable selection function can be provided for the between-subjects network. |
bm |
Logical. Determines whether the same moderators are applied in the
between-subjects network. By default, the value of |
beepno |
Character string or numeric value to indicate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
dayno |
Character string or numeric value to indiciate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
deleteMissing |
Logical. Determines whether to automatically perform listwise deletion if there are any missing values in the dataset. |
... |
Additional arguments. |
Uses a pseudo-mixed effects approach, wherein fixed effects are estimated and random effects are approximated. See the work of Epskamp et al. (2018) for more details on how these types of effects are estimated.
mlGVAR
objects
Epskamp, S., Waldorp, L. J., Mottus, R., & Borsboom, B. (2018). The gaussian graphical model in cross-sectional and time-series data. Multivariate Behavioral Research. 53, 453-580.
mlGVARsim, lmerVAR, fitNetwork,
varSelect, resample, net, netInts,
plotNet
fit1 <- mlGVAR(mlgvarDat, 'M') fit2 <- mlGVAR(mlgvarDat, 'M', bm = TRUE) # Fit the same moderator in the between-subjects network fit3 <- mlGVAR(mlgvarDat, 'M', selectFUN = 'varSelect')
fit1 <- mlGVAR(mlgvarDat, 'M') fit2 <- mlGVAR(mlgvarDat, 'M', bm = TRUE) # Fit the same moderator in the between-subjects network fit3 <- mlGVAR(mlgvarDat, 'M', selectFUN = 'varSelect')
Data generated from mlGVARsim
, with five variables that serve
as nodes in the multi-level GVAR model, one moderator variable, and an ID
variable that distinguishes between subjects.
mlgvarDat
mlgvarDat
A 50000 x 7
data frame with five variables to serve as nodes in
the networks, one variable "M"
to serve as the time-lagged
moderator, and an ID
variable that labels responses from each of
100
simulated individuals. For each ID number, there are 500
time-ordered responses.
Affords the generation of simulated data containing multiple timepoint measurements for a number of subjects. Can simulate data with a single moderator as well.
mlGVARsim( nTime = 50, nPerson = 10, nNode = 3, m = NULL, m2 = 0.25, m1 = 0.7, m0 = 1, lag = 1, thetaVar = NULL, mu_SD = NULL, init_beta_SD = NULL, fixedMuSD = 1, shrink_fixed = 0.9, propPos = 0.5, m1SD = 0.1, m2SD = 0.1, m1_range = NULL, m2_range = NULL, shrink_deviation = 0.9, getM = FALSE, contemporaneous = "wishart", GGMsparsity = 0.5, mcenter = TRUE, skew = FALSE, skewErr = FALSE, ordinal = FALSE, nLevels = 5, ordWithin = TRUE, minOrd = 3, thresholds = NULL, mseed = NULL, onlyNets = FALSE, modType = "none" )
mlGVARsim( nTime = 50, nPerson = 10, nNode = 3, m = NULL, m2 = 0.25, m1 = 0.7, m0 = 1, lag = 1, thetaVar = NULL, mu_SD = NULL, init_beta_SD = NULL, fixedMuSD = 1, shrink_fixed = 0.9, propPos = 0.5, m1SD = 0.1, m2SD = 0.1, m1_range = NULL, m2_range = NULL, shrink_deviation = 0.9, getM = FALSE, contemporaneous = "wishart", GGMsparsity = 0.5, mcenter = TRUE, skew = FALSE, skewErr = FALSE, ordinal = FALSE, nLevels = 5, ordWithin = TRUE, minOrd = 3, thresholds = NULL, mseed = NULL, onlyNets = FALSE, modType = "none" )
nTime |
Numeric value. The number of timepoints to simulate for each individual. |
nPerson |
The number of subjects to create data for. Can set to |
nNode |
The number of nodes/variables to simulate. Does not include a moderator if one is specified. |
m |
Logical. If |
m2 |
Numeric. If |
m1 |
Functions similarly to |
m0 |
Only relevant when |
lag |
Numeric value, supposed to indicate the number of lags to simulate
models parameters for. Recommended to leave at |
thetaVar |
Numeric vector containing the variance associated with each
node (excluding the moderator) in the contemporaneous network. If
|
mu_SD |
Numeric vector of length 2. The first value determines the standard deviation of the means associated with the temporal data, and the second value determines the standard deviations of the means associated with the between-subjects network. |
init_beta_SD |
Similar to |
fixedMuSD |
Standard deviation of the random values for the means of the fixed effects. |
shrink_fixed |
Numeric value to determine the factor by which to shrink sampled beta coefficients for fixed effects. Value between 0 and 1, where higher values are recommended. |
propPos |
The proportion of edges with a positive sign. |
m1SD |
Standard deviation of the moderator main effect coefficients. |
m2SD |
Standard deviation of the moderator interaction effect coefficients. |
m1_range |
Numeric vector of length 2. The range of values for moderator main effect coefficients. |
m2_range |
Numeric vector of length 2. The range of values for moderator interaction effect coefficients. |
shrink_deviation |
Numeric value to determine the factor by which to shrink contemporaneous coefficients. Value between 0 and 1, where higher values are recommended. |
getM |
If |
contemporaneous |
Options include |
GGMsparsity |
Numeric value between 0 and 1. Determines the sparsity of sampled network matrices. |
mcenter |
If |
skew |
If |
skewErr |
The skewness parameter for the |
ordinal |
Logical. Determines whether to sample ordinal variables. If a
numeric value is provided, then this will automatically be assigned to the
|
nLevels |
Number of levels for the ordinal variables. Only relevant if
|
ordWithin |
If |
minOrd |
The minimum number of unique values allowed for each variable. |
thresholds |
List of length |
mseed |
Numeric value for the seed to be set when |
onlyNets |
If |
modType |
Determines the type of moderation to employ, such as
|
Made to simulate data based on pre-specified parameters, possibly for power
simulations or other analyses. Output can be used to fit models with either
mlGVAR
or lmerVAR
.
Simulated mlGVAR or VAR data.
mlGVAR, lmerVAR, simNet, plotNet,
net, netInts
set.seed(1) x <- mlGVARsim(nTime = 50, nPerson = 10, nNode = 3, m = TRUE)
set.seed(1) x <- mlGVARsim(nTime = 50, nPerson = 10, nNode = 3, m = TRUE)
Samples data based on several parameters, mainly used to see how different
sample sizes perform given various parameterizations when simulating from
network models, especially moderated networks. See simNet
for
more details about arguments as well as the warning about simulations that
fail.
mnetPowerSim( niter = 10, N = 100, p = 5, m = FALSE, m1 = 0, m2 = 0.1, sparsity = 0.5, lags = NULL, trueNet = NULL, threshold = TRUE, rule = "OR", avg = TRUE, maxiter = 100, saveFits = TRUE, saveData = FALSE, intercepts = NULL, mbinary = FALSE, select = NULL, vargs = list(), type = "g", gibbs = TRUE, ordinal = FALSE, mord = FALSE, nLevels = 5, minOrd = 3, div = 1000, modType = "none", m1_range = NULL, m2_range = c(0.1, 0.3), time = TRUE, skewErr = FALSE, nCores = 1, cluster = "mclapply", fixedPar = NULL, V2 = 1, ... )
mnetPowerSim( niter = 10, N = 100, p = 5, m = FALSE, m1 = 0, m2 = 0.1, sparsity = 0.5, lags = NULL, trueNet = NULL, threshold = TRUE, rule = "OR", avg = TRUE, maxiter = 100, saveFits = TRUE, saveData = FALSE, intercepts = NULL, mbinary = FALSE, select = NULL, vargs = list(), type = "g", gibbs = TRUE, ordinal = FALSE, mord = FALSE, nLevels = 5, minOrd = 3, div = 1000, modType = "none", m1_range = NULL, m2_range = c(0.1, 0.3), time = TRUE, skewErr = FALSE, nCores = 1, cluster = "mclapply", fixedPar = NULL, V2 = 1, ... )
niter |
Number of iterations/samples to take for each combination of parameters. |
N |
Numeric value, or vector of sample sizes to generate data with. |
p |
Numeric value, or vector of network sizes. |
m |
If a value is provided then a moderated network will be simulated.
See |
m1 |
Functions similarly to |
m2 |
Numeric. If |
sparsity |
Numeric value between 0 and 1. Determines the sparsity of sampled network matrices. |
lags |
Determines whether the network should be a temporal network or
not. If simulating a temporal network, set to |
trueNet |
The adjacency matrix of the data-generating network model, or a list containing the adjacency matrix as the first element, and the interaction matrix as the second element. |
threshold |
See corresponding argument in |
rule |
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The |
avg |
See corresponding argument of |
maxiter |
If a model fails to be fit, this determines the maximum number of iterations to re-try it before giving up. Will also simulate new datasets at each iteration. |
saveFits |
Logical. Determines whether to save the models fit to each dataset at each iteration. |
saveData |
Logical. Determines whether to save the datasets generated at each iteration. |
intercepts |
A vector of means for sampling node values. |
mbinary |
Logical. Determines whether the moderator should be a binary variable. |
select |
Identifies a variable selection function – either
|
vargs |
A named list of arguments relevant to the variable selection
procedure specified by the |
type |
Can supply a variable selection object, such as the output from
either |
gibbs |
If |
ordinal |
Logical. Determines whether to generate ordinal values or not. |
mord |
Logical. Determines whether the moderator variable should be simulated as ordinal. |
nLevels |
Number of levels for the ordinal variables. Only relevant if
|
minOrd |
The minimum number of unique values allowed for each variable. |
div |
A value to use as a sign that the sampler diverged. Can be
increased based on expected range of values. If a datapoint is larger than
|
modType |
Determines the type of moderation to employ, such as
|
m1_range |
Numeric vector of length 2. The range of values for moderator main effect coefficients. |
m2_range |
Numeric vector of length 2. The range of values for moderator interaction effect coefficients. |
time |
If |
skewErr |
The skewness parameter for the |
nCores |
Numeric value indicating the number of CPU cores to use for the
resampling. If |
cluster |
Character vector indicating which type of parallelization to
use, if |
fixedPar |
Numeric. If provided, then this will be set as the
coefficient value for all edges in the network. Provides a way to
standardize the parameter values while varying the sparsity of the network.
If |
V2 |
If |
... |
Additional arguments. |
Evaluates how closely an estimated network is with the true network with regards to metrics such as sensitivity, specificity, and precision, among others. Doesn't calculate values for power, but can be used to serve a similar function as a traditional power analysis based on simulated datasets.
Power simulation results
summary.mnetPower, plotPower, simNet,
mlGVARsim
x <- mnetPowerSim(niter = 10, N = c(100, 200)) summary(x) plot(x)
x <- mnetPowerSim(niter = 10, N = c(100, 200)) summary(x) plot(x)
Methods for modeling and plotting various types of moderated networks, including tools for model selection. Model selection tools can be employed for any type of moderated network, and include methods based on the LASSO as well as resampling techniques such as bootstrapping, multi-sample splitting, and stability selection. The primary model types include:
Cross-section moderated networks
Temporal (idiographic) moderated networks
Multi-level moderated networks
Model fitting: | fitNetwork, mlGVAR,
lmerVAR |
Variable selection: | varSelect,
resample, modSelect |
Model comparison: |
modLL, modTable, SURll, SURtable |
Simulating network data: | simNet, mlGVARsim,
mnetPowerSim |
Centrality and clustering: |
centTable, clustTable |
Adjacency matrices: |
net, netInts |
Bootstrapping and stability: |
bootNet |
Plotting functions are available for all model objects and can be accessed
through the plot()
S3 generic.
Package: | modnets |
Title: | Modeling Moderated Networks |
Version: | 0.9.0 |
Author: | Trevor Swanson |
Maintainer: | [email protected] |
URL: | https://github.com/tswanson222/modnets |
BugReports: | https://github.com/tswanson222/modnets/issues |
License: | GPL-3 |
Imports: | abind, corpcor, ggplot2, glinternet, glmnet, gridExtra, gtools, igraph, interactionTest, leaps, lme4, lmerTest, Matrix, methods, mvtnorm, parallel, pbapply, plyr, psych, qgraph, reshape2, systemfit |
Suggests: | sn, arm, hierNet, psychTools |
Date: | 2021-09-26 |
Trevor Swanson
Maintainer: Trevor Swanson [email protected]
Swanson, T. J. (2020). Modeling moderators in psychological networks (Publication No. 28000912) [Doctoral dissertation, University of Kansas]. ProQuest Dissertations Publishing.
resample
Creates the necessary input for fitNetwork when selecting variables based on
the resample
function. The purpose of making this function
available to the user is to that different decisions can be made about how
exactly to use the resample
output to select a model, as
sometimes there is more than one option for choosing a final model.
modSelect( obj, data = NULL, fit = FALSE, select = "select", thresh = NULL, ascall = TRUE, type = "gaussian", ... )
modSelect( obj, data = NULL, fit = FALSE, select = "select", thresh = NULL, ascall = TRUE, type = "gaussian", ... )
obj |
|
data |
The dataframe used to create the |
fit |
Logical. Determines whether to fit the selected model to the data
or just return the model specifications. Must supply a dataset in the
|
select |
Character string, referring to which variable of the output
should be used as the basis for selecting variables. If the resampling
method was either When the resampling method was For all types of |
thresh |
Numeric value. If |
ascall |
Logical. Determines whether to return a list with arguments
necessary for fitting the model with |
type |
Should just leave as-is. Automatically taken from the
|
... |
Additional arguments. |
A call ready for fitNetwork
, a fitted network model, or
a list of selected variables for each node along with relevant attributes.
Essentially, the output is either the selected model itself or a list of
the necessary parameters to fit it.
res1 <- resample(ggmDat, m = 'M', niter = 10) mods1 <- modSelect(res1) fit1 <- fitNetwork(ggmDat, morderators = 'M', type = mods1) res2 <- resample(ggmDat, m = 'M', sampMethod = 'stability') fit2 <- modSelect(res2, data = ggmDat, fit = TRUE, thresh = .7)
res1 <- resample(ggmDat, m = 'M', niter = 10) mods1 <- modSelect(res1) fit1 <- fitNetwork(ggmDat, morderators = 'M', type = mods1) res2 <- resample(ggmDat, m = 'M', sampMethod = 'stability') fit2 <- modSelect(res2, data = ggmDat, fit = TRUE, thresh = .7)
net
returns the adjacency matrix for any network model fit
using functions from the modnets
package. netInts
returns a matrix of interaction terms associated with a moderated network.
net( fit, n = "beta", threshold = FALSE, rule = "OR", binary = FALSE, nodewise = FALSE, d = 14, r = NULL ) netInts( fit, n = "temporal", threshold = FALSE, avg = FALSE, rule = "none", r = NULL, empty = TRUE, mselect = NULL )
net( fit, n = "beta", threshold = FALSE, rule = "OR", binary = FALSE, nodewise = FALSE, d = 14, r = NULL ) netInts( fit, n = "temporal", threshold = FALSE, avg = FALSE, rule = "none", r = NULL, empty = TRUE, mselect = NULL )
fit |
A fitted network model. Can be the output from
|
n |
When multiple networks exist for a single object, this allows the
user to indicate which adjacency matrix to return. For a GGM, all values of
this argument return the same adjacency matrix. For a SUR network,
|
threshold |
A numeric or logical value to set a p-value threshold.
|
rule |
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The |
binary |
Logical. If |
nodewise |
Logical, only applies to GGMs (including between-subjects
networks). If |
d |
Numeric. Only used for output of |
r |
Numeric. Chooses which rows/columns to remove from the output, if desired. |
avg |
Logical. For |
empty |
Logical. Determines the output of |
mselect |
Only used for |
For GGMs when a non-symmetric matrix is requested, columns will represent outcomes and rows will represent predictors. For temporal networks, columns represent predictors and rows represent outcomes.
Can also be used with output from the resample
and
bootNet
functions.
An adjacency matrix representing a network or a matrix of interaction terms.
fitNetwork, mlGVAR, lmerVAR,
bootNet, resample, simNet, mlGVARsim
x <- fitNetwork(ggmDat, 'M') net(x, threshold = .05) netInts(x, threshold = TRUE) y <- mlGVAR(mlgvarDat, 'M') net(y, n = 'beta') net(y, n = 'pcc') net(y, n = 'between') netInts(y)
x <- fitNetwork(ggmDat, 'M') net(x, threshold = .05) netInts(x, threshold = TRUE) y <- mlGVAR(mlgvarDat, 'M') net(y, n = 'beta') net(y, n = 'pcc') net(y, n = 'between') netInts(y)
Allows for easy conversion of continuous variables into ordinal variables.
ordinalize( data, m = NULL, nLevels = 5, thresholds = NULL, mthresh = NULL, mord = TRUE, minOrd = 3 )
ordinalize( data, m = NULL, nLevels = 5, thresholds = NULL, mthresh = NULL, mord = TRUE, minOrd = 3 )
data |
An |
m |
The column number or name of the moderator variable, if applicable.
Leave as |
nLevels |
Number of levels for the ordinal variables. |
thresholds |
List of length |
mthresh |
Vector of length |
mord |
if |
minOrd |
The minimum number of unique values allowed for each variable. |
If a moderator value is specified via the m
argument, that variable
will automatically be relegated to the last column of the resultant dataframe
or matrix. It will also be renamed "M"
A dataframe or matrix containing the ordinalized data.
dat <- data.frame(sapply(1:5, function(z) rnorm(100))) ord_dat <- ordinalize(dat) # Including a moderator, without converting the moderator into an ordinal variable ord_dat <- ordinalize(dat, m = 5, mord = FALSE) colnames(dat)[5] <- 'M' ord_dat <- ordinalize(dat, m = 'M', mord = FALSE) # Use thresholds to break each variable into quartiles thresh <- lapply(dat, function(z) quantile(z, probs = c(.25, .5, .75))) ord_dat <- ordinalize(dat, thresholds = thresh)
dat <- data.frame(sapply(1:5, function(z) rnorm(100))) ord_dat <- ordinalize(dat) # Including a moderator, without converting the moderator into an ordinal variable ord_dat <- ordinalize(dat, m = 5, mord = FALSE) colnames(dat)[5] <- 'M' ord_dat <- ordinalize(dat, m = 'M', mord = FALSE) # Use thresholds to break each variable into quartiles thresh <- lapply(dat, function(z) quantile(z, probs = c(.25, .5, .75))) ord_dat <- ordinalize(dat, thresholds = thresh)
Allows one to plot results from the resample
function based on
a few different options.
## S3 method for class 'resample' plot(x, what = "network", ...)
## S3 method for class 'resample' plot(x, what = "network", ...)
x |
Output from the |
what |
Can be one of three options for all |
... |
Additional arguments. |
For the what
argument, the options correspond with calls to the
following functions:
"network": plotNet
"bootstrap": plotBoot
"coefs":
plotCoefs
"stability": plotStability
"pvals": plotPvals
"bootstrap"
and "pvals"
only available for bootstrapped and
multi-sample split resampling. "stability"
only available for
stability selection.
Plots various aspects of output from the resample
function.
fit1 <- resample(ggmDat, m = 'M', niter = 10) net(fit1) netInts(fit1) plot(fit1) plot(fit1, what = 'coefs') plot(fit1, what = 'bootstrap', multi = TRUE) plot(fit1, what = 'pvals', outcome = 2, predictor = 4) fit2 <- resample(gvarDat, m = 'M', niter = 10, lags = 1, sampMethod = 'stability') plot(fit2, what = 'stability', outcome = 3)
fit1 <- resample(ggmDat, m = 'M', niter = 10) net(fit1) netInts(fit1) plot(fit1) plot(fit1, what = 'coefs') plot(fit1, what = 'bootstrap', multi = TRUE) plot(fit1, what = 'pvals', outcome = 2, predictor = 4) fit2 <- resample(gvarDat, m = 'M', niter = 10, lags = 1, sampMethod = 'stability') plot(fit2, what = 'stability', outcome = 3)
bootNet
outputsCreates various types of plot to visualize bootNet
objects.
plotBoot( x, type = "edges", net = "temporal", plot = "all", cor = 0.7, order = "mean", ci = 0.95, pairwise = TRUE, interactions = TRUE, labels = NULL, title = NULL, cis = "quantile", true = NULL, errbars = FALSE, vline = FALSE, threshold = FALSE, difference = FALSE, color = FALSE, text = FALSE, textPos = "value", multi = NULL, directedDiag = FALSE, ... ) ## S3 method for class 'bootNet' plot( x, type = "edges", net = "temporal", plot = "all", cor = 0.7, order = "mean", ci = 0.95, pairwise = TRUE, interactions = TRUE, labels = NULL, title = NULL, cis = "quantile", true = NULL, errbars = FALSE, vline = FALSE, threshold = FALSE, difference = FALSE, color = FALSE, text = FALSE, textPos = "value", multi = NULL, directedDiag = FALSE, ... )
plotBoot( x, type = "edges", net = "temporal", plot = "all", cor = 0.7, order = "mean", ci = 0.95, pairwise = TRUE, interactions = TRUE, labels = NULL, title = NULL, cis = "quantile", true = NULL, errbars = FALSE, vline = FALSE, threshold = FALSE, difference = FALSE, color = FALSE, text = FALSE, textPos = "value", multi = NULL, directedDiag = FALSE, ... ) ## S3 method for class 'bootNet' plot( x, type = "edges", net = "temporal", plot = "all", cor = 0.7, order = "mean", ci = 0.95, pairwise = TRUE, interactions = TRUE, labels = NULL, title = NULL, cis = "quantile", true = NULL, errbars = FALSE, vline = FALSE, threshold = FALSE, difference = FALSE, color = FALSE, text = FALSE, textPos = "value", multi = NULL, directedDiag = FALSE, ... )
x |
Output from |
type |
The outcome measure to plot. Options include: |
net |
Determines which network to plot coefficients for. Options
include: |
plot |
Primary use is to set as |
cor |
Numeric value to indicate the correlation stability value to be plotted. Only applies to the case-drop bootstrapping output. |
order |
Determines how to arrange the predictors displayed in the plot.
If |
ci |
Numeric value between 0 and 1 to specify the confidence level. |
pairwise |
Logical. Whether to plot pairwise relationships. Defaults to
|
interactions |
Logical. Whether to plot interactions. Defaults to
|
labels |
Logical. Determines whether to plot names of the predictors. |
title |
Character vector the title label. |
cis |
Either |
true |
Defaults to |
errbars |
Logical. Not relevant to the case-drop bootstrap. If
|
vline |
Logical or numeric. Not relevant to the case-drop bootstrap. If
|
threshold |
Numeric or logical. Not relevant to the case-drop bootstrap.
Has a significant effect on the bootstrapped coefficient distributions. If
|
difference |
Logical. Not relevant to the case-drop bootstrap. If
|
color |
Logical. Only applies when |
text |
Logical. For difference plots, if |
textPos |
Supports the |
multi |
Useful when there are interactions in a model. If |
directedDiag |
See corresponding argument in the |
... |
Additional arguments. |
A coefficient plot, difference plot, or correlation-stability plot.
When plot %in% c('none', FALSE)
, the table used to construct the
relevant plot will be returned as output instead.
boot1 <- bootNet(ggmDat, caseDrop = TRUE) plot(boot1) plotBoot(boot1) # This functions the same as the command above boot2 <- bootNet(ggmDat) plot(boot2) plot(boot2, difference = TRUE)
boot1 <- bootNet(ggmDat, caseDrop = TRUE) plot(boot1) plotBoot(boot1) # This functions the same as the command above boot2 <- bootNet(ggmDat) plot(boot2) plot(boot2, difference = TRUE)
Return a plot or dataframe showing the point estimates from each model, along with confidence intervals based on the estimated standard errors.
plotCoefs( fit, true = FALSE, alpha = 0.05, plot = TRUE, col = "blue", flip = TRUE, data = NULL, select = TRUE, size = 1, labels = TRUE, title = NULL, vars = "all" )
plotCoefs( fit, true = FALSE, alpha = 0.05, plot = TRUE, col = "blue", flip = TRUE, data = NULL, select = TRUE, size = 1, labels = TRUE, title = NULL, vars = "all" )
fit |
Output from |
true |
An adjacency matrix containing the true parameter values, if known. This can be used in conjunction with a simulated network, in that the user can supply the true network and plot those values against the estimated values. |
alpha |
Alpha level that is used to compute confidence intervals. |
plot |
Logical. If |
col |
Character string. Color of the points associated with the
|
flip |
Logical. If |
data |
Supply the original dataset if not already included in the
|
select |
Relevant to the |
size |
Numeric. Size of the point estimates. |
labels |
If logical, determines whether or not variable labels should be included. If a character vector, can be used to customize variable labels. |
title |
Custom plot title. |
vars |
Defaults to |
This is differentiated from the output of bootNet
and
plotBoot
in that the confidence intervals are computed directly
from model parameters rather than estimated from bootstrapping.
Plot displaying estimated model coefficients and confidence intervals.
fitNetwork, resample, getFitCIs,
plot.resample, plotNet
x <- fitNetwork(ggmDat) plot(x, which.net = 'coefs') plotCoefs(x) # This is the same as the above command
x <- fitNetwork(ggmDat) plot(x, which.net = 'coefs') plotCoefs(x) # This is the same as the above command
An easy wrapper for plotting the same network at different levels of a
moderator. Using the mval
argument of the fitNetwork
function, you can create multiple models—conditional networks—wherein the
same model is fit at different values of the moderator.
plotMods( nets, nodewise = FALSE, elsize = 2, vsize = NULL, elabs = TRUE, predict = NULL, layout = NULL, which.net = "temporal", ... )
plotMods( nets, nodewise = FALSE, elsize = 2, vsize = NULL, elabs = TRUE, predict = NULL, layout = NULL, which.net = "temporal", ... )
nets |
List of network models fit with |
nodewise |
See corresponding argument in |
elsize |
Numeric value to indicate the size of the edge labels. |
vsize |
Numeric value to indicate the size of the nodes. If |
elabs |
If |
predict |
See corresponding argument in |
layout |
Can be a character string, corresponding to the options in
|
which.net |
See corresponding argument in |
... |
Additional arguments. |
Importantly, this function will fix a common layout across all conditional networks so that the network can be easily compared (visually) at different levels of the moderator.
Returns a plot where multiple conditional networks are plotted side by side.
data <- na.omit(psychTools::msq[, c('hostile', 'lonely', 'nervous', 'sleepy', 'depressed')]) fit0 <- fitNetwork(data, moderators = 'depressed', mval = 0) fit1 <- fitNetwork(data, moderators = 'depressed', mval = 1) fit2 <- fitNetwork(data, moderators = 'depressed', mval = 2) fits <- list(fit0, fit1, fit2) plotMods(fits)
data <- na.omit(psychTools::msq[, c('hostile', 'lonely', 'nervous', 'sleepy', 'depressed')]) fit0 <- fitNetwork(data, moderators = 'depressed', mval = 0) fit1 <- fitNetwork(data, moderators = 'depressed', mval = 1) fit2 <- fitNetwork(data, moderators = 'depressed', mval = 2) fits <- list(fit0, fit1, fit2) plotMods(fits)
Core function for plotting various types of network models. Accessible
through the plot()
S3 generic function.
plotNet( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'ggm' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'SURnet' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'mlGVAR' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'lmerVAR' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'ggmSim' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'mlGVARsim' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'GVARsim' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... )
plotNet( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'ggm' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'SURnet' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'mlGVAR' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'lmerVAR' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'ggmSim' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'mlGVARsim' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... ) ## S3 method for class 'GVARsim' plot( x, which.net = "temporal", threshold = FALSE, layout = "spring", predict = FALSE, mnet = FALSE, names = TRUE, nodewise = FALSE, scale = FALSE, lag = NULL, con = "R2", cat = "nCC", covNet = FALSE, plot = TRUE, elabs = FALSE, elsize = 1, rule = "OR", binarize = FALSE, mlty = TRUE, mselect = NULL, ... )
x |
Output from any of the |
which.net |
When multiple networks exist for a single object, this
allows the user to indicate which network to plot. For a GGM, all values of
this argument return the same adjacency matrix. For a SUR network,
|
threshold |
A numeric or logical value to set a p-value threshold.
|
layout |
Character. Corresponds to the |
predict |
If |
mnet |
Logical. If |
names |
If |
nodewise |
Only applies to GGMs. If |
scale |
Logical. Only applies when |
lag |
This argument will be removed. The function will automatically detect whether the network is based on time-lagged data. |
con |
Character string indicating which type of prediction error to plot
for continuous variables, if |
cat |
Character string indicating which type of prediction error to plot
for categorical variables, if |
covNet |
Logical. Only applies when a covariate is modeled. Allows the covariate to be plotted as a separate square "node". |
plot |
Logical. If |
elabs |
Logical. If |
elsize |
numeric |
rule |
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The |
binarize |
Logical. If |
mlty |
Logical. If |
mselect |
If the model contains more than one moderator, input the
character string naming which moderator you would like the plot to reflect.
Only affects which lines are dashed or solid. Not compatible with the
|
... |
Additional arguments. |
Displays a network plot, or returns a qgraph
object if
plot = FALSE
.
fitNetwork, predictNet, mlGVAR,
lmerVAR, simNet, mlGVARsim, plotCoefs,
intsPlot, resample
fit1 <- fitNetwork(ggmDat) plot(fit1) plotNet(fit1) # This and the command above produce the same result fit2 <- fitNetwork(gvarDat, moderators = 'M', lags = 1) plot(fit2, 'pdc') # Partial Directed Correlations plot(fit2, 'pcc') # Partial Contemporaneous Correlations
fit1 <- fitNetwork(ggmDat) plot(fit1) plotNet(fit1) # This and the command above produce the same result fit2 <- fitNetwork(gvarDat, moderators = 'M', lags = 1) plot(fit2, 'pdc') # Partial Directed Correlations plot(fit2, 'pcc') # Partial Contemporaneous Correlations
Designed for easy-to-use plotting with temporal networks. Essentially just a
wrapper for running plotNet
twice—once for a temporal
network, and again for a contemporaneous network—and plotting the two
networks in the same window. Good for a quick glance at results from a SUR
network. Also compatible with mlGVAR
and lmerVAR
outputs, although can only plot two networks in the same window.
plotNet3
can be used to plot 3 networks.
plotNet2( object, whichNets = NULL, whichTemp = c("temporal", "PDC"), titles = c("PDC ", "PCC "), ... )
plotNet2( object, whichNets = NULL, whichTemp = c("temporal", "PDC"), titles = c("PDC ", "PCC "), ... )
object |
Output from |
whichNets |
Vector of length 2 indicating which networks to plot.
|
whichTemp |
Which version of the temporal network should be plotted,
either |
titles |
Character vector of length 2 where custom names for the two network plots can be supplied. |
... |
Additional arguments. |
Returns two network plots side by side.
x <- fitNetwork(gvarDat, lags = TRUE) plotNet2(x)
x <- fitNetwork(gvarDat, lags = TRUE) plotNet2(x)
Quick, easy plotting for mlGVAR
and lmerVAR
output. Allows one to plot three networks in the same window: temporal,
contemporaneous, and between-subject.
plotNet3( object, ..., nets = c("temporal", "contemporaneous", "between"), titles = TRUE, l = 3, label = NULL, xpos = 0, ypos = 0.5 )
plotNet3( object, ..., nets = c("temporal", "contemporaneous", "between"), titles = TRUE, l = 3, label = NULL, xpos = 0, ypos = 0.5 )
object |
|
... |
Additional arguments. |
nets |
Character vector of length 3 indicating which networks to plot,
and in what order. Same options as for |
titles |
If |
l |
A numeric value to indicate a type of pane layout. |
label |
Can include a character string for text annotation. |
xpos |
Numeric, x-axis value for where the text annotation should go. Between 0 and 1. |
ypos |
numeric, y-axis value for where the text annotation should go. Between 0 and 1. |
Returns 3 network plots.
x <- mlGVAR(mlgvarDat, 'M') plotNet3(x)
x <- mlGVAR(mlgvarDat, 'M') plotNet3(x)
Plots the output from the mnetPowerSim
function.
plotPower( x, by = "type", yvar = "default", yadd = NULL, hline = 0.8, xlab = "Number of cases", title = NULL, ... ) ## S3 method for class 'mnetPower' plot( x, by = "type", yvar = "default", yadd = NULL, hline = 0.8, xlab = "Number of cases", title = NULL, ... )
plotPower( x, by = "type", yvar = "default", yadd = NULL, hline = 0.8, xlab = "Number of cases", title = NULL, ... ) ## S3 method for class 'mnetPower' plot( x, by = "type", yvar = "default", yadd = NULL, hline = 0.8, xlab = "Number of cases", title = NULL, ... )
x |
|
by |
In development. Currently only supports |
yvar |
The performance metrics to plot. Options include:
|
yadd |
Specify additional performance metrics to plot. The final
performance metrics that end up being plotted are simply: |
hline |
Numeric value between 0 and 1 for where to plot a horizontal
line of interest. Can set to |
xlab |
Character string for the x-axis label. |
title |
Character string for the title of the plot. |
... |
Additional arguments. |
The options of what performance metrics to plot include:
Sensitivity
Specificity
Correlation
MAE (Mean Absolute Error)
Precision
Accuracy
FDR (False Discovery Rate)
Plots the results of a power simulation according to a variety of performance metrics.
x <- mnetPowerSim(niter = 10, N = c(100, 200)) summary(x) plot(x)
x <- mnetPowerSim(niter = 10, N = c(100, 200)) summary(x) plot(x)
Plots the empirical cumulative distribution function of the p-values related to iterated resampling via bootstrapping or multi-sample splitting.
plotPvals(x, outcome = 1, predictor = 1, title = TRUE, alpha = 0.05)
plotPvals(x, outcome = 1, predictor = 1, title = TRUE, alpha = 0.05)
x |
Output from |
outcome |
Character string or numeric value (in terms of columns in the dataset) to indicate which outcome to plot the p-value distribution for. |
predictor |
Character string or numeric value (in terms of columns in the dataset) to indicate which predictor to plot the p-value distribution for. |
title |
If |
alpha |
The false discovery rate. Defaults to .05 |
See Meinshausen, Meier, & Buhlmann (2009) for details.
Returns a plot based on the relationship between a particular outcome and predictor.
Meinshausen, N., Meier, L., & Buhlmann, P. (2009). P-values for high-dimensional regression. Journal of the American Statistical Association. 104, 1671-1681.
x <- resample(ggmDat, sampMethod = "bootstrap") plot(x, what = 'pvals') plot(x, 'pvals', outcome = 'V2', predictor = 'V1')
x <- resample(ggmDat, sampMethod = "bootstrap") plot(x, what = 'pvals') plot(x, 'pvals', outcome = 'V2', predictor = 'V1')
Creates a plot to show the stability path for a particular variable in terms of how frequently it was chosen in stability selection.
plotStability( x, outcome = 1, s = c("simult", "split1", "split2"), thresh = 0.5, typeLegend = TRUE )
plotStability( x, outcome = 1, s = c("simult", "split1", "split2"), thresh = 0.5, typeLegend = TRUE )
x |
Output of |
outcome |
Character string or numeric value (in terms of columns in the dataset) to indicate which outcome to plot the stability path for. |
s |
Character string or numeric value. This indicates which stability
path to return a plot for. Either the first sample split |
thresh |
The selection threshold, which is represented as a horizontal red line on the plot. Defaults to .5 |
typeLegend |
Logical. If |
See Meinshausen & Buhlmann (2010) for details on stability selection. Cannot be used when the criterion for stability selection was set as cross-validation.
Plot of the stability path associated with a given outcome.
Meinshausen, N., & Buhlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: Series B (Statistical Methodology). 72, 417-423
x <- resample(ggmDat, sampMethod = "stability") plot(x, what = "stability") plot(x, 'stability', outcome = 'V3')
x <- resample(ggmDat, sampMethod = "stability") plot(x, what = "stability") plot(x, 'stability', outcome = 'V3')
See the prediction error based on different statistics for either GGMs or SURs. Also can compare and find the change values (such as R-squared change) between two networks of the same size (i.e., with the same nodes).
predictNet(object, data = NULL, all = FALSE, scale = FALSE)
predictNet(object, data = NULL, all = FALSE, scale = FALSE)
object |
Output from |
data |
The dataset used to fit the network model, or another network of
the same type and size to be compared with the network specified in the
first argument. If the prediction error for only one network is desired,
and the dataset is included as an element of the relevant object, then this
can be left as |
all |
if |
scale |
Logical; determines whether or not to standardize the data before computing prediction error. This argument will be removed. |
A table showing different measures of prediction error associated
with each node of the network. Or, if two networks are provided, a table
that shows the difference in prediction error for each node across the two
networks. Specifically, this is computed by taking the statistics for
data
and subtracting them from those for object
.
If all = TRUE
, then the following output is returned:
The observed values of the outcome variables based on the data provided.
The predicted values of the outcomes based on the models provided.
Table containing prediction error statistics for each node.
fit1 <- fitNetwork(ggmDat, covariates = 'M') fit2 <- fitNetwork(ggmDat, moderators = 'M') predictNet(fit1) predictNet(fit1, all = TRUE) predictNet(fit2, fit1) # Find the differences in prediction error across the two models
fit1 <- fitNetwork(ggmDat, covariates = 'M') fit2 <- fitNetwork(ggmDat, moderators = 'M') predictNet(fit1) predictNet(fit1, all = TRUE) predictNet(fit2, fit1) # Find the differences in prediction error across the two models
Multiple resampling procedures for selecting variables for a final network model. There are three resampling methods that can be parameterized in a variety of different ways. The ultimate goal is to fit models across iterated resamples with variable selection procedures built in so as to home in on the best predictors to include within a given model. The methods available include: bootstrapped resampling, multi-sample splitting, and stability selection.
resample( data, m = NULL, niter = 10, sampMethod = "bootstrap", criterion = "AIC", method = "glmnet", rule = "OR", gamma = 0.5, nfolds = 10, nlam = 50, which.lam = "min", threshold = FALSE, bonf = FALSE, alpha = 0.05, exogenous = TRUE, split = 0.5, center = TRUE, scale = FALSE, varSeed = NULL, seed = NULL, verbose = TRUE, lags = NULL, binary = NULL, type = "g", saveMods = TRUE, saveData = FALSE, saveVars = FALSE, fitit = TRUE, nCores = 1, cluster = "mclapply", block = FALSE, beepno = NULL, dayno = NULL, ... )
resample( data, m = NULL, niter = 10, sampMethod = "bootstrap", criterion = "AIC", method = "glmnet", rule = "OR", gamma = 0.5, nfolds = 10, nlam = 50, which.lam = "min", threshold = FALSE, bonf = FALSE, alpha = 0.05, exogenous = TRUE, split = 0.5, center = TRUE, scale = FALSE, varSeed = NULL, seed = NULL, verbose = TRUE, lags = NULL, binary = NULL, type = "g", saveMods = TRUE, saveData = FALSE, saveVars = FALSE, fitit = TRUE, nCores = 1, cluster = "mclapply", block = FALSE, beepno = NULL, dayno = NULL, ... )
data |
|
m |
Character vector or numeric vector indicating the moderator(s), if
any. Can also specify |
niter |
Number of iterations for the resampling procedure. |
sampMethod |
Character string indicating which type of procedure to use.
|
criterion |
The criterion for the variable selection procedure. Options
include: |
method |
Character string to indicate which method to use for variable
selection. Options include |
rule |
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The |
gamma |
Numeric value of the hyperparameter for the |
nfolds |
Only relevant if |
nlam |
if |
which.lam |
Character string. Only applies if |
threshold |
Logical or numeric. If |
bonf |
Logical. Determines whether to apply a bonferroni adjustment on the distribution of p-values for each coefficient. |
alpha |
Type 1 error rate. Defaults to .05. |
exogenous |
Logical. Indicates whether moderator variables should be
treated as exogenous or not. If they are exogenous, they will not be
modeled as outcomes/nodes in the network. If the number of moderators
reaches |
split |
If |
center |
Logical. Determines whether to mean-center the variables. |
scale |
Logical. Determines whether to standardize the variables. |
varSeed |
Numeric value providing a seed to be set at the beginning of the selection procedure. Recommended for reproducible results. Importantly, this seed will be used for the variable selection models at each iteration of the resampler. Caution this means that while each model is run with a different sample, it will always have the same seed. |
seed |
Can be a single value, to set a seed before drawing random seeds
of length |
verbose |
Logical. Determines whether information about the modeling progress should be displayed in the console. |
lags |
Numeric or logical. Can only be 0, 1 or |
binary |
Numeric vector indicating which columns of the data contain binary variables. |
type |
Determines whether to use gaussian models |
saveMods |
Logical. Indicates whether to save the models fit to the samples at each iteration or not. |
saveData |
Logical. Determines whether to save the data from each subsample across iterations or not. |
saveVars |
Logical. Determines whether to save the variable selection models at each iteration. |
fitit |
Logical. Determines whether to fit the final selected model on
the original sample. If |
nCores |
Numeric value indicating the number of CPU cores to use for the
resampling. If |
cluster |
Character vector indicating which type of parallelization to
use, if |
block |
Logical or numeric. If specified, then this indicates that
|
beepno |
Character string or numeric value to indicate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
dayno |
Character string or numeric value to indiciate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
... |
Additional arguments. |
Sampling methods can be specified via the sampMethod
argument.
Standard bootstrapped resampling,
wherein a bootstrapped sample of size n
is drawn with replacement at
each iteration. Then, a variable selection procedure is applied to the
sample, and the selected model is fit to obtain the parameter values.
P-values and confidence intervals for the parameter distributions are then
estimated.
Involves taking two disjoint samples from the original data – a training sample and a test sample. At each iteration the variable selection procedure is applied to the training sample, and then the resultant model is fit on the test sample. Parameters are then aggregated based on the coefficients in the models fit to the test samples.
Stability selection begins the same as multi-sample splitting, in that two disjoint samples are drawn from the data at each iteration. However, the variable selection procedure is then applied to each of the two subsamples at each iteration. The objective is to compute the proportion of times that each predictor was selected in each subsample across iterations, as well as the proportion of times that it was simultaneously selected in both disjoint samples. At the end of the resampling, the final model is selected by setting a frequency threshold between 0 and 1, indicating the minimum proportion of samples that a variable would have to have been selected to be retained in the final model.
For the bootstrapping and multi-sample split methods, p-values are aggregated for each parameter using a method developed by Meinshausen, Meier, & Buhlmann (2009) that employs error control based on the false-discovery rate. The same procedure is employed for creating adjusted confidence intervals.
A key distinguishing feature of the bootstrapping procedure implemented in
this function versus the bootNet
function is that the latter is
designed to estimate the parameter distributions of a single model, whereas
the version here is aimed at using the bootstrapped resamples to select a
final model. In a practical sense, this boils down to using the bootstrapping
method in the resample
function to perform variable selection
at each iteration of the resampling, rather than taking a single constrained
model and applying it equally at all iterations.
resample
output
Meinshausen, N., Meier, L., & Buhlmann, P. (2009). P-values for high-dimensional regression. Journal of the American Statistical Association. 104, 1671-1681.
Meinshausen, N., & Buhlmann, P. (2010). Stability selection. Journal of the Royal Statistical Society: Series B (Statistical Methodology). 72, 417-423
plot.resample, modSelect, fitNetwork,
bootNet, mlGVAR, plotNet, plotCoefs,
plotBoot, plotPvals, plotStability, net,
netInts, glinternet::glinternet,
glinternet::glinternet.cv,
glmnet::glmnet,
glmnet::cv.glmnet,
leaps::regsubsets
fit1 <- resample(ggmDat, m = 'M', niter = 10) net(fit1) netInts(fit1) plot(fit1) plot(fit1, what = 'coefs') plot(fit1, what = 'bootstrap', multi = TRUE) plot(fit1, what = 'pvals', outcome = 2, predictor = 4) fit2 <- resample(gvarDat, m = 'M', niter = 10, lags = 1, sampMethod = 'stability') plot(fit2, what = 'stability', outcome = 3)
fit1 <- resample(ggmDat, m = 'M', niter = 10) net(fit1) netInts(fit1) plot(fit1) plot(fit1, what = 'coefs') plot(fit1, what = 'bootstrap', multi = TRUE) plot(fit1, what = 'pvals', outcome = 2, predictor = 4) fit2 <- resample(gvarDat, m = 'M', niter = 10, lags = 1, sampMethod = 'stability') plot(fit2, what = 'stability', outcome = 3)
Indicates the minimum sample size required to fit a moderated or unmoderated
network model based on the number of nodes p
, number of moderators
m
, and the number of lags.
sampleSize(p, m = 0, lags = 0, print = TRUE)
sampleSize(p, m = 0, lags = 0, print = TRUE)
p |
Number of nodes |
m |
Number of moderator variables (defaults to |
lags |
Number of lags (currently only supports |
print |
if |
When lags = 0
, the minimum sample size N refers to the number
of subjects, whereas when lags = 1
it is assumed that a single subject
is being measured at multiple time points, where N refers to the
number of time points.
Minimum sample size to fit a network model according to the specified parameters.
sampleSize(p = 10) sampleSize(p = 10, m = 1) sampleSize(p = 10, m = 1, lags = 1) minSamp <- sampleSize(p = 10, m = 1, lags = 1, print = FALSE)
sampleSize(p = 10) sampleSize(p = 10, m = 1) sampleSize(p = 10, m = 1, lags = 1) minSamp <- sampleSize(p = 10, m = 1, lags = 1, print = FALSE)
Provides a quick representation showing which variables were selected as
predictors of each node in a network, both for unmoderated and moderated
networks. Especially useful as a way to see which variables were selected in
a variable selection procedure, such as through the varSelect
and resample
functions.
selected(object, threshold = FALSE, mod = c("temporal", "between"))
selected(object, threshold = FALSE, mod = c("temporal", "between"))
object |
Output from either |
threshold |
Can be a numeric value between |
mod |
Only relevant to models fit with |
The threshold
argument allows the user to set a threshold for
p-values, such that the output only reflects the predictors that are
significant at that threshold. This argument can be utilized whether or not a
variable selection procedure has been employed.
A table where the columns represent nodes, and the rows show which
variables were selected in predicting each node. For moderated networks,
the output is a list that separates main effects (mods
) from
interaction effects (ints
).
fit1 <- fitNetwork(ggmDat) selected(fit1) fit2 <- mlGVAR(mlgvarDat, m = 'M', verbose = FALSE) selected(fit2, threshold = TRUE, mod = 'temporal') # Can also set to 'between' fit3 <- fitNetwork(gvarDat, moderators = 'M', type = 'varSelect', lags = 1) selected(fit3)
fit1 <- fitNetwork(ggmDat) selected(fit1) fit2 <- mlGVAR(mlgvarDat, m = 'M', verbose = FALSE) selected(fit2, threshold = TRUE, mod = 'temporal') # Can also set to 'between' fit3 <- fitNetwork(gvarDat, moderators = 'M', type = 'varSelect', lags = 1) selected(fit3)
Used for generating moderated and unmoderated adjacency matrices, along with data based on those model structures.
simNet( N = 100, p = 5, m = FALSE, m2 = 0.1, b1 = NULL, b2 = NULL, sparsity = 0.5, intercepts = NULL, nIter = 250, msym = FALSE, onlyDat = FALSE, pbar = TRUE, div = 10, gibbs = TRUE, ordinal = FALSE, nLevels = 5, mord = FALSE, time = TRUE, mbinary = FALSE, minOrd = 3, m1 = NULL, m1_range = NULL, m2_range = c(0.1, 0.3), modType = "none", lags = NULL, V = 2, skewErr = FALSE, onlyNets = FALSE, netArgs = NULL, nCores = 1, cluster = "SOCK", getChains = FALSE, const = 1.5, fixedPar = NULL, V2 = 1, ... )
simNet( N = 100, p = 5, m = FALSE, m2 = 0.1, b1 = NULL, b2 = NULL, sparsity = 0.5, intercepts = NULL, nIter = 250, msym = FALSE, onlyDat = FALSE, pbar = TRUE, div = 10, gibbs = TRUE, ordinal = FALSE, nLevels = 5, mord = FALSE, time = TRUE, mbinary = FALSE, minOrd = 3, m1 = NULL, m1_range = NULL, m2_range = c(0.1, 0.3), modType = "none", lags = NULL, V = 2, skewErr = FALSE, onlyNets = FALSE, netArgs = NULL, nCores = 1, cluster = "SOCK", getChains = FALSE, const = 1.5, fixedPar = NULL, V2 = 1, ... )
N |
Numeric value. Total number of subjects. |
p |
Numeric value. Total number of nodes (excluding moderator). |
m |
If a value is provided, a moderator is generated and named |
m2 |
Numeric. If |
b1 |
Can provide an adjacency matrix to use for generating data. |
b2 |
Can provide an interaction matrix for generated moderated data. |
sparsity |
Numeric value between 0 and 1. Determines the sparsity of sampled network matrices. |
intercepts |
A vector of means for sampling node values. |
nIter |
Number of iterations for generating each instance of a datapoint with the Gibbs sampler. |
msym |
If |
onlyDat |
If |
pbar |
If |
div |
A value to use as a sign that the sampler diverged. Can be
increased based on expected range of values. If a datapoint is larger than
|
gibbs |
If |
ordinal |
Logical. Determines whether to generate ordinal values or not. |
nLevels |
Number of levels for the ordinal variables. Only relevant if
|
mord |
Logical. Determines whether the moderator variable should be simulated as ordinal. |
time |
If |
mbinary |
Logical. Determines whether the moderator should be a binary variable. |
minOrd |
The minimum number of unique values allowed for each variable. |
m1 |
Functions similarly to |
m1_range |
Numeric vector of length 2. The range of values for moderator main effect coefficients. |
m2_range |
Numeric vector of length 2. The range of values for moderator interaction effect coefficients. |
modType |
Determines the type of moderation to employ, such as
|
lags |
If |
V |
Numeric, either 1 or 2. Determines whether to randomize the order of
simulating node values at each iteration of the Gibbs sampler. If |
skewErr |
The skewness parameter for the |
onlyNets |
If |
netArgs |
Only for use by the internal function
|
nCores |
Numeric value indicating the number of CPU cores to use for the
resampling. If |
cluster |
Character vector indicating which type of parallelization to
use, if |
getChains |
Logical. Determines whether to return the data-generating chains from the Gibbs sampler. |
const |
Numeric. The constant to be used by the internal
|
fixedPar |
Numeric. If provided, then this will be set as the
coefficient value for all edges in the network. Provides a way to
standardize the parameter values while varying the sparsity of the network.
If |
V2 |
If |
... |
Additional arguments. |
If no moderator is specified then data can be generated directly from a
partial correlation matrix by setting gibbs = FALSE
, which produces
fast simulation results. Alternatively, a Gibbs sampler is used to generate
data, which is the default option. For moderated networks, Gibbs sampling is
the only method available.
Simulated network models as well as data generated from those models.
For GGMs, model matrices are always symmetric. For temporal networks (when
lags = 1
), columns predict rows.
Importantly, the Gibbs sampler can easily diverge given certain model
parameters. Generating network data based on moderator variables can
produce data that quickly take on large values due to the presence of
multiplicative terms. If the simulation fails, first simply try re-running
the function with a different seed; this will often be sufficient to solve
the problem when default parameters are specified. Additionally, one can
increase the value of div
, in case the sampler only diverges
slightly or simply produced an anomalous value. This raises the threshold
of tolerated values before the sampler stops. If supplying user-generated
model matrices (for the b1
and/or b2
arguments) and the
function continues to fail, you will likely need to change the parameter
values in those matrices, as it may not be possible to simulate data under
the given values. If simulating the model matrices inside the function (as
is the default) and the function continues to fail, try adjusting the
following parameters:
Try reducing the value of m2
to specify fewer interactions.
Try reducing a range with a smaller
maximum for m2_range
, to adjust the range of interaction
coefficients.
Try adjusting the corresponding main effect parameters
for the moderator, m1
and m1_range
.
Try setting
modType = "full"
to reduce the number of main effect parameters.
Try setting a low value(s) for fixedPar
, in order to provide
parameter values that are known to be lower
An alternative approach could be to use the internal function
simNet2
, which is a wrapper designed to re-run simNet
when it
fails and automatically adjust simulation parameters such as div
to
thoroughly test a given parameterization scheme. This function can be
accessed via modnets:::simNet2
. There is not documentation for this
function, so it is recommended to look at the source code if one wishes to
use it This wrapper is also used inside the mnetPowerSim
function.
mlGVARsim, mnetPowerSim, plotNet,
net, netInts, plotBoot, plotCoefs
# Generate a moderated GGM along with data set.seed(1) x <- simNet(N = 100, p = 3, m = TRUE) net(x) # Get data-generating adjacency matrix netInts(x) # Get data-generating interaction matrix plot(x) # Plot the moderated network that generated the data # Generate a single-subject GVAR model with data set.seed(1) x <- simNet(N = 500, p = 3, m = TRUE, lags = 1) net(x, n = 'temporal') # Get the data-generating time-lagged adjacency matrix net(x, n = 'contemporaneous') # Get the data-generating standardized residual covariance matrix plot(x, which.net = 'beta') # 'beta' is another way of referring to the temporal network plot(x, which.net = 'pcc') # 'pcc' is another way of referring to the contemporaneous network
# Generate a moderated GGM along with data set.seed(1) x <- simNet(N = 100, p = 3, m = TRUE) net(x) # Get data-generating adjacency matrix netInts(x) # Get data-generating interaction matrix plot(x) # Plot the moderated network that generated the data # Generate a single-subject GVAR model with data set.seed(1) x <- simNet(N = 500, p = 3, m = TRUE, lags = 1) net(x, n = 'temporal') # Get the data-generating time-lagged adjacency matrix net(x, n = 'contemporaneous') # Get the data-generating standardized residual covariance matrix plot(x, which.net = 'beta') # 'beta' is another way of referring to the temporal network plot(x, which.net = 'pcc') # 'pcc' is another way of referring to the contemporaneous network
A quick way to view the results of power simulations conducted with
mnetPowerSim
.
## S3 method for class 'mnetPower' summary(object, ind = "all", order = NULL, decreasing = FALSE, ...)
## S3 method for class 'mnetPower' summary(object, ind = "all", order = NULL, decreasing = FALSE, ...)
object |
Output from |
ind |
Character string or vector to indicate which aspects of the
results to view. If |
order |
Character string referring to which output index to organize output by. |
decreasing |
Logical. Determines whether to organize values from highest
to lowest or vice versa according to the value of the |
... |
Additional arguments. |
Summary table, or list of summary tables.
x <- mnetPowerSim(niter = 10, N = c(100, 200)) summary(x) plot(x)
x <- mnetPowerSim(niter = 10, N = c(100, 200)) summary(x) plot(x)
A wrapper for the systemfit::systemfit
function that will construct formulas for all equations based on specified
moderators. This function was NOT designed for user-level functionality, but
rather exists to be embedded within fitNetwork
. The purpose for
making it available to the user is for allowing the exact fitted model to be
highly customizable.
SURfit( data, varMods = NULL, mod = "min", maxiter = 100, m = NULL, type = "g", center = TRUE, scale = FALSE, exogenous = TRUE, covs = NULL, sur = TRUE, consec = NULL, ... )
SURfit( data, varMods = NULL, mod = "min", maxiter = 100, m = NULL, type = "g", center = TRUE, scale = FALSE, exogenous = TRUE, covs = NULL, sur = TRUE, consec = NULL, ... )
data |
Dataframe or matrix containing idiographic temporal data. |
varMods |
Output of |
mod |
Character string. Only applies if output from
|
maxiter |
Numeric. The maximum number of iterations to attempt before stopping the function. |
m |
Character string or numeric value to specify the moderator (if any). |
type |
Indicates the type of model to use, either |
center |
Logical. Determines whether to mean-center the variables. |
scale |
Logical. Determines whether to standardize the variables. |
exogenous |
Logical. See |
covs |
something |
sur |
Logical. Provides input to the |
consec |
A logical vector that identifies which values to include in
accordance with the |
... |
Additional arguments. |
See the systemfit
package for details on customizing
systemfit::systemfit
objects. Constraints
can be applied via the varMods
argument, which is intended to
facilitate the output of the varSelect
and
resample
functions. These objects can be further edited to
apply constraints not specified by these automated functions. Moreover, there
are a variety of additional arguments that can be supplied to the
systemfit::systemfit
function if desired.
If the variable selection results from resample
are intended to
be used as input for the varMods
argument, then these results must be
fed into the modSelect
function.
A SUR model, as fit with the
systemfit::systemfit
function.
SURnet, fitNetwork,
systemfit::systemfit
A method for converting outputs from the
systemfit::systemfit
function into
temporal and contemporaneous networks. Intended as an internal function of
fitNetwork
. Not intended for use by the user. The only purpose
of making it available is to allow for extreme customization, and the
capacity to convert any
systemfit::systemfit
output into a pair of
network models compatible with the modnets
package.
SURnet( fit, dat, s = "sigma", m = NULL, threshold = FALSE, mval = NULL, medges = 1, pcor = "none" )
SURnet( fit, dat, s = "sigma", m = NULL, threshold = FALSE, mval = NULL, medges = 1, pcor = "none" )
fit |
Output from |
dat |
A list containing elements |
s |
Character string indicating which type of residual covariance matrix
to compute for SUR models. Options include |
m |
Character string or numeric value to specify the moderator (if any). |
threshold |
See corresponding argument of |
mval |
Numeric. See corresponding argument of |
medges |
Numeric. See corresponding argument of |
pcor |
See corresponding argument of |
Temporal and contemporaneous networks
SURfit, fitNetwork,
systemfit::systemfit
Perform variable selection via the LASSO, best subsets selection, forward selection, backward selection, or sequential replacement on unmoderated networks. Or, perform variable selection via the hierarchical LASSO for moderated networks. Can be used for both GGMs and SUR networks.
varSelect( data, m = NULL, criterion = "AIC", method = "glmnet", lags = NULL, exogenous = TRUE, type = "g", center = TRUE, scale = FALSE, gamma = 0.5, nfolds = 10, varSeed = NULL, useSE = TRUE, nlam = NULL, covs = NULL, verbose = TRUE, beepno = NULL, dayno = NULL )
varSelect( data, m = NULL, criterion = "AIC", method = "glmnet", lags = NULL, exogenous = TRUE, type = "g", center = TRUE, scale = FALSE, gamma = 0.5, nfolds = 10, varSeed = NULL, useSE = TRUE, nlam = NULL, covs = NULL, verbose = TRUE, beepno = NULL, dayno = NULL )
data |
|
m |
Character vector or numeric vector indicating the moderator(s), if
any. Can also specify |
criterion |
The criterion for the variable selection procedure. Options
include: |
method |
Character string to indicate which method to use for variable
selection. Options include |
lags |
Numeric or logical. Can only be 0, 1 or |
exogenous |
Logical. Indicates whether moderator variables should be
treated as exogenous or not. If they are exogenous, they will not be
modeled as outcomes/nodes in the network. If the number of moderators
reaches |
type |
Determines whether to use gaussian models |
center |
Logical. Determines whether to mean-center the variables. |
scale |
Logical. Determines whether to standardize the variables. |
gamma |
Numeric value of the hyperparameter for the |
nfolds |
Only relevant if |
varSeed |
Numeric value providing a seed to be set at the beginning of the selection procedure. Recommended for reproducible results. |
useSE |
Logical. Only relevant if |
nlam |
if |
covs |
Numeric or character string indicating a variable to be used as a covariate. Currently not working properly. |
verbose |
Logical. Determines whether to provide output to the console about the status of the procedure. |
beepno |
Character string or numeric value to indicate which variable
(if any) encodes the survey number within a single day. Must be used in
conjunction with |
dayno |
Character string or numeric value to indicate which variable (if
any) encodes the survey number within a single day. Must be used in
conjunction with |
The primary value of the output is to be used as input when fitting the
selected model with the fitNetwork
function. Specifically, the
output of varSelect
can be assigned to the type
argument
of fitNetwork
in order to fit the constrained models that were
selected across nodes.
For moderated networks, the only variable selection approach available is
through the glinternet
package, which implements the hierarchical
LASSO. The criterion for model selection dictates which function from the
package is used, where information criteria use the
glinternet::glinternet
function to
compute models, and cross-validation calls the
glinternet::glinternet.cv
function.
List of all models, with the selected variables for each along with
model coefficients and the variable selection models themselves. Primarily
for use as input to the type
argument of the
fitNetwork
function.
resample, fitNetwork, bootNet,
mlGVAR, glinternet::glinternet,
glinternet::glinternet.cv,
glmnet::glmnet,
glmnet::cv.glmnet,
leaps::regsubsets
vars1 <- varSelect(ggmDat, criterion = 'BIC', method = 'subset') fit1 <- fitNetwork(ggmDat, type = vars1) vars2 <- varSelect(ggmDat, criterion = 'CV', method = 'glmnet') fit2 <- fitNetwork(ggmDat, type = vars2, which.lam = 'min') # Add a moderator vars3 <- varSelect(ggmDat, m = 'M', criterion = 'EBIC', gamma = .5) fit3 <- fitNetwork(ggmDat, moderators = 'M', type = vars3)
vars1 <- varSelect(ggmDat, criterion = 'BIC', method = 'subset') fit1 <- fitNetwork(ggmDat, type = vars1) vars2 <- varSelect(ggmDat, criterion = 'CV', method = 'glmnet') fit2 <- fitNetwork(ggmDat, type = vars2, which.lam = 'min') # Add a moderator vars3 <- varSelect(ggmDat, m = 'M', criterion = 'EBIC', gamma = .5) fit3 <- fitNetwork(ggmDat, moderators = 'M', type = vars3)