| Title: | Multiple Canonical Correlation Analysis (Kernel and Functional) |
|---|---|
| Description: | Implementation of kernel and functional multiple canonical correlation analysis. |
| Authors: | Tomasz Gorecki [aut, cre] (ORCID: <https://orcid.org/0000-0002-9969-5257>) |
| Maintainer: | Tomasz Gorecki <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-24 05:46:34 UTC |
| Source: | https://github.com/halmaris/multicca |
Computes the Hopkins statistic for representations based on increasing numbers of canonical components obtained from an MCCA model.
hopkins_vs_components( fit, blocks = NULL, max_comp = NULL, m = NULL, nrep = 50, seed = NULL )hopkins_vs_components( fit, blocks = NULL, max_comp = NULL, m = NULL, nrep = 50, seed = NULL )
fit |
Fitted object of class |
blocks |
Vector of block indices included in the representation.
If |
max_comp |
Maximum number of components to evaluate. |
m |
Number of sampled points used in the Hopkins statistic. |
nrep |
Number of repetitions used to estimate the statistic. |
seed |
Optional random seed. |
A data frame containing:
components – number of components,
hopkins – mean Hopkins statistic,
sd – standard deviation across repetitions.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 3) hopkins_vs_components(fit, max_comp = 2)set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 3) hopkins_vs_components(fit, max_comp = 2)
Fits either kernel MCCA for repeated measures data or functional MCCA.
mcca_fit( method = c("kernel", "functional"), X, ncomp = 2, eps = 0.001, gamma = NULL, nbasis = 5, basis_type = "fourier", argvals = NULL )mcca_fit( method = c("kernel", "functional"), X, ncomp = 2, eps = 0.001, gamma = NULL, nbasis = 5, basis_type = "fourier", argvals = NULL )
method |
Character string specifying the method to use.
Either |
X |
List of feature blocks. Each element |
ncomp |
Number of leading canonical components. |
eps |
Regularization parameter. |
gamma |
Gaussian kernel bandwidth for the kernel method. |
nbasis |
Number of basis functions for the functional method. |
basis_type |
Basis type for the functional method.
Either |
argvals |
Optional time grid for the functional method. |
An object of class mcca_fit. The following S3 methods are
available for this class:
print() prints a short summary of the fitted model,
summary() provides a more detailed summary of the model.
set.seed(1) n <- 20 T_len <- 10 X <- list(lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2))) fit <- mcca_fit(method = 'kernel', X = X, ncomp = 2, eps = 1e-2) print(fit) summary(fit)set.seed(1) n <- 20 T_len <- 10 X <- list(lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2))) fit <- mcca_fit(method = 'kernel', X = X, ncomp = 2, eps = 1e-2) print(fit) summary(fit)
Performs a grid search over regularization and model parameters for kernel or functional multiple canonical correlation analysis.
mcca_grid_search( method = c("kernel", "functional"), X, eps_grid, gamma_grid = NULL, nbasis_grid = NULL, ncomp_eval = 2, criterion = c("first", "sumk"), basis_type = "fourier", argvals = NULL )mcca_grid_search( method = c("kernel", "functional"), X, eps_grid, gamma_grid = NULL, nbasis_grid = NULL, ncomp_eval = 2, criterion = c("first", "sumk"), basis_type = "fourier", argvals = NULL )
method |
Character string specifying the method. Either 'kernel' or 'functional'. |
X |
List of feature blocks. |
eps_grid |
Vector of candidate regularization parameters. |
gamma_grid |
Vector of candidate kernel bandwidths (kernel method). |
nbasis_grid |
Vector of candidate numbers of basis functions (functional method). |
ncomp_eval |
Number of canonical components used in evaluation. |
criterion |
Criterion used to rank models: 'first' or 'sumk'. |
basis_type |
Basis type used in functional method: 'fourier' or 'bspline'. |
argvals |
Optional time grid for functional data. |
A list containing:
results – data frame with grid search scores,
best_fit – fitted MCCA model for the best parameter set,
best_row – row of the grid corresponding to the best parameters.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) res <- mcca_grid_search( method = "kernel", X = X, eps_grid = c(1e-3, 1e-2), gamma_grid = c(0.1, 1), ncomp_eval = 2 ) res$best_rowset.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) res <- mcca_grid_search( method = "kernel", X = X, eps_grid = c(1e-3, 1e-2), gamma_grid = c(0.1, 1), ncomp_eval = 2 ) res$best_row
This function performs a complete analysis workflow for multiple canonical correlation analysis (MCCA). It fits either the kernel or functional MCCA model, computes the Hopkins statistic for increasing numbers of components, and produces diagnostic plots.
mcca_pipeline( method = c("kernel", "functional"), X, groups = NULL, labels = NULL, ncomp = 5, eps = 0.001, gamma = NULL, nbasis = 5, basis_type = "fourier", argvals = NULL, hopkins_blocks = NULL, hopkins_max_comp = NULL, hopkins_m = NULL, hopkins_nrep = 100, block_x = 1, block_y = 2, pair_comp = 1 )mcca_pipeline( method = c("kernel", "functional"), X, groups = NULL, labels = NULL, ncomp = 5, eps = 0.001, gamma = NULL, nbasis = 5, basis_type = "fourier", argvals = NULL, hopkins_blocks = NULL, hopkins_max_comp = NULL, hopkins_m = NULL, hopkins_nrep = 100, block_x = 1, block_y = 2, pair_comp = 1 )
method |
Character string specifying the method to use. Either 'kernel' or 'functional'. |
X |
List of feature blocks. Each element |
groups |
Optional grouping variable used for coloring points in plots. |
labels |
Optional vector of labels used to annotate points in plots. |
ncomp |
Number of canonical components to estimate. |
eps |
Regularization parameter used in the generalized eigenproblem. |
gamma |
Gaussian kernel bandwidth used in the kernel MCCA method. |
nbasis |
Number of basis functions used in the functional MCCA method. |
basis_type |
Basis type used in the functional method. Either 'fourier' or 'bspline'. |
argvals |
Optional time grid used for functional data smoothing. |
hopkins_blocks |
Vector of block indices used when computing the
Hopkins statistic. If |
hopkins_max_comp |
Maximum number of components used when computing
the Hopkins statistic. If |
hopkins_m |
Number of sampled points used in the Hopkins statistic. |
hopkins_nrep |
Number of repetitions used when estimating the Hopkins statistic. |
block_x |
Index of the first block used in the pairwise component plot. |
block_y |
Index of the second block used in the pairwise component plot. |
pair_comp |
Index of the canonical component used in the pairwise plot. |
A list containing:
fit – fitted MCCA model object.
hopkins – data frame with Hopkins statistic values.
pair_plot – ggplot object with pairwise component scatter plot.
hopkins_plot – ggplot object showing Hopkins statistic versus
number of components.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) groups <- sample(1:2, n, replace = TRUE) res <- mcca_pipeline( method = 'kernel', X = X, groups = groups, ncomp = 3, eps = 1e-2 ) res$fit head(res$hopkins)set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) groups <- sample(1:2, n, replace = TRUE) res <- mcca_pipeline( method = 'kernel', X = X, groups = groups, ncomp = 3, eps = 1e-2 ) res$fit head(res$hopkins)
Plots the Hopkins statistic as a function of the number of canonical components.
plot_hopkins_curve(df, title = NULL)plot_hopkins_curve(df, title = NULL)
df |
Data frame returned by |
title |
Optional plot title. |
A ggplot2 object.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 3) H <- hopkins_vs_components(fit, max_comp = 2) plot_hopkins_curve(H)set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 3) H <- hopkins_vs_components(fit, max_comp = 2) plot_hopkins_curve(H)
Creates a scatter plot comparing canonical components from two blocks.
plot_mcca_pair( fit_x, fit_y = NULL, block_x = 1, block_y = 2, comp = 1, groups = NULL, labels = NULL, title = NULL )plot_mcca_pair( fit_x, fit_y = NULL, block_x = 1, block_y = 2, comp = 1, groups = NULL, labels = NULL, title = NULL )
fit_x |
Fitted object of class |
fit_y |
Optional second MCCA object. If |
block_x |
Block index for x-axis. |
block_y |
Block index for y-axis. |
comp |
Component index. |
groups |
Optional grouping variable. |
labels |
Optional point labels. |
title |
Optional plot title. |
A ggplot2 object.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 2) plot_mcca_pair(fit)set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 2) plot_mcca_pair(fit)
Creates a scatter plot of two canonical components obtained from an MCCA model for a selected block.
plot_mcca_scatter( fit, block = 1, comp_x = 1, comp_y = 2, groups = NULL, labels = NULL, add_ellipse = TRUE, point_size = 2.5, title = NULL )plot_mcca_scatter( fit, block = 1, comp_x = 1, comp_y = 2, groups = NULL, labels = NULL, add_ellipse = TRUE, point_size = 2.5, title = NULL )
fit |
Object of class |
block |
Block index. |
comp_x |
Component used on the x-axis. |
comp_y |
Component used on the y-axis. |
groups |
Optional grouping variable. |
labels |
Optional point labels. |
add_ellipse |
Logical; whether to draw group ellipses. |
point_size |
Size of plotted points. |
title |
Optional plot title. |
A ggplot2 object.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 2) plot_mcca_scatter(fit)set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = "kernel", X = X, ncomp = 2) plot_mcca_scatter(fit)
Projects new observations onto canonical components obtained from a fitted MCCA model (kernel or functional).
## S3 method for class 'mcca_fit' predict(object, newdata, ...)## S3 method for class 'mcca_fit' predict(object, newdata, ...)
object |
Object of class |
newdata |
List of feature blocks with the same structure as used during model fitting. |
... |
Additional arguments (unused). |
List of matrices containing projected component scores for each block.
set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = 'kernel', X = X, ncomp = 2) predict(fit, X)set.seed(1) n <- 20 T_len <- 10 X <- list( lapply(seq_len(n), function(i) matrix(rnorm(T_len * 3), T_len, 3)), lapply(seq_len(n), function(i) matrix(rnorm(T_len * 2), T_len, 2)) ) fit <- mcca_fit(method = 'kernel', X = X, ncomp = 2) predict(fit, X)
Provides a summary of a fitted MCCA model, including the number of blocks, sample size, regularization parameter, and generalized canonical correlations.
## S3 method for class 'mcca_fit' summary(object, ...)## S3 method for class 'mcca_fit' summary(object, ...)
object |
An object of class |
... |
Additional arguments (currently unused). |
An object of class summary.mcca_fit.