set.seed(1)
T <- 50; K <- 3; N <- 2
y <- scale(matrix(rnorm(T * K), T, K), center = TRUE, scale = TRUE)
# Example rho: two regimes with different average correlations
rho <- rbind(c(0.10, 0.05, 0.00),
c(0.60, 0.40, 0.30)) # lower-tri order for K=3
# Fixed-P filtering
Pfix <- matrix(c(0.9, 0.1,
0.2, 0.8), nrow = 2, byrow = TRUE)
out_fix <- rsdc_hamilton(y = y, X = NULL, beta = NULL,
rho_matrix = rho, K = K, N = N, P = Pfix)
str(out_fix$filtered_probs)
# TVTP filtering (include an intercept yourself)
X <- cbind(1, scale(seq_len(T)))
beta <- rbind(c(1.2, 0.0),
c(0.8, -0.1))
out_tvtp <- rsdc_hamilton(y = y, X = X, beta = beta,
rho_matrix = rho, K = K, N = N)
out_tvtp$log_likelihood
Run the code above in your browser using DataLab