Contents

Overview

lavaan is the standard R package for structural equation modeling, with its familiar model syntax (=~, ~, ~~). psychonetrics offers complementary strengths: network (GGM) parameterizations, automated network search (prune() / stepup()), Ising and time-series models, and meta-analytic SEM. Version 0.16 adds two converters — validated against lavaan — so you can move a model between the two frameworks and use the best tool for each step.

The bridge is the lvm family with latent = "cov" and residual = "cov" — the standard ML CFA/SEM parameterization that both packages share.

fromlavaan(): lavaan → psychonetrics

Specify and fit a model in lavaan as usual, then hand the fitted object to fromlavaan(). The resulting psychonetrics model reproduces the lavaan estimates, standard errors, chi-square, degrees of freedom and log-likelihood — after which the full psychonetrics toolbox (modification indices, pruning, network reparameterization) becomes available.

library("psychonetrics")
library("lavaan")
library("dplyr")
data(HolzingerSwineford1939)

# A standard three-factor CFA in lavaan syntax:
HS.model <- 'visual  =~ x1 + x2 + x3
             textual =~ x4 + x5 + x6
             speed   =~ x7 + x8 + x9'
fit_lav <- cfa(HS.model, data = HolzingerSwineford1939, meanstructure = TRUE)

# Convert to psychonetrics and (re-)estimate:
mod_pn <- fit_lav %>% fromlavaan %>% runmodel

mod_pn %>% fit
Output
logl lavaan : -3737.745 logl psychonetrics : -3737.745 # exact match chisq lavaan : 85.306 df 24 chisq psychonetrics : 85.306 df 24

Multi-group models and cross-group equality constraints carry over too. For example, a two-group CFA with equal loadings (group.equal = "loadings") reproduces exactly:

fit_mg <- cfa(HS.model, data = HolzingerSwineford1939,
              group = "school", group.equal = "loadings",
              meanstructure = TRUE)

mod_mg <- fit_mg %>% fromlavaan %>% runmodel
mod_mg %>% fit
Output
lavaan psychonetrics logl -3686.294 -3686.294 chisq 124.044 124.044 df 54 54 npar 54 54
Meanstructure tip. Fit the lavaan model with meanstructure = TRUE for the log-likelihood to match exactly. If the lavaan model has no mean structure, fromlavaan() still reproduces estimates, standard errors, chi-square and df, but adds a saturated mean structure and warns that the log-likelihood differs by a constant.

tolavaan(): psychonetrics → lavaan

The reverse converter takes a fitted psychonetrics lvm (with latent = "cov", residual = "cov") and returns either a fitted lavaan object (the default) or a lavaan parameter table (type = "partable"). This is handy for reusing lavaan's reporting, plotting (e.g. semPlot), or downstream tools:

# Round-trip the model from the previous example back to lavaan:
back <- tolavaan(mod_pn)

class(back)               # "lavaan"
logLik(back)              # -3737.745  (matches the psychonetrics fit)

# Or extract just the parameter table:
pt <- tolavaan(mod_pn, type = "partable")
Output
class(back) : "lavaan" logLik(back) : -3737.745

Estimates, standard errors, chi-square and log-likelihood round-trip exactly, so a model can travel lavaan → psychonetrics → lavaan without drift.

Supported features

The converters target standard maximum-likelihood CFA/SEM. The following are supported:

Features outside this scope (for example ordered-categorical estimators, certain nonlinear constraints, or definitions that do not map onto the lvm cov/cov parameterization) raise an informative error rather than silently producing a wrong model. For network parameterizations, fit in psychonetrics directly — see the LVM page.

Summary