Learn R Programming

convergenceDFM (version 0.1.4)

estimate_factor_OU: Estimate Factor Ornstein-Uhlenbeck model (Stan if available)

Description

Estimates a multivariate OU with cross-equation coupling \(Y_{t}\) depending on lagged \(X_{t-1}\) via a \(\beta\) matrix. Uses cmdstanr when available, otherwise rstan, with a discrete AR(1) fallback.

Usage

estimate_factor_OU(
  factors_data,
  data_prep = NULL,
  chains = 4,
  iter = 2000,
  seed = 1234,
  adapt1 = 0.98,
  adapt2 = 0.999,
  mtd1 = 12,
  mtd2 = 15,
  verbose = TRUE
)

Value

A list with posterior medians (\(\phi\), \(\mu\), \(\beta\)), half-lives, coupling strength, pseudo-R2, and the fitted Stan object.

Arguments

factors_data

List with scores_X, scores_Y.

data_prep

Optional preprocessed data (reserved).

chains, iter, seed

Stan sampling controls.

adapt1, adapt2, mtd1, mtd2

Advanced Stan controls.

verbose

Logical; print progress/details.

Examples

Run this code
# \donttest{
  # Create toy factor data
  set.seed(123)
  n <- 50
  X_scores <- matrix(rnorm(n * 2), n, 2)
  Y_scores <- matrix(rnorm(n * 2), n, 2)
  factors_data <- list(scores_X = X_scores, scores_Y = Y_scores)
  
  # Estimate OU model (reduce iterations for speed)
  ou_result <- estimate_factor_OU(factors_data, chains = 2, iter = 500, 
                                   verbose = FALSE)
  
  # Check half-lives
  print(ou_result$half_lives_Y)
# }

Run the code above in your browser using DataLab