simNet {modnets} | R Documentation |
Simulate network structure and data
Description
Used for generating moderated and unmoderated adjacency matrices, along with data based on those model structures.
Usage
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,
...
)
Arguments
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. |
Details
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.
Value
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.
Warning
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
andm1_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.
See Also
mlGVARsim, mnetPowerSim, plotNet,
net, netInts, plotBoot, plotCoefs
Examples
# 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