netSimulator: Network Estimation Performance

Description Usage Arguments Details Author(s) Examples

View source: R/netSimulator.R

Description

This function can be used to run a simulation study on the performance of network estimation by varying sample size or any argument used as input to estimateNetwork. The purpose of this function is to provide a way to assess the required sample size given a network structure, as well as to easily perform simulation studies. By default, the function uses genGGM to simulate a chain graph or small-world network. See details for more information. The replicationSimulator function instead assesses how well a network based on a second independent sample would replicate the network based on the first independent sample.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
netSimulator(
      input = genGGM(Nvar = 10), 
      nCases = c(50, 100, 250, 500, 1000, 2500), 
      nReps = 100,
      nCores = 1, 
      default,
      dataGenerator, 
      ...,
      moreArgs = list(),
      moreOutput = list())
    
replicationSimulator(
      input = genGGM(Nvar = 10), 
      nCases = c(50, 100, 250, 500, 1000, 2500), 
      nReps = 100,
      nCores = 1, 
      default,
      dataGenerator, 
      ..., 
      moreArgs = list())

Arguments

input

Either a weights matrix, a list containing elements graph (encoding the weights matrix) and intercepts (encoding the intercepts), or a function generating such objects. By default, genGGM is used to generate a Gaussian graphical model. However, it is reccomended to replace this with a prior expected graph structure.

nCases

The sample sizes to test for.

nReps

Number of repetitions per sampling level.

nCores

Number of cores to use. Set to more than 1 to use parallel computing.

default

Default set used (see estimateNetwork). In most cases, this will set dataGenerator to the relevant generator.

dataGenerator

A function that generates data. The first argument must be the sample size, the second argument must be the output of input. Can often be ignored if default is set.

moreArgs

A named list of arguments to be used when estimating the network, but which should not be interpreted as different conditions. Use this argument to assign arguments that require vectors.

moreOutput

List with functions that take the estimated weights matrix as first argument and the true weights matrix as second argument to produce some output.

...

Arguments used by estimateNetwork to estimate the network structure. Providing a vector for any argument will simulate under each value. This way, any argument in estimateNetwork can be used in a simulation study.

Details

*any* argument to estimateNetwork can be used in a simulation study, with a vector (e.g., rule = c("AND","OR")) specifying that both conditions are tested. Adding too many conditions can quickly make any simulation study intractible, so only vary some arguments! The dataGenerator argument can be any function that generates data. Currently, only ggmGenerator and IsingGenerator are implemented in bootnet itself, which generates data given a Gaussian graphical model.

Author(s)

Sacha Epskamp <[email protected]>

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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
# 5-node GGM chain graph:
trueNetwork <- genGGM(5)

# Simulate:
Res <- netSimulator(trueNetwork, nReps = 10)

# Results:
Res

# Plot:
plot(Res)

## Not run: 
library("bootnet")

# BFI example:
# Load data:
library("psych")
data(bfi)
bfiData <- bfi[,1:25]

# Estimate a network structure, with parameters refitted without LASSO regularization:
library("qgraph")
Network <- EBICglasso(cor_auto(bfiData), nrow(bfiData), refit = TRUE)

# Simulate 100 repititions in 8 cores under different sampling levels:
Sim1 <- netSimulator(Network,
                     default = "EBICglasso",
                     nCases = c(100,250,500),
                     nReps = 100,
                     nCores = 8)

# Table of results:
Sim1

# Plot results:
plot(Sim1)

# Compare different default set at two sampling levels:
Sim2 <- netSimulator(Network,
                     default = c("EBICglasso","pcor","huge"),
                     nCases = c(100,250,500),
                     nReps = 100,
                     nCores = 8)

# Print results:
Sim2

# Plot results:
plot(Sim2, xfacet = "default", yvar = "correlation")

# Difference using polychoric or pearson correlations in ordinal data:
Sim3 <- netSimulator(Network,
                     dataGenerator = ggmGenerator(ordinal = TRUE, nLevels = 4),
                     default = "EBICglasso",
                     corMethod = c("cor","cor_auto"),
                     nCases = c(100,250, 500),
                     nReps = 100,
                     nCores = 8)

# Print results:
Sim3

# Plot results:
plot(Sim3, color = "corMethod")

# Ising model:
trueNetwork <- read.csv('http://sachaepskamp.com/files/weiadj.csv')[,-1]
trueNetwork <- as.matrix(trueNetwork)
Symptoms <- rownames(trueNetwork) <- colnames(trueNetwork)
Thresholds <- read.csv('http://sachaepskamp.com/files/thr.csv')[,-1]

# Create an input list (intercepts now needed)
input <- list(graph=trueNetwork,intercepts=Thresholds)

# Simulate under different sampling levels:
Sim4 <- netSimulator(
  input = input,
  default = "IsingFit",
  nCases = c(250,500,1000),
  nReps = 100,
  nCores = 8)

# Results:
Sim4

# Plot:
plot(Sim4)

# Compare AND and OR rule:
Sim5 <- netSimulator(
  input = input,
  default = "IsingFit",
  nCases = c(250,500,1000),
  rule = c("AND","OR"),
  nReps = 100,
  nCores = 8)

# Print:
Sim5

# Plot:
plot(Sim5, yfacet = "rule")


## End(Not run)

bootnet documentation built on July 28, 2018, 9:03 a.m.