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,
...
)
n x k
dataframe or matrix.
Numeric or character vector indicating which variables (if any) to use as moderators.
Primarily used to supply a variable selection object, such as
those created with varSelect
or modSelect
, or
to indicate that a variable selection method should be employed by setting
the value to "varSelect"
. Currently doesn't support setting the
value to "resample"
, although this will be implemented in the
future. Alternatively, this can be used to specify the type of variable for
each node. In this case it should be either a single value --
"gaussian"
or "binomial"
-- or can be a vector of length
k
to specify which of those two types apply to each variable. These
dictate which family to use for the call to
stats::glm
. Cannot use binomial models for SUR
networks.
Logical or numeric, to indicate whether to fit a SUR model or
not. Set to TRUE
or 1 for a SUR model fit to temporal data for a
single subject.
Only useful if type = "varSelect"
, and if the
varSeed
argument is not specified in the ...
Can be used to specify the number of folds in cross-validation
when type = "varSelect"
and criterion = "CV"
. Overwritten if
nfolds
argument is provided.
Only useful if type = "varSelect"
and the criterion is
set to "EBIC"
. This is the hyperparameter for the calculation of
EBIC.
Only useful if criterion = "CV"
, or if a variable
selection object based on cross-validation is supplied for type
.
Options include "min"
, which uses the lambda value that minimizes
the objective function, or "1se"
which uses the lambda value at 1
standard error above the value that minimizes the objective function.
Only applies to GGMs (including between-subjects networks) when a
threshold is supplied. The "AND"
rule will only preserve edges when
both corresponding coefficients have p-values below the threshold, while
the "OR"
rule will preserve an edge so long as one of the two
coefficients have a p-value below the supplied threshold.
Determines whether to standardize all variables or not.
Only applies to SUR networks. Logical. Provides input to the
method
argument of the
systemfit::systemfit
function. If
TRUE
, then the method
will be "SUR"
. If FALSE
,
then the method
will be "OLS"
. These two methods only differ
when constraints are applied. When a saturated model is fit, both methods
produce the same results.
Determines whether to mean-center variables or not.
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.
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.
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 k - 1
or k
, then exogenous
will automatically
be FALSE
.
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.
Character string indicating which type of residual covariance
matrix to compute for SUR models. Options include "res", "dfres",
"sigma"
. "sigma"
uses the residual covariance matrix as computed by
the systemfits
package. "res"
and "dfres"
compute the
matrix based directly on the residual values. "dfres"
is the sample
estimator that uses N - 1
in the denominator, while "res"
just uses N
. Input for SURnet
function.
Only relevant when lags = 1
and exogenous =
FALSE
. Determines the linetype of moderated edges (corresponds to the lty
argument of plot()
).
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.
See argument of SURfit()
function.
Logical. Determines whether to return log-likelihood statistics
with model results. Recommended to keep TRUE
.
Logical. Determines whether to save the fitobj
element
of the output, which contains the nodewise models, or the SUR model output
of systemfit::systemfit
.
Logical. Determines whether to convert the output to a binary, unweighted network. Only relevant for GGMs.
Logical. Determines whether to remove linear trends from time series variables. Only applies to temporal networks.
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
argument. Only relevant to temporal data.
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 beepno
argument. Only relevant to temporal data.
Additional arguments.
A ggm or SUR network
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.
# NOT RUN {
fit1 <- fitNetwork(ggmDat)
# }
# NOT RUN {
fit2 <- fitNetwork(ggmDat, 'M', type = 'varSelect', criterion = 'BIC')
# }
# NOT RUN {
fit3 <- fitNetwork(gvarDat, 'M', lags = 1)
# }
Run the code above in your browser using DataLab