Learn R Programming

RSDC (version 1.1-2)

rsdc_likelihood: Negative Log-Likelihood for Regime-Switching Correlation Models

Description

Computes the negative log-likelihood for a multivariate correlation-only regime-switching model, with either a fixed (time-invariant) transition matrix or time-varying transition probabilities (TVTP) driven by exogenous covariates. Likelihood evaluation uses the Hamilton (1989) filter.

Usage

rsdc_likelihood(params, y, exog = NULL, K, N)

Value

Numeric scalar: the negative log-likelihood to be minimized by an optimizer.

Arguments

params

Numeric vector of model parameters packed as:

  • No exogenous covariates (exog = NULL): first \(N(N-1)\) transition parameters (for the fixed transition matrix), followed by \(N \times K(K-1)/2\) correlation parameters, stacked row-wise by regime in lower.tri order.

  • With exogenous covariates (exog provided): first \(N \times p\) TVTP coefficients (beta, row \(i\) corresponds to regime \(i\)), followed by \(N \times K(K-1)/2\) correlation parameters, stacked row-wise by regime in lower.tri order.

y

Numeric matrix \(T \times K\) of observations (e.g., standardized residuals). Columns are treated as mean-zero, unit-variance; only correlation is modeled.

exog

Optional numeric matrix \(T \times p\) of exogenous covariates. If supplied, a TVTP specification is used.

K

Integer. Number of observed series (columns of y).

N

Integer. Number of regimes.

Details

  • Transition dynamics:

    • Fixed P (no exog): params begins with transition parameters. For \(N=2\), the implementation maps them to \(P=\begin{pmatrix} p_{11} & 1-p_{11}\\ 1-p_{22} & p_{22}\end{pmatrix}\).

    • TVTP: with exog, diagonal persistence is \(p_{ii,t} = \mathrm{logit}^{-1}(X_t^\top \beta_i)\); off-diagonals are equal and sum to \(1-p_{ii,t}\).

  • Correlation build: per regime, the lower-triangular vector is filled into a symmetric correlation matrix. Non-positive-definite proposals or \(|\rho|\ge 1\) are penalized via a large objective value.

  • Evaluation: delegates to rsdc_hamilton; if the filter returns log_likelihood = -Inf, a large penalty is returned.

See Also

rsdc_hamilton (filter), optim, and DEoptim

Examples

Run this code
# Small toy example (N = 2, K = 3), fixed P (no exog)
set.seed(1)
T <- 40; K <- 3; N <- 2
y <- scale(matrix(rnorm(T * K), T, K), center = TRUE, scale = TRUE)

# Pack parameters: trans (p11, p22), then rho by regime (lower-tri order)
p11 <- 0.9; p22 <- 0.8
rho1 <- c(0.10, 0.05, 0.00)  # (2,1), (3,1), (3,2)
rho2 <- c(0.60, 0.40, 0.30)
params <- c(p11, p22, rho1, rho2)

nll <- rsdc_likelihood(params, y = y, exog = NULL, K = K, N = N)
nll

# TVTP example: add X and beta (pack beta row-wise, then rho)
X <- cbind(1, scale(seq_len(T)))
beta <- rbind(c(1.2, 0.0),
              c(0.8, -0.1))
params_tvtp <- c(as.vector(t(beta)), rho1, rho2)
nll_tvtp <- rsdc_likelihood(params_tvtp, y = y, exog = X, K = K, N = N)
nll_tvtp

Run the code above in your browser using DataLab