Skip to content

Instantly share code, notes, and snippets.

@SachaEpskamp
Created September 1, 2019 03:22
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/08f0a53d7a11744a72e6d067c3d1a148 to your computer and use it in GitHub Desktop.
Save SachaEpskamp/08f0a53d7a11744a72e6d067c3d1a148 to your computer and use it in GitHub Desktop.
library("parSim")
parSim(
### SIMULATION CONDITIONS
# Vary sample size:
sampleSize = c(250, 500, 1000),
# Vary missingness:
missing = c(0, 0.1, 0.25),
reps = 100, # 5 repititions
write = TRUE, # Writing results to a file
name = "missingdata_sims_1", # Name of the file
nCores = 8, # I use 8 cores here
expression = {
### SIMULATION CODE ###
# Packages:
library("psychonetrics")
library("dplyr")
library("bootnet")
# Function needed:
source("compareNetworks.R")
# Generate true network:
trueNet <- genGGM(10, nei = 2, propPositive = 0.8, p = 0.25)
# Generate data:
generator <- ggmGenerator()
Data <- generator(sampleSize, trueNet)
# Add missings:
for (i in 1:ncol(Data)){
Data[runif(sampleSize) < missing,i] <- NA
}
# Estimate model (FDR prune):
mod <- ggm(Data, estimator = "FIML") %>%
runmodel %>%
prune(adjust = "fdr", alpha = 0.05, recursive = FALSE)
# Extract network:
estNet <- getmatrix(mod, "omega")
# Compare to true network:
results <- compareNetworks(trueNet, estNet)
# Return results:
results
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment