The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

vbpm

Variational Bayes Psychometric Models

vbpm is a home for variational Bayes estimation of psychometric measurement models. Its models are partially confirmatory: they span the confirmatory-to-exploratory continuum, with parameters on specified paths anchored by a design matrix and parameters on unspecified paths selected from the data by continuous spike-and-slab priors.

The package provides variational Bayes factor analysis (vbfa), where a design matrix Q governs the item loadings, and regularized MIMIC (vbmimic), which adds covariates predicting the factors and regularizes both the measurement part (Q_A) and the structural part (Q_B).

Features

Installation

1. A C++ toolchain (one-time setup)

vbpm ships C++ code — the QUIC solver behind the local-dependence branch — so installing it compiles that code and a C++ toolchain must be present. Many R users already have one (any package installed from source needs it); check before installing anything:

# install.packages("pkgbuild")
pkgbuild::has_build_tools(debug = TRUE)   # TRUE = you are ready, skip to step 2

If that returns FALSE:

system what to install where
Windows Rtools, matched to your R version — Rtools45 for R 4.5.x, Rtools44 for R 4.4.x (check with getRversion()). Run the installer with its defaults; ≈500 MB installed. https://cran.r-project.org/bin/windows/Rtools/
macOS Xcode command line tools (not the full Xcode app): run xcode-select --install in Terminal and accept the prompt; ≈1 GB. https://mac.r-project.org/tools/
Linux Your distribution’s R development packages: sudo apt install r-base-dev (Debian/Ubuntu) or sudo dnf install R-devel gcc-c++ (Fedora/RHEL); a few tens of MB.

Restart R afterwards, then re-run the has_build_tools() check.

2. The package

# install.packages("remotes")
remotes::install_github("Jinsong-Chen/vbpm", build_vignettes = TRUE)

Or clone and install from source:

git clone https://github.com/Jinsong-Chen/vbpm.git
R CMD INSTALL vbpm

Then:

library(vbpm)
vignette("vbfa")         # start here
vignette("pefa")         # the factor-count sweep and its three tables
vignette("bifactor")     # bifactor structures, AO/AZ backbones, and sweeps
vignette("vbmimic")      # covariates predicting the factors
citation("vbpm")

Building the vignettes needs knitr, rmarkdown, and pandoc (bundled with RStudio; from a plain shell, point RSTUDIO_PANDOC at it).

Quick start

library(vbpm)

sim <- sim_fa(N = 500, K = 3, ipf = 6, lam = .7, lac = .3)
Y   <- sim$dat

## partially confirmatory Q: 1 = anchor, 0 = fixed zero, -1 = estimate
Q <- matrix(-1, ncol(Y), 3)
Q[1:2, ] <- 0; Q[1:2, 1] <- 1        # two anchors on factor 1 only

fit <- vbfa(Y, Q)                    # dynamic path on by default; quiet
fit                                  # compact summary (S3 print method)
idx <- fit_stats(fit)                # nominal hard-selected count by default

Fits are ordinary named lists with a shared vbpm_fit class attached — fields such as fit$Lam, fit$pi, and fit$Phi remain public API. Focused vignettes cover vbfa, one pefa() sweep walked table by table under overextraction, bifactor/higher-order/testlet structures with AO and AZ backbones, and vbmimic.

MIMIC, with covariates predicting the factors:

B <- matrix(0, 3, 9)                 # sparse structural design: 3 covariates
for (k in 1:3) B[k, (k*3-2):(k*3)] <- .3   # per factor

sim <- sim_lvm(N = 500, K = 3, J = 18, P = 9, b = B, phx = 0)
Y   <- sim$dat[, 1:18]               # items first ...
X   <- sim$dat[, 19:27]              # ... covariates last

## anchor two items per factor; leave the structural part exploratory.
## (With BOTH parts fully exploratory the solution can be rotationally
## ambiguous -- anchor at least one part.)
Q_A <- matrix(-1L, 18, 3)
for (k in 1:3) { a <- which(rep(1:3, each = 6) == k)[1:2]
                 Q_A[a, ] <- 0L; Q_A[a, k] <- 1L }
Q_B <- matrix(-1L, 3, 9)

fit <- vbmimic(Y, X, Q_A, Q_B)
round(fit$B, 2)                      # which covariates predict which factors

References

Known limitations

As of 0.9.1:

vbfa() reproduces its published reference output. A stored-reference regression test checks that result during every R CMD check, at a strict relative tolerance of 1e-8 that remains sensitive to material regression. It is not asserted bitwise: the estimator runs through compiled BLAS/LAPACK, whose SIMD and FMA choices differ between platforms, so the last one or two ulps are a property of the build rather than of the estimator.

See NEWS.md for the per-version changelog.

License

GPL-3.

Authors

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.