| Title: | Generalized Contrastive Principal Component Analysis |
|---|---|
| Description: | Implements dense and sparse generalized contrastive principal component analysis (gcPCA) with S3 fit objects and methods for prediction, summaries, and plotting. The gcPCA is a hyperparameter-free method for comparing high-dimensional datasets collected under different experimental conditions to reveal low-dimensional patterns enriched in one condition compared to the other. Method details are described in de Oliveira, Garg, Hjerling-Leffler, Batista-Brito, and Sjulson (2025) <doi:10.1371/journal.pcbi.1012747>. |
| Authors: | Eliezyer de Oliveira [aut, cre] |
| Maintainer: | Eliezyer de Oliveira <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-06-01 11:14:17 UTC |
| Source: | https://github.com/cran/gcpca |
Extract gcPCA loadings
## S3 method for class 'gcPCA' coef(object, ...) ## S3 method for class 'sparse_gcPCA' coef(object, ...)## S3 method for class 'gcPCA' coef(object, ...) ## S3 method for class 'sparse_gcPCA' coef(object, ...)
object |
A fitted |
... |
Unused. |
For dense models, a loadings matrix. For sparse models, a named list of loading matrices (one per lasso penalty).
Return fitted training scores
## S3 method for class 'gcPCA' fitted(object, ...)## S3 method for class 'gcPCA' fitted(object, ...)
object |
A fitted |
... |
Passed to |
A list with Ra_scores and Rb_scores.
gcPCA() fits dense generalized contrastive principal components from two
data matrices (Ra and Rb) measured on the same feature set.
gcPCA( Ra, Rb, method = "v4", Ncalc = NULL, Nshuffle = 0, normalize_flag = TRUE, alpha = 1, alpha_null = 0.975, cond_number = 10^13 )gcPCA( Ra, Rb, method = "v4", Ncalc = NULL, Nshuffle = 0, normalize_flag = TRUE, alpha = 1, alpha_null = 0.975, cond_number = 10^13 )
Ra |
Matrix for condition A ( |
Rb |
Matrix for condition B ( |
method |
Character scalar selecting optimization variant. |
Ncalc |
Optional number of gcPCs for orthogonal variants ( |
Nshuffle |
Number of shuffles used to estimate a null distribution. |
normalize_flag |
Logical; if |
alpha |
Contrastive coefficient used by method |
alpha_null |
Quantile for null thresholding (reserved in current code). |
cond_number |
Maximum allowed denominator condition number. |
An object of class "gcPCA" with loadings, scores, objective values,
and fit metadata.
set.seed(1) Ra <- matrix(rnorm(40 * 5), ncol = 5) Rb <- matrix(rnorm(35 * 5), ncol = 5) fit <- gcPCA(Ra, Rb, method = "v4", Ncalc = 3) pred <- predict(fit, Ra = Ra) str(pred$Ra_scores)set.seed(1) Ra <- matrix(rnorm(40 * 5), ncol = 5) Rb <- matrix(rnorm(35 * 5), ncol = 5) fit <- gcPCA(Ra, Rb, method = "v4", Ncalc = 3) pred <- predict(fit, Ra = Ra) str(pred$Ra_scores)
Convenience wrapper around coef() for "gcPCA" and "sparse_gcPCA"
objects.
loadings(object, ...)loadings(object, ...)
object |
A fitted model object. |
... |
Extra arguments passed to |
A loading matrix or a named list of loading matrices.
Plot gcPCA scores
## S3 method for class 'gcPCA' plot(x, which = c(1, 2), ...)## S3 method for class 'gcPCA' plot(x, which = c(1, 2), ...)
x |
A fitted |
which |
Integer vector of length 2 indicating components to plot. |
... |
Extra graphical parameters passed to |
x, invisibly.
Project data with a fitted gcPCA model
## S3 method for class 'gcPCA' predict(object, Ra = NULL, Rb = NULL, ...) ## S3 method for class 'sparse_gcPCA' predict(object, Ra = NULL, Rb = NULL, ...)## S3 method for class 'gcPCA' predict(object, Ra = NULL, Rb = NULL, ...) ## S3 method for class 'sparse_gcPCA' predict(object, Ra = NULL, Rb = NULL, ...)
object |
A fitted |
Ra |
Optional matrix for condition A. |
Rb |
Optional matrix for condition B. |
... |
Unused. |
For dense models, a list of score matrices. For sparse models, a list of score-matrix lists, one per penalty value.
Print a gcPCA model
## S3 method for class 'gcPCA' print(x, ...)## S3 method for class 'gcPCA' print(x, ...)
x |
A fitted |
... |
Unused. |
x, invisibly.
Print a gcPCA summary
## S3 method for class 'summary.gcPCA' print(x, ...)## S3 method for class 'summary.gcPCA' print(x, ...)
x |
A |
... |
Unused. |
x, invisibly.
Convenience wrapper around predict() for "gcPCA" and "sparse_gcPCA"
objects.
scores(object, newdata = NULL, ...)scores(object, newdata = NULL, ...)
object |
A fitted model object. |
newdata |
Optional matrix (treated as |
... |
Extra arguments passed to |
A list of projected scores.
sparse_gcPCA() fits sparse gcPCA loadings over a path of lasso penalties.
sparse_gcPCA( Ra, Rb, method = "v4", Ncalc = NULL, normalize_flag = TRUE, Nsparse = NULL, Nshuffle = 0, lasso_penalty = exp(seq(log(0.01), log(1), length.out = 10)), ridge_penalty = 0, alpha = 1, alpha_null = 0.975, tol = 1e-05, max_steps = 1000, cond_number = 1e+13 )sparse_gcPCA( Ra, Rb, method = "v4", Ncalc = NULL, normalize_flag = TRUE, Nsparse = NULL, Nshuffle = 0, lasso_penalty = exp(seq(log(0.01), log(1), length.out = 10)), ridge_penalty = 0, alpha = 1, alpha_null = 0.975, tol = 1e-05, max_steps = 1000, cond_number = 1e+13 )
Ra |
Matrix for condition A ( |
Rb |
Matrix for condition B ( |
method |
Character scalar selecting optimization variant. |
Ncalc |
Optional number of gcPCs for orthogonal variants ( |
normalize_flag |
Logical; if |
Nsparse |
Number of sparse gcPCs to estimate. |
Nshuffle |
Number of shuffles passed to the dense gcPCA stage. |
lasso_penalty |
Numeric vector of lasso penalties. |
ridge_penalty |
Numeric ridge penalty. |
alpha |
Contrastive coefficient used by method |
alpha_null |
Quantile for null thresholding (reserved in current code). |
tol |
Convergence tolerance for sparse optimization. |
max_steps |
Maximum number of sparse optimization iterations. |
cond_number |
Maximum allowed denominator condition number. |
An object of class c("sparse_gcPCA", "gcPCA") containing sparse
loadings and training projections across penalties.
set.seed(1) Ra <- matrix(rnorm(50 * 6), ncol = 6) Rb <- matrix(rnorm(45 * 6), ncol = 6) fit <- sparse_gcPCA(Ra, Rb, method = "v4", Nsparse = 2, lasso_penalty = c(0.05, 0.1)) pred <- predict(fit, Ra = Ra) str(pred$Ra_scores)set.seed(1) Ra <- matrix(rnorm(50 * 6), ncol = 6) Rb <- matrix(rnorm(45 * 6), ncol = 6) fit <- sparse_gcPCA(Ra, Rb, method = "v4", Nsparse = 2, lasso_penalty = c(0.05, 0.1)) pred <- predict(fit, Ra = Ra) str(pred$Ra_scores)
Summarize a gcPCA model
## S3 method for class 'gcPCA' summary(object, ...)## S3 method for class 'gcPCA' summary(object, ...)
object |
A fitted |
... |
Unused. |
A "summary.gcPCA" list with eigenvalues, standard deviations,
explained variance summaries, and tuning settings.