rtmb_fa: RTMB-based Factor Analysis Wrapper

View source: R/wrapper_fa.R

rtmb_faR Documentation

RTMB-based Factor Analysis Wrapper

Description

Performs exploratory factor analysis (EFA) using RTMB. It supports standard rotation methods (e.g., varimax, promax) as well as regularized factor analysis using a Spike-and-Slab Prior (SSP) for estimating sparse loading matrices.

Usage

rtmb_fa(
  data,
  nfactors = 1,
  rotate = NULL,
  score = FALSE,
  prior = prior_flat(),
  y_range = NULL,
  init = NULL,
  fixed = NULL,
  missing = c("listwise", "fiml"),
  WAIC = FALSE
)

Arguments

data

Observation data frame or matrix (N x J).

nfactors

Number of factors (K).

rotate

String specifying the rotation method (e.g., "varimax", "promax", "ssp"). If NULL, no rotation is applied. Specifying "ssp" performs regularized factor analysis.

score

Logical; if TRUE, factor scores are calculated in the generate block (default is FALSE).

prior

Prior configuration: 'prior_flat()', 'prior_normal()', or 'prior_weak()'. 'prior_ssp()' is accepted when 'rotate = "ssp"'. Hyperparameters can be specified within these functions (e.g., 'prior_normal(mean_sd = 10, sd_rate = 1 / 5, loadings_sd = 10)'). Available FA aliases are 'mean_sd', 'sd_rate', and 'loadings_sd'; they override the corresponding common arguments 'mu_sd', 'sigma_rate', and 'b_sd'. 'sd_rate' is an exponential rate, so '1 / 5' gives a prior mean of 5. 'ssp_ratio' is available when 'rotate = "ssp"'.

y_range

A numeric vector of length 2 specifying the theoretical min and max values of the items. Used to construct weakly informative priors when 'prior = prior_weak()'.

init

List of initial values.

fixed

A named list of parameter values to fix (optional).

missing

Missing value handling strategy: "listwise" (default) or "fiml" (Full Information Maximum Likelihood).

WAIC

Logical; if TRUE, add pointwise 'log_lik' to the generate block for WAIC.

Examples


  # Prepare a subset of the BigFive dataset for factor analysis
  data(BigFive, package = "BayesRTMB")
  fa_data <- BigFive[, 1:10]

  # --- 1. Standard Exploratory Factor Analysis (1 Factor) ---
  fit_fa1 <- rtmb_fa(data = fa_data, nfactors = 1)

  # Maximum A Posteriori (MAP) estimation
  map_fa1 <- fit_fa1$optimize()
  map_fa1$summary()

BayesRTMB documentation built on Nov. 24, 2026, 9:06 a.m.