Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.