| Title: | Lambda-Controlled Cross-Domain Feature Adjustment |
|---|---|
| Description: | Provides cross-domain feature adjustment methods for biological and other tabular data. Domain labels define group centroids, and singular value decomposition of their offsets from a common anchor estimates a domain-shift subspace. An orthogonal projection removes a user-controlled fraction of each sample's component in that subspace. A correction strength of zero preserves the input; a strength of one removes the entire learned subspace component. Intermediate values provide partial correction. The fitted transformation can be applied to new samples without refitting. |
| Authors: | Weikaixin Kong [aut, cre] |
| Maintainer: | Weikaixin Kong <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-09-29 16:18:17 UTC |
| Source: | https://github.com/cran/CrossDomainAdjust |
Learns the low-dimensional subspace spanned by domain centroid differences and stores the orthogonal projection matrix for that subspace. For K domains, the learned domain-shift subspace has rank at most K - 1 when the anchor is in the affine hull of the centroids, including both built-in anchors. An arbitrary custom anchor can give rank K, subject to the number of features.
fit_domain_projector(x, domain, anchor = "domain_mean")fit_domain_projector(x, domain, anchor = "domain_mean")
x |
Numeric matrix or data frame with samples in rows and features in columns. |
domain |
Character or factor vector giving the domain label for each row of |
anchor |
Character string or named numeric vector. Use |
An object of class "domain_projector".
set.seed(1) x <- rbind( matrix(rnorm(20), nrow = 5), matrix(rnorm(20) + 1, nrow = 5), matrix(rnorm(20) - 1, nrow = 5) ) colnames(x) <- paste0("feature_", seq_len(ncol(x))) domain <- rep(c("A", "B", "C"), each = 5) projector <- fit_domain_projector(x, domain, anchor = "domain_mean") projectorset.seed(1) x <- rbind( matrix(rnorm(20), nrow = 5), matrix(rnorm(20) + 1, nrow = 5), matrix(rnorm(20) - 1, nrow = 5) ) colnames(x) <- paste0("feature_", seq_len(ncol(x))) domain <- rep(c("A", "B", "C"), each = 5) projector <- fit_domain_projector(x, domain, anchor = "domain_mean") projector
Corrects feature values by removing a lambda-controlled fraction of the learned
domain-shift projection component:
x_corrected = x - lambda * ((x - anchor) %*% P).
lambda = 0 returns the original features. lambda = 1 fully
projects away the learned cross-domain subspace.
project_features(projector, x, lambda = 1)project_features(projector, x, lambda = 1)
projector |
A |
x |
Numeric matrix, data frame, or named numeric vector of feature values. |
lambda |
Numeric scalar in |
A numeric matrix with corrected features.
set.seed(2) x <- rbind( matrix(rnorm(20), nrow = 5), matrix(rnorm(20) + 1, nrow = 5) ) colnames(x) <- paste0("feature_", seq_len(ncol(x))) domain <- rep(c("A", "B"), each = 5) projector <- fit_domain_projector(x, domain) project_features(projector, x, lambda = 0) project_features(projector, x, lambda = 0.5) project_features(projector, x, lambda = 1)set.seed(2) x <- rbind( matrix(rnorm(20), nrow = 5), matrix(rnorm(20) + 1, nrow = 5) ) colnames(x) <- paste0("feature_", seq_len(ncol(x))) domain <- rep(c("A", "B"), each = 5) projector <- fit_domain_projector(x, domain) project_features(projector, x, lambda = 0) project_features(projector, x, lambda = 0.5) project_features(projector, x, lambda = 1)
Convenience wrapper for correcting a single named feature vector.
project_new_sample(projector, sample, domain = NULL, lambda = 1)project_new_sample(projector, sample, domain = NULL, lambda = 1)
projector |
A |
sample |
Named numeric vector, one-row data frame, or one-row matrix. |
domain |
Optional source-domain label for the sample. If supplied, it must match one of the training domains. |
lambda |
Numeric scalar in |
A named numeric vector of corrected features.
set.seed(3) x <- rbind( matrix(rnorm(20), nrow = 5), matrix(rnorm(20) + 1, nrow = 5) ) colnames(x) <- paste0("feature_", seq_len(ncol(x))) domain <- rep(c("A", "B"), each = 5) projector <- fit_domain_projector(x, domain) new_sample <- setNames(rnorm(ncol(x)) + 1, colnames(x)) project_new_sample(projector, new_sample, domain = "B", lambda = 0.8)set.seed(3) x <- rbind( matrix(rnorm(20), nrow = 5), matrix(rnorm(20) + 1, nrow = 5) ) colnames(x) <- paste0("feature_", seq_len(ncol(x))) domain <- rep(c("A", "B"), each = 5) projector <- fit_domain_projector(x, domain) new_sample <- setNames(rnorm(ncol(x)) + 1, colnames(x)) project_new_sample(projector, new_sample, domain = "B", lambda = 0.8)