Skip to content

Instantly share code, notes, and snippets.

@SachaEpskamp
Created February 11, 2020 13:54
Show Gist options
  • Save SachaEpskamp/985b7483a2195a1f4720c32e1bcdf01b to your computer and use it in GitHub Desktop.
Save SachaEpskamp/985b7483a2195a1f4720c32e1bcdf01b to your computer and use it in GitHub Desktop.
library("psychonetrics")
library("psychTools")
library("dplyr")
data("bfi")
# Extraversion and Neuroticism items:
data <- bfi[,11:20]
# ggm model:
mod_ggm <- ggm(data, estimator = "FIML") %>%
runmodel %>%
prune %>%
modelsearch
# CFA model:
latents <- c("extraversion","neuroticism")
lambda <- matrix(0,10,2)
lambda[1:5,1] <- lambda[6:10,2] <- 1
mod_cfa <- lvm(data, lambda = lambda, estimator = "FIML") %>%
runmodel %>%
prune %>%
modelsearch
# RNM model:
mod_rnm <- rnm(data, lambda = lambda, estimator = "FIML") %>%
runmodel %>%
prune %>%
modelsearch
# RNM with only a extraversion factor:
lambda <- matrix(rep(1:0,each=5),ncol=1)
latents <- "extraversion"
mod_rnm_extraversion <- rnm(data, lambda = lambda, estimator = "FIML") %>%
runmodel %>%
prune %>%
modelsearch
# RNM with only a neuroticism factor:
lambda <- matrix(rep(0:1,each=5),ncol=1)
latents <- "neuroticism"
mod_rnm_neuroticism <- rnm(data, lambda = lambda, estimator = "FIML") %>%
runmodel %>%
prune %>%
modelsearch
# Compare all models:
compare(
GGM = mod_ggm,
RNM = mod_rnm,
RNM_extraversion = mod_rnm_extraversion,
RNM_neuroticism = mod_rnm_neuroticism
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment