Permutation test of whether the anchor displacement matrix carries
coherent, structured signal orthogonal to the estimated batch subspace –
an overidentification-style check of the instrumental-variable assumption
underlying somalign_fit_anchored()'s correction = "subspace" mode:
anchors should isolate the batch direction, not biology.
Arguments
- fit
A
somalign_anchored_fitobject fromsomalign_fit_anchored(..., correction = "subspace")or"both".- n_perm
Positive integer. Number of permutation replicates. Default
999L.- seed
Integer or
NULL. RNG seed for reproducibility (restored on exit; does not leak into the caller's session). Default1L;NULLdisables seeding.
Value
A list of class somalign_exclusion_test with sv_observed,
sv_null, p_value, null_quantiles, relative_stat, rank_used,
n_anchors, n_features, verdict ("pass" if p > 0.1, "warn" if
in [0.05, 0.1], "fail" if < 0.05), and feature_residual_norm
(per-feature ||R[, j]||, identifying which markers drive a violation).
Details
The statistic is the leading singular value of the orthogonal residual
\(R = D (I - V V^\top)\), where \(D\) is the scaled anchor displacement
matrix (fit$anchors$displacements) and \(V\) is the estimated batch
subspace (fit$anchors$batch_subspace$V). The null distribution is
generated by permuting each feature (column) of \(R\) independently
across anchors, which preserves each feature's own variance but destroys
any coherent cross-feature direction. A small p-value means \(R\)'s
features move together more than chance recombination would produce –
i.e., the anchors carry a real, structured direction that correction = "subspace" is not removing (a batch-direction violation, or biology
leaking through the anchors). A large p-value supports the assumption that
anchors capture only batch structure.
Row permutation of \(R\) or \(D\) would not work here: row permutation is an orthogonal transformation and leaves every singular value of a matrix exactly invariant, so it cannot detect anything. Column-wise permutation is required because it is not an orthogonal row transform and genuinely decorrelates features.
The test has no power when variance_threshold = 1 (V spans the full
feature space, so R is identically zero), and low power when
n_anchors < 3 * rank, or when the true structure is fully absorbed into
\(V\) (inspect fit$anchors$batch_subspace$rank and
variance_explained).
Role
A diagnostic validating the correction path's assumption,
not a label-transfer diagnostic. A fail verdict means the corrected
coordinates may mix biology into the batch subspace; it does not impugn the
transferred labels, which are computed from the transport plan alone.
Examples
set.seed(1)
p <- 3L
mat <- rbind(
matrix(rnorm(20 * p, mean = -2), ncol = p),
matrix(rnorm(20 * p, mean = 2), ncol = p)
)
colnames(mat) <- paste0("F", seq_len(p))
ref <- somalign_train_reference(mat, grid = kohonen::somgrid(2, 2, "hexagonal"),
rlen = 5)
shifted <- mat + 0.5
qry <- somalign_query(shifted, ref, grid = kohonen::somgrid(2, 2, "hexagonal"),
rlen = 5)
anc_idx <- 1:10
fit <- somalign_fit_anchored(qry, ref,
anchor_old = mat[anc_idx, , drop = FALSE],
anchor_new = shifted[anc_idx, , drop = FALSE],
rho_anchor = 1, correction = "subspace")
#> somalign_fit: 3 query node(s) have match_mass_ratio > 1 (max 1.11); this is expected in unbalanced OT. See diagnostics$ot$match_mass_ratio for details.
somalign_exclusion_test(fit, n_perm = 199L)
#> <somalign_exclusion_test>
#> sv_observed = 0.0000 p = 0.9196 verdict = pass
#> null sv (2.5%/50%/97.5%): 0.0000 / 0.0000 / 0.0000
#> rank = 1 n_anchors = 10 n_features = 3