Estimate a network structure

Share:

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
estimateNetwork(data, default = c("none", "EBICglasso", "pcor", "IsingFit", "IsingLL", 
                "huge", "adalasso"), prepFun, prepArgs, estFun, estArgs, 
                graphFun, graphArgs, intFun, intArgs, labels, verbose = TRUE)

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.

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

"pcor"

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

adalasso

Uses the adalasso.net from the parcor package.

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.

See details section for a more detailed description.

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.

prepArgs

A list with arguments for prepFun. Defaults to list() if omitted and default is not set.

estFun

A function that takes as input the prepared raw data and estimates a network.

estArgs

A list with arguments for estArgs

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.

graphArgs

A list with arguments for graphFun. Defaults to list() if omitted and default is not set.

intFun

A function that takes the result of estFun and extracts the estimated intercepts. Defaults to null if omitted and default is not set.

intArgs

A list with arguments for intFun. Defaults to list() if omitted and default is not set.

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.

Details

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 <mail@sachaepskamp.com>

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
# BFI Extraversion data from psych package:
library("psych")
data(bfi)
bfiSub <- bfi[,1:25]

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

# Some pointers:
print(Network)

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

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

## End(Not run)