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.
estimateNetwork(data, default = c("none", "EBICglasso", "pcor","IsingFit","IsingSampler",
"huge","adalasso","mgm","relimp", "cor","TMFG", "ggmModSelect", "LoGo",
"graphicalVAR"), fun, prepFun, prepArgs, estFun, estArgs, graphFun, graphArgs,
intFun, intArgs, labels, verbose = TRUE, construct = c("default","function",
"arguments"), .dots = list(), weighted = TRUE, signed = TRUE, directed, datatype,
checkNumeric = FALSE, …, .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, principalDirection = FALSE,
lambda.min.ratio = 0.01, nlambda = 100, threshold = 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, alpha = 0.05, principalDirection = FALSE)
bootnet_cor(data, corMethod = c("cor_auto", "cov", "cor", "npn"), missing = c("pairwise",
"listwise","fiml","stop"), sampleSize = c("maximum", "minimim"), verbose = TRUE,
corArgs = list(), threshold = 0, alpha = 0.05, principalDirection = FALSE)
bootnet_IsingFit(data, tuning = 0.25, missing = c("listwise","stop"), verbose = TRUE,
rule = c("AND","OR"), split = "median", principalDirection = FALSE)
bootnet_IsingSampler(data, missing = c("listwise","stop"), verbose = TRUE,
split = "median", method = c("default","ll","pl","uni","bi"),
principalDirection = FALSE)
bootnet_adalasso(data,missing = c("listwise","stop"), verbose = TRUE, nFolds = 10,
principalDirection = FALSE)
bootnet_huge(data, tuning = 0.5, missing = c("listwise","stop"), verbose = TRUE,
npn = TRUE, criterion = c("ebic","ric","stars"), principalDirection = FALSE,
lambda.min.ratio = 0.01, nlambda = 100)
bootnet_mgm(data, type, level, tuning = 0.5, missing = c("listwise","stop"),
verbose = TRUE, criterion = c("EBIC","CV"), nFolds = 10, order = 2,
rule = c("AND","OR"), binarySign, ...)
bootnet_relimp(data, normalized = TRUE, type = "lmg",
structureDefault = c("none", "custom", "EBICglasso",
"pcor", "IsingFit", "IsingSampler", "huge",
"adalasso", "mgm", "cor", "TMFG", "ggmModSelect",
"LoGo"), missing = c("listwise", "stop"), ..., verbose
= TRUE, threshold = 0)
bootnet_TMFG(data, graphType = c("cor", "pcor"), corMethod =
c("cor_auto", "cov", "cor", "npn"), missing =
c("pairwise", "listwise", "fiml", "stop"), verbose =
TRUE, corArgs = list(), principalDirection = FALSE,
...)
bootnet_LoGo(data, corMethod = c("cor_auto","cov","cor","npn"), missing = c("pairwise",
"listwise","fiml","stop"), verbose = TRUE, corArgs = list(), principalDirection = FALSE,
...)
bootnet_graphicalVAR(data, tuning = 0.5, verbose = TRUE, principalDirection = FALSE,
missing = c("listwise","stop"), ...)
bootnet_ggmModSelect(data,tuning = 0, corMethod = c("cor_auto","cov","cor","npn"),
missing = c("pairwise","listwise","fiml","stop"), sampleSize = c("maximum","minimim"),
verbose = TRUE, corArgs = list(), principalDirection = FALSE, start = c("glasso",
"empty","full"), stepwise = TRUE, nCores = 1, ...)
A data frame or matrix containing the raw data. Must be numeric, integer or ordered factors.
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 \code{EstimateIsing} function from the IsingSampler package. }
\item{\code{"pcor"}}{Partial correlation network (non-regularized Gaussian Markov random field), using \code{cor2pcor} from the corpcor package. Calls \code{bootnet_pcor}.}
\item{\code{"cor"}}{Correlation network.}
\item{\code{"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
.
"TMFG"
Estimates a Triangulated Maximally Filtered Graph, using the function TMFG
of the NetworkToolbox package. Calls bootnet_TMFG
. Note that this estimates a *correlation network* by default (use the 'graphType' argument to estimate a partial correlation network instead).
"LoGo"
Estimates a Local/Global Sparse Inverse Covariance Matrix, using the function LoGo
of the NetworkToolbox package. Calls bootnet_LoGo
.
"relimp"
Estimates a (directed) relative importance network, using the function 'calc.relimp' of the 'relaimpo' package. The 'structureDefault' argument can be used to use a different default set for estimating the structure of the graph. Calls bootnet_relimp
.
"ggmModSelect"
Estimates an unregularized GGM using the glasso algorithm and stepwise model selection, using the 'ggmModSelect' function from the qgraph package. Calls bootnet_ggmModSelect
.
"graphicalVAR"
Estimates a graphical VAR model using the graphicalVAR package. This results in two networks which can be plotted using the 'graph' argument in the plot method. Calls bootnet_graphicalVAR
.
See details section for a more detailed description.
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).
EBIC tuning parameter, used in 'EBICglasso', 'IsingFit', 'huge', 'mgm' and 'ggmModSelect' default sets. Note that the default value differs: 'EBICglasso', 'huge' and 'mgm' use 0.5, 'IsingFit' uses 0.25 and 'ggmModSelect uses 0.
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.
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.
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.
A list with arguments for the function used defined by corMethod
.
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'
)).
Logical used in EBICglasso default set: should the estimated model structure be refitted without LASSO regularization?
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.
A function or character string ("median"
or "mean"
) indicating how to binarize values when estimating an Ising model.
The estimation method used in the IsingSampler default set (see EstimateIsing
).
Logical, should nonparanormal be used in huge default set?
The criterion used in model selection. "ebic"
, "ric"
or "stars"
in the huge default set or "EBIC"
or "CV"
in the mgm default set.
Number of folds used in k-fold cross-validation.
For mgm, see mgm or mgmfit; for relative importance networks, see calc.relimp
See mgm
. Automatically set if not assigned.
Order up until including which interactions are included in the model. See mgm
. Automatically set if not assigned.
See mgm
. Automatically set if not assigned.
Should normalized relative importance be used in relative importance networks?
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.
"cor"
to estimate a correlation network and "pcor"
to estimate a partial correlation network (GGM)
Significance level to test at.
Rescales variables according to the sign of the first eigen-vector. This will lead to most correlations to be positive (positive manifold), leading to negative edges to be substantively interpretable.
Logical indicating if 'ggmModSelect' should use stepwise estimation.
See ggmModSelect
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.
A list with arguments for prepFun
. Defaults to list()
if omitted and default
is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.
A function that takes as input the prepared raw data and estimates a network. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.
A list with arguments for estArgs
. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.
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.
A list with arguments for graphFun
. Defaults to list()
if omitted and default
is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.
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.
A list with arguments for intFun
. Defaults to list()
if omitted and default
is not set. ARGUMENT IS DEPRECATED AND WILL BE REMOVED.
A character vector containing the node labels. If omitted the column names of the data are used.
Logical, currently only used when default = "EBICglasso"
in the cor_auto
function.
Logical, should the analyzed network be weighted?
Logical, should the analyzed network be signed?
Logical, is the analyzed network directed? Usually does not have to be set and is detected automatically.
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.
"normal"
if the data argument is a data frame, or "graphicalVAR"
if the data argument is a data list that can be used as input to the graphicalVAR package.
Logical: should the data be checked to be numeric?
Minimal lambda ratio (LASSO tuning parameter)
Number of LASSO tuning parameters to test
Number of cores to use in estimating networks
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.
Used internally in the bootnet function. Do not use.
Logical. If TRUE attempts to save memory (RAM) by removing some objects from the output. Used by bootnet by default for bootstraps.
A bootnetResult
object with the following elements:
The weights matrix of the network
The intercepts
The results of the estimation procedure
A vector with node labels
Number of nodes in the network
Number of persons in the network
Input used, including the result of the default set used
%% ~Describe the value returned %% If it is a LIST, use %% \item{comp1 }{Description of 'comp1'} %% \item{comp2 }{Description of 'comp2'} %% ...
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. Fhe functions bootnet_
correspond to the functions used when using default sets. E.g, default = "pcor"
sets fun = bootnet_pcor
. As such, the arguments described above can be used depending on the default set used.
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"
cor_auto
from the qgraph package
list(verbose=TRUE)
for estimating a network and list(verbose=FALSE)
for bootstrap samples.
EBICglasso
from the qgraph package
list(n = nrow(data), returnAllResults = TRUE)
function(x)x[['optnet']]
list()
list()
default = "IsingFit"
default = "pcor"
default = "adalasso"
identity
list()
adalasso.net
from the parcor package
list()
function(x)as.matrix(Matrix::forceSymmetric(x$pcor.adalasso)
list()
null
list()
default = "huge"
function(x)huge.npn(na.omit(as.matrix(x)),verbose = FALSE)
, using huge.npn
from the huge package
list()
function(x)huge::huge.select(huge::huge(x,method = "glasso",verbose=FALSE), criterion = "ebic",verbose = FALSE)
, using the huge package
list()
as.matrix(qgraph::wi2net(as.matrix(x$opt.icov)))
, using the huge package
list()
null
list()
Epskamp, S., Borsboom, D., & Fried, E. I. (2016). Estimating psychological networks and their accuracy: a tutorial paper. arXiv preprint, arXiv:1604.08462.
# NOT RUN {
# 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")
# }
Run the code above in your browser using DataLab