Package {CrossDomainAdjust}


Type: Package
Title: Lambda-Controlled Cross-Domain Feature Adjustment
Version: 0.1.1
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.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.1.0)
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2026-09-18 14:56:35 UTC; weika
Author: Weikaixin Kong [aut, cre]
Maintainer: Weikaixin Kong <weikaixin.kong@aalto.fi>
Repository: CRAN
Date/Publication: 2026-09-29 13:30:38 UTC

Fit a Cross-Domain Feature Projector

Description

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.

Usage

fit_domain_projector(x, domain, anchor = "domain_mean")

Arguments

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 x.

anchor

Character string or named numeric vector. Use "domain_mean" for the equal-weight mean of domain centroids, matching (mu_1 + ... + mu_K) / K. Use "sample_mean" for the sample-size-weighted feature mean. A named numeric vector can also be supplied as a custom projection anchor.

Value

An object of class "domain_projector".

Examples

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")
projector

Project Features with a Fitted Cross-Domain Projector

Description

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.

Usage

project_features(projector, x, lambda = 1)

Arguments

projector

A "domain_projector" returned by fit_domain_projector().

x

Numeric matrix, data frame, or named numeric vector of feature values.

lambda

Numeric scalar in [0, 1].

Value

A numeric matrix with corrected features.

Examples

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)

Project One New Sample

Description

Convenience wrapper for correcting a single named feature vector.

Usage

project_new_sample(projector, sample, domain = NULL, lambda = 1)

Arguments

projector

A "domain_projector" returned by fit_domain_projector().

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 [0, 1].

Value

A named numeric vector of corrected features.

Examples

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)