simNet {modnets} | R Documentation |
Description
Used for generating moderated and unmoderated adjacency matrices, along withdata 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 ofsampled network matrices. |
intercepts | A vector of means for sampling node values. |
nIter | Number of iterations for generating each instance of a datapointwith the Gibbs sampler. |
msym | If |
onlyDat | If |
pbar | If |
div | A value to use as a sign that the sampler diverged. Can beincreased 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 besimulated as ordinal. |
time | If |
mbinary | Logical. Determines whether the moderator should be a binaryvariable. |
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 moderatormain effect coefficients. |
m2_range | Numeric vector of length 2. The range of values for moderatorinteraction 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 ofsimulating 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 theresampling. If |
cluster | Character vector indicating which type of parallelization touse, if |
getChains | Logical. Determines whether to return the data-generatingchains from the Gibbs sampler. |
const | Numeric. The constant to be used by the internal |
fixedPar | Numeric. If provided, then this will be set as thecoefficient value for all edges in the network. Provides a way tostandardize 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 apartial correlation matrix by setting gibbs = FALSE
, which producesfast simulation results. Alternatively, a Gibbs sampler is used to generatedata, which is the default option. For moderated networks, Gibbs sampling isthe 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 (whenlags = 1
), columns predict rows.
Warning
Importantly, the Gibbs sampler can easily diverge given certain modelparameters. Generating network data based on moderator variables canproduce data that quickly take on large values due to the presence ofmultiplicative terms. If the simulation fails, first simply try re-runningthe function with a different seed; this will often be sufficient to solvethe problem when default parameters are specified. Additionally, one canincrease the value of div
, in case the sampler only divergesslightly or simply produced an anomalous value. This raises the thresholdof tolerated values before the sampler stops. If supplying user-generatedmodel matrices (for the b1
and/or b2
arguments) and thefunction continues to fail, you will likely need to change the parametervalues in those matrices, as it may not be possible to simulate data underthe given values. If simulating the model matrices inside the function (asis the default) and the function continues to fail, try adjusting thefollowing parameters:
Try reducing the value of
m2
to specify fewer interactions.Try reducing a range with a smallermaximum for
m2_range
, to adjust the range of interactioncoefficients.Try adjusting the corresponding main effect parametersfor 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 provideparameter values that are known to be lower
An alternative approach could be to use the internal functionsimNet2
, which is a wrapper designed to re-run simNet
when itfails and automatically adjust simulation parameters such as div
tothoroughly test a given parameterization scheme. This function can beaccessed via modnets:::simNet2
. There is not documentation for thisfunction, so it is recommended to look at the source code if one wishes touse 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 dataset.seed(1)x <- simNet(N = 100, p = 3, m = TRUE)net(x) # Get data-generating adjacency matrixnetInts(x) # Get data-generating interaction matrixplot(x) # Plot the moderated network that generated the data# Generate a single-subject GVAR model with dataset.seed(1)x <- simNet(N = 500, p = 3, m = TRUE, lags = 1)net(x, n = 'temporal') # Get the data-generating time-lagged adjacency matrixnet(x, n = 'contemporaneous') # Get the data-generating standardized residual covariance matrixplot(x, which.net = 'beta') # 'beta' is another way of referring to the temporal networkplot(x, which.net = 'pcc') # 'pcc' is another way of referring to the contemporaneous network
[Package modnets version 0.9.0 Index]