Learn R Programming

valueprhr (version 0.1.0)

run_sparse_cca: Run Sparse CCA with PCA Preprocessing

Description

Performs canonical correlation analysis on PCA-reduced price matrices, with optional sparsity penalties.

Usage

run_sparse_cca(
  X_matrix,
  Y_matrix,
  n_components = 3L,
  variance_threshold = 0.9,
  min_pcs = 8L,
  max_pcs = 12L
)

Value

A list containing:

method

Method used for CCA

correlations

Canonical correlations

U_loadings

X loadings in PC space

V_loadings

Y loadings in PC space

W_X_original

X loadings projected to original variables

W_Y_original

Y loadings projected to original variables

n_pcs_x

Number of PCs used for X

n_pcs_y

Number of PCs used for Y

Arguments

X_matrix

Numeric matrix of direct prices.

Y_matrix

Numeric matrix of production prices.

n_components

Number of canonical components to extract. Default 3.

variance_threshold

Cumulative variance threshold for PCA. Default 0.90.

min_pcs

Minimum number of PCs to retain. Default 8.

max_pcs

Maximum number of PCs to retain. Default 12.

Details

The function first reduces dimensionality using PCA, then applies CCA. Falls back to base R cancor if specialized packages unavailable.

Examples

Run this code
set.seed(123)
n <- 50
p <- 20
X <- matrix(rnorm(n * p), n, p)
Y <- X %*% matrix(rnorm(p * 5), p, 5) + matrix(rnorm(n * 5, 0, 0.5), n, 5)
colnames(X) <- paste0("X", 1:p)
colnames(Y) <- paste0("Y", 1:5)

result <- run_sparse_cca(X, Y, n_components = 2)
print(result$correlations)

Run the code above in your browser using DataLab