estimateNetwork: Estimate a network structure

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/estimateNetwork.R

Description

This function allows for flexible estimation of a network structure using various R packages and model frameworks. This is typically done by using one of the default sets. See details for manual specification. See also Epskamp, Borsboom and Fried (2016) for more details.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
estimateNetwork(data, default = c("none", "EBICglasso", "pcor", "IsingFit", 
      "IsingSampler", "huge", "adalasso", "mgm", "relimp"), fun, prepFun, prepArgs, 
      estFun, estArgs, graphFun, graphArgs, intFun, intArgs, labels, verbose = TRUE,
      construct = c("default","function","arguments"), .dots = list(), weighted = TRUE, 
      signed = TRUE, directed, ..., .input, memorysaver = FALSE)
                
bootnet_EBICglasso(data, tuning = 0.5, corMethod = c("cor_auto","cov","cor","npn"), 
  missing = c("pairwise","listwise","fiml","stop"), sampleSize = c("maximum","minimim"),
  verbose = TRUE, corArgs = list(), refit = FALSE)
  
bootnet_pcor(data, corMethod = c("cor_auto", "cov", "cor", "npn"), missing = c("pairwise",
  "listwise","fiml","stop"), sampleSize = c("maximum", "minimim"), verbose = TRUE, 
  corArgs = list(), threshold = 0)
  
bootnet_IsingFit(data, tuning = 0.25, missing = c("listwise","stop"), verbose = TRUE,
  rule = c("AND","OR"), split = "median")
  
bootnet_IsingSampler(data, missing = c("listwise","stop"), verbose = TRUE,
  split = "median", method = c("default","ll","pl","uni","bi"))
  
bootnet_adalasso(data,missing = c("listwise","stop"), verbose = TRUE, nFolds = 10)
  
bootnet_huge(data, tuning = 0.5, missing = c("listwise","stop"), verbose = TRUE,
  npn = TRUE, criterion = c("ebic","ric","stars"))
  
bootnet_mgm(data, type, lev, tuning = 0.5, missing = c("listwise","stop"), 
  verbose = TRUE, criterion = c("EBIC","CV"), nFolds = 10, degree = 2,
  rule = c("AND","OR"))
  
bootnet_relimp(data, normalized = TRUE, type = "lmg",
  structureDefault = c("none", "custom", "EBICglasso", "pcor", "IsingFit", 
  "IsingSampler", "huge", "adalasso", "mgm"),  missing = c("listwise","stop"),
  ..., verbose = TRUE, threshold = 0)

Arguments

data

A data frame or matrix containing the raw data. Must be numeric, integer or ordered factors.

default

A string indicating the method to use. Specifying a default sets default values to prepFun, prepArgs, estFun, estArgs, graphFun, graphArgs, intFun and intArgs. Setting a default can be omitted but that does require specifying all above mentioned arguments. Current options are:

"EBICglasso"

Gaussian Markov random field estimation using graphical LASSO and extended Bayesian information criterion to select optimal regularization parameter. Using EBICglasso from the qgraph package. Calls bootnet_EBICglasso.

"IsingFit"

Ising model estimation using LASSO regularized nodewise logistic regression and extended Bayesian information criterion to select optimal regularization parameter. Using IsingFit from the IsingFit package. Calls bootnet_IsingFit.

IsingSampler

Calls the EstimateIsing function from the IsingSampler package.

"pcor"

Partial correlation network (non-regularized Gaussian Markov random field), using cor2pcor from the corpcor package. Calls bootnet_pcor.

adalasso

Uses the adalasso.net from the parcor package. Calls bootnet_adalasso.

huge

Uses EBIC model selection of GGM networks estimated via the glasso algorithm as implemented in the huge package (as opposed to glasso and qgraph packages used in default = "EBICglasso"). Uses nonparanormal transformation in preparing the data and does not use polychoric correlations. Calls bootnet_huge.

mgm

Estimates a Mixed graphical model by using the the mgm (or mgmfit in older versions) function of the mgm package. Calls bootnet_mgm.

See details section for a more detailed description.

fun

A custom estimation function, when no default set is used. This must be a function that takes the data as input (first argument) and returns either a weights matrix or a list containing the elements "graph" for the weights matrix, "intercepts" for the intercepts (optional) and "results" for the full estimation results (optional).

tuning

EBIC tuning parameter, used in 'EBICglasso', 'IsingFit', 'huge' and 'mgm' default sets.

corMethod

Correlation method, used in 'EBICglasso' and 'pcor' default sets. "cor_auto" uses cor_auto for polychoric and polyserial correlations, "cov" uses the cov function for covariances, "cor" will use the cor function for correlations and "npn" will apply the nonparanormal transformation (via huge.npn) and then compute correlations.

missing

How to handle missing data? "pairwise" for pairwise deletion, "listwise" for listwise deletion, "fiml" for full-information maximum likelihood and "stop" to stop with an error.

sampleSize

How will sample size be computed in EBICglasso default set? "maximum" takes total number of rows including rows with NA, and "minimum" takes total number of rows that contain no NA.

corArgs

A list with arguments for the function used defined by corMethod.

threshold

Thresholding to use in partial correlation networks. Can be a fixed number to threshold all absolute edges below this value, 'locfdr' for local FDR, or any option corresponding to adjustments in corr.p ('none', 'sig', 'holm', 'hochberg', 'hommel', 'bonferroni', 'BH', 'BY' or 'fdr')).

refit

Logical used in EBICglasso default set: should the estimated model structure be refitted without LASSO regularization?

rule

The rule to use to select an edge in nodewise estimation. "AND" to only select in edge if both regression coefficients are nonzero and "OR" if only one is nonzero. Used in 'IsingFit' and 'mgm' default sets.

split

A function or character string ("median" or "mean") indicating how to binarize values when estimating an Ising model.

method

The estimation method used in the IsingSampler default set (see EstimateIsing).

npn

Logical, should nonparanormal be used in huge default set?

criterion

The criterion used in model selection. "ebic", "ric" or "stars" in the huge default set or "EBIC" or "CV" in the mgm default set.

nFolds

Number of folds used in k-fold cross-validation.

type

For mgm, see mgm or mgmfit; for relative importance networks, see calc.relimp

lev

See mgm or mgmfit.

degree

Degree of mixed model, see mgm or mgmfit

normalized

Should normalized relative importance be used in relative importance networks?

structureDefault

In relative importance networks, default set used to compute the graph structure. Any other arguments used (using ...) are sent to the graph estimator function as well.

prepFun

A function that takes as input the raw data and returns whatever the estimation function needs (as first argument). Typically this function is used to correlate or binarize the data. Defaults to identity if omitted and default is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

prepArgs

A list with arguments for prepFun. Defaults to list() if omitted and default is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

estFun

A function that takes as input the prepared raw data and estimates a network. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

estArgs

A list with arguments for estArgs. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

graphFun

A function that takes the result of estFun and extracts the estimated weights matrix. Defaults to identity if omitted and default is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

graphArgs

A list with arguments for graphFun. Defaults to list() if omitted and default is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

intFun

A function that takes the result of estFun and extracts the estimated intercepts. Defaults to null if omitted and default is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

intArgs

A list with arguments for intFun. Defaults to list() if omitted and default is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.

labels

A character vector containing the node labels. If omitted the column names of the data are used.

verbose

Logical, currently only used when default = "EBICglasso" in the cor_auto function.

weighted

Logical, should the analyzed network be weighted?

signed

Logical, should the analyzed network be signed?

directed

Logical, is the analyzed network directed? Usually does not have to be set and is detected automatically.

construct

Should the estimator function be constructed using new bootnet functionality (function) or old bootnet functionality (arguments)? Will default to function unless arguments such as estFun are used.

.dots

A list of arguments used in the estimation function set by a default set or by the fun argument.

...

A list of arguments used in the estimation function set by a default set or by the fun argument.

.input

Used internally in the bootnet function. Do not use.

memorysaver

Logical. If TRUE attempts to save memory (RAM) by removing some objects from the output. Used by bootnet by default for bootstraps.

Details

NEW FUNCTIONALTIY:

The user can manually specify an estimation method by assigning a custom function to the 'fun' argument. This function must take data as input and output an estimated network.

DEPRECATED OLD FUNCTIONALITY:

The user can manually set the estimation method of the PMRF in bootnet using a set of arguments to the bootnet function. First, the method of preprocessing the data must be defined via the prepFun argument, which must be assigned a function that takes a dataset as input and returns the viable input for the network estimator. The argument prepArgs can be specified a list of arguments to the prepFun function. Data preprocessing typically means correlating the data for the GGM or binarizing it for the Ising model (to this end bootnet provides a binarize function). Next, we estimate the network. To do so, we assign the estFun argument, a function that takes whatever the output of prepFun was and estimates a network. The estArgs argument can be used to assign a list of additional arguments to the function used in estFun. Finally, we need to extract the weights matrix and intercepts. Assigning functions to the graphFun and intFun arguments respectively can do this. An example of how these commands work together to estimate a network using default = "EBICglasso" is shown below:

estimateNetwork(Data, prepFun = cor_auto, prepArgs = list(verbose = FALSE), estFun = qgraph::EBICglasso, estArgs = list(n = nrow(bfi)), graphFun = identity, intFun= null)

The following defaults can be used:

default = "EBICglasso"
prepFun

cor_auto from the qgraph package

prepArgs

list(verbose=TRUE) for estimating a network and list(verbose=FALSE) for bootstrap samples.

estFun

EBICglasso from the qgraph package

estArgs

list(n = nrow(data), returnAllResults = TRUE)

graphFun

function(x)x[['optnet']]

graphArgs

list()

intFun

null

intArgs

list()

default = "IsingFit"
prepFun

binarize

prepArgs

list()

estFun

IsingFit from the IsingFit package

estArgs

list(plot = FALSE, progress = FALSE)

graphFun

function(x)x[['weiadj']]

graphArgs

list()

intFun

function(x)x[['thresholds']]

intArgs

list()

default = "pcor"
prepFun

cor_auto from the qgraph package

prepArgs

list()

estFun

cor2pcor from the corpcor package

estArgs

list()

graphFun

identity

graphArgs

list()

intFun

null

intArgs

list()

default = "adalasso"
prepFun

identity

prepArgs

list()

estFun

adalasso.net from the parcor package

estArgs

list()

graphFun

function(x)as.matrix(Matrix::forceSymmetric(x$pcor.adalasso)

graphArgs

list()

intFun

null

intArgs

list()

default = "huge"
prepFun

function(x)huge.npn(na.omit(as.matrix(x)),verbose = FALSE), using huge.npn from the huge package

prepArgs

list()

estFun

function(x)huge::huge.select(huge::huge(x,method = "glasso",verbose=FALSE), criterion = "ebic",verbose = FALSE), using the huge package

estArgs

list()

graphFun

as.matrix(qgraph::wi2net(as.matrix(x$opt.icov))), using the huge package

graphArgs

list()

intFun

null

intArgs

list()

Value

A bootnetResult object with the following elements:

graph

The weights matrix of the network

intercepts

The intercepts

results

The results of the estimation procedure

labels

A vector with node labels

nNodes

Number of nodes in the network

nPerson

Number of persons in the network

input

Input used, including the result of the default set used

Author(s)

Sacha Epskamp <[email protected]>

References

Epskamp, S., Borsboom, D., & Fried, E. I. (2016). Estimating psychological networks and their accuracy: a tutorial paper. arXiv preprint, arXiv:1604.08462.

See Also

bootnet

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# BFI Extraversion data from psych package:
library("psych")
data(bfi)
bfiSub <- bfi[,1:25]

# Estimate network:
Network <- estimateNetwork(bfiSub, default = "EBICglasso")

## Not run: 
# Some pointers:
print(Network)

# Estimated network:
plot(Network, layout = 'spring') 

# Centrality indices:
library("qgraph")
centralityPlot(Network)

# BIC model selection:
Network_BIC <- estimateNetwork(bfiSub, default = "EBICglasso", tuning = 0)

# Ising model:
Network_BIC <- estimateNetwork(bfiSub, default = "IsingFit")

## End(Not run)

bootnet documentation built on Sept. 6, 2017, 5:03 p.m.