# Load bfi data from psych package:
library("psychTools")
data(bfi)
# Also load dplyr for the pipe operator:
library("dplyr")
# Let's take the agreeableness items, and gender:
ConsData <- bfi %>%
select(A1:A5, gender) %>%
na.omit # Let's remove missingness (otherwise use Estimator = "FIML)
# Define variables:
vars <- names(ConsData)[1:5]
# Model with Cholesky decompositon:
mod <- varcov(ConsData, vars = vars, type = "chol")
# Run model:
mod <- mod %>% runmodel
# Transform to GGM:
mod_trans <- transmod(mod, type = "ggm") %>% runmodel
# Note: runmodel often not needed
# Obtain thresholded GGM:
getmatrix(mod_trans, "omega", threshold = TRUE)
Run the code above in your browser using DataLab