Learn R Programming

bootnet (version 0.2)

bootnet: Bootstrapped network estimation

Description

This function can be used to bootstrap network estimation methods so that the spread of parameter and centrality estimates can be assessed.

Usage

bootnet(data, nBoots = 1000, default = c("none", "EBICglasso", "pcor","IsingFit","IsingLL"), type = c("nonparametric","parametric","node","person","jackknife"), model = c("detect","GGM","Ising"), prepFun, prepArgs = list(), estFun, estArgs, graphFun, graphArgs, intFun, intArgs, verbose = TRUE, labels, alpha = 1, subNodes = 2:(ncol(data)-1), subPersons = round(seq(0.25,0.95,length=10)*nrow(data)), computeCentrality = TRUE, propBoot = 1, replacement = TRUE, edgeResample = FALSE)

Arguments

data
A data frame or matrix containing the raw data. Must be numeric, integer or ordered factors.
nBoots
Number of bootstraps
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 criterium 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 criterium 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.

See details section for a more detailed description.

type
The kind of bootstrap method to use.
model
The modeling framework to use. Automatically detects if data is binary or not.
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.
verbose
Logical. Should progress of the function be printed to the console?
labels
A character vector containing the node labels. If omitted the column names of the data are used.
alpha
The centrality tuning parameter as used in centrality.
subNodes
Range of nodes to sample in node-drop bootstrap
subPersons
Range of persons to sample in person-drop bootstrap
computeCentrality
Logical, should centrality be computed?
propBoot
Proportion of persons to sample in bootstraps. Set to lower than 1 for m out of n bootstrap
replacement
Logical, should replacement be used in bootstrap sampling?
edgeResample
Logical, if TRUE only the order of edges based on bootstraps is retained and parameter values of the original network are mapped to this new order.

Value

A bootnet object with the following elements:
sampleTable
A data frame containing all estimated values on the real sample.
bootTable
A data frame containing all estimated values on all bootstrapped samples.
sample
A bootnetResult object with plot and print method containing the estimated network of the real sample.
boots
A list of bootnetResult objects containing the raw bootstrap results.

Details

The following defaults can be used:
default = "EBICglasso"
prepFun
cor_auto from the qgraph package

prepArgs
list(verbose=FALSE)

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()

See Also

plot.bootnet, summary.bootnet

Examples

Run this code
# BFI Extraversion data from psych package:
library("psych")
data(bfi)
bfiSub <- bfi[,11:15]

# 10 bootstraps (using Pearson correlations to speed up):
Results <- bootnet(bfiSub, nBoot = 5, default = "EBICglasso", prepFun = cor, 
                   prepArgs = list(use = "pairwise.complete.obs"))


# Results:
print(Results)

# Estimated network:
plot(Results$sample, layout = 'spring') 

# Estimated values in sample:
Results$sampleTable

# Estimated samples in bootstraps:
Results$bootTable

# Summary table:
summary(Results)

# Summary of strength only:
summary(Results, "strength")

# Plots of edges:
plot(Results, plot = "area", order = "sample")
plot(Results, plot = "interval", order = "sample")

#### Centrality ####

# Node-drop:
# 100 bootstraps (using Pearson correlations to speed up):
NodeDrop <- bootnet(bfiSub, nBoot = 25, default = "EBICglasso", prepFun = cor, 
                   prepArgs = list(use = "pairwise.complete.obs"), type = "node")

# Person-drop:
PersonDrop <- bootnet(bfiSub, nBoot = 25, default = "EBICglasso", prepFun = cor, 
                    prepArgs = list(use = "pairwise.complete.obs"), type = "node")

## Not run: 
#   # 1000 bootstraps (using Pearson correlations to speed up):
#   NodeDrop <- bootnet(bfiSub, nBoot = 1000, default = "EBICglasso", prepFun = cor, 
#                       prepArgs = list(use = "pairwise.complete.obs"), type = "node")
#   
#   # Person-drop:
#   PersonDrop <- bootnet(bfiSub, nBoot = 1000, default = "EBICglasso", prepFun = cor, 
#                         prepArgs = list(use = "pairwise.complete.obs"), type = "node")
# ## End(Not run)

# Plot:
plot(NodeDrop) # Correlation with original
plot(NodeDrop, perNode = TRUE) # Value per sampling level

plot(PersonDrop) # Correlation with original
plot(PersonDrop, perNode = TRUE) # Value per sampling level

Run the code above in your browser using DataLab