fitNetwork {modnets}R Documentation

Fit cross-sectional and idiographic moderated network models

Description

The main function that ties everything together for both cross-sectional and idiographic (temporal) network models, moderated or otherwise.

Usage

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,
  ...
)

Arguments

data

n x k dataframe or matrix.

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 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.

lags

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.

seed

Only useful if type = "varSelect", and if the varSeed argument is not specified in the ...

folds

Can be used to specify the number of folds in cross-validation when type = "varSelect" and criterion = "CV". Overwritten if nfolds argument is provided.

gamma

Only useful if type = "varSelect" and the criterion is set to "EBIC". This is the hyperparameter for the calculation of EBIC.

which.lam

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.

rule

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.

threshold

Determines whether to employ a p-value threshold on the model. If TRUE then this defaults to .05. Not recommended, as thresholds can be applied post-hoc through the plotting functions, or via the net and netInts functions. Recommended to leave as FALSE.

scale

Determines whether to standardize all variables or not.

std

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.

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 k - 1 or k, then exogenous will automatically be FALSE.

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 "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.

medges

Only relevant when lags = 1 and exogenous = FALSE. Determines the linetype of moderated edges (corresponds to the lty argument of plot()).

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 SURfit() function.

getLL

Logical. Determines whether to return log-likelihood statistics with model results. Recommended to keep TRUE.

saveMods

Logical. Determines whether to save the fitobj element of the output, which contains the nodewise models, or the SUR model output of systemfit::systemfit.

binarize

Logical. Determines whether to convert the output to a binary, unweighted network. Only relevant for GGMs.

fitCoefs

Determines whether to use the getFitCIs function on the output. Not recommended to use. The downside is that this will overwrite the fitobj element of the output which contains the actual models. Better to leave this as FALSE, and then use the getFitCIs function on the object separately.

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 argument. Only relevant to temporal data.

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 beepno argument. Only relevant to temporal data.

...

Additional arguments.

Details

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.

Value

A ggm or SUR network

Examples

fit1 <- fitNetwork(ggmDat)


fit2 <- fitNetwork(ggmDat, 'M', type = 'varSelect', criterion = 'BIC')


fit3 <- fitNetwork(gvarDat, 'M', lags = 1)

[Package modnets version 0.9.0 Index]