Score quantile-function FDA (inv-fdaqf) within-sample discriminator
Source:R/singlesample-quantile-fda-scorers.R
score_inv_fdaqf.RdScores each row of X independently with the frozen model learned by
fit_inv_fdaqf. The model-universe features present in X
(intersect(model$feature_universe, colnames(X))) define the present
substrate; for one specimen its within-sample rCLR profile over exactly those
present features is resampled to the frozen quantile-function length, projected
onto the frozen FPCA eigenbasis (same functional mean and loadings as at
fitting), standardised by the frozen center/scale and passed
through the frozen linear head. Larger values are more case-like.
Scoring uses only each row's own values plus the frozen model – no test-batch
renormalisation, no cross-row coupling, no statistic estimated from X.
If fewer than model$hp$min_features model-universe features are present,
the documented neutral score 0 is returned for every row; a single
specimen whose own number of present rCLR coordinates falls below
model$hp$min_features likewise scores the neutral 0. A degenerate
fit whose frozen basis has realised \(K=0\) (every kept training QF
identical) scores every row the constant 0.
Arguments
- model
An
inv_fdaqf_modelobject returned byfit_inv_fdaqf.- X
Numeric matrix (samples \(\times\) features) of non-negative abundance values. Columns must be named feature ids.
- meta
Optional per-sample metadata. Accepted for interface uniformity and ignored by this method.
Value
Plain finite numeric vector of length nrow(X). Larger values
are more case-like. The score of a row depends only on that row's values and
the frozen model, and is exactly invariant to per-sample positive scaling.
Examples
if (FALSE) { # \dontrun{
set.seed(1)
p <- 60
features <- paste0("miR-", sprintf("%03d", seq_len(p)))
n <- 160
y <- rep(c(0, 1), each = n / 2)
X <- matrix(0, n, p, dimnames = list(NULL, features))
rank_frac <- (seq_len(p) - 1) / (p - 1)
ctrl_mu <- 2 + 3 * rank_frac
case_mu <- 2 + 3 * rank_frac^3
for (i in seq_len(n)) {
mu <- if (y[i] == 1) case_mu else ctrl_mu
X[i, ] <- exp(stats::rnorm(p, mean = mu, sd = 0.2))
}
model <- fit_inv_fdaqf(X, y)
score_inv_fdaqf(model, X[1, , drop = FALSE])
} # }