# 5-node GGM chain graph:
trueNetwork <- genGGM(5)
# Simulate:
Res <- netSimulator(trueNetwork, nReps = 10)
# Results:
Res
# \donttest{
# Plot:
plot(Res)
# BFI example:
# Load data:
library("psychTools")
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_EBICglasso <- netSimulator(Network,
default = c("EBICglasso"),
nCases = c(100,250,500),
nReps = 100,
nCores = 8)
Sim2_pcor <- netSimulator(Network,
default = c("pcor"),
nCases = c(100,250,500),
nReps = 100,
nCores = 8)
Sim2_huge <- netSimulator(Network,
default = c("huge"),
nCases = c(100,250,500),
nReps = 100,
nCores = 8)
Sim2 <- rbind(Sim2_EBICglasso, Sim2_pcor, Sim2_huge)
# 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")
# }
Run the code above in your browser using DataLab