Skip to content

Instantly share code, notes, and snippets.

@SachaEpskamp
Created November 18, 2019 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SachaEpskamp/c0761ba43dfd0997ed0092055e80bd68 to your computer and use it in GitHub Desktop.
Save SachaEpskamp/c0761ba43dfd0997ed0092055e80bd68 to your computer and use it in GitHub Desktop.
library("bootnet")
library("mvtnorm")
library("qgraph")
# Sample size:
n <- 40000
# Generate 10-node chain graph with positive edges:
net <- genGGM(10, propPositive = 1, constant = 1.1)
# Form data:
data <- ggmGenerator()(n,net)
# Form error:
error <- rmvnorm(n,sigma=diag(10))
# Add data with error:
data2 <- data + error
# Make ordered (binary):
data3 <- 1 * (data2 < 0)
# Estimate three networks:
net1 <- estimateNetwork(data, default = "ggmModSelect")
net2 <- estimateNetwork(data2, default = "ggmModSelect")
net3 <- estimateNetwork(data3, default = "ggmModSelect")
# Plot everything:
layout(matrix(1:4,2,2,byrow=TRUE))
qgraph(net,layout="circle",theme = "colorblind", title = "True network")
plot(net1,layout="circle", title = "ggmModSelect estimate")
plot(net2,layout="circle", title = "ggmModSelect estimate (with error)")
plot(net3,layout="circle", title = "ggmModSelect estimate (with error and polychorics)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment