Fit robust-regression hemolysis nuisance model from training controls
Source:R/singlesample-hemolysis.R
fit_hemolysis_rr.RdFits per-feature Huber M-estimation robust regressions (MASS::rlm)
of log-expression on a hemolysis proxy score (and optionally a platelet
proxy). The resulting intercept and slope coefficients are frozen at fit
time. At deployment, the predicted nuisance contribution is subtracted from
test-sample log-expressions via apply_hemolysis_rr.
Failed fits (convergence failures, NA coefficients) fall back to a zero-slope
model (intercept = feature mean) and are flagged in the stable vector.
Usage
fit_hemolysis_rr(
X_train,
hemo_score,
platelet_score = NULL,
method = c("huber", "rlm"),
clip_max = 2
)Arguments
- X_train
Numeric matrix (samples \(\times\) features). Ideally a mix of clean and mildly contaminated training controls.
- hemo_score
Numeric vector of length
nrow(X_train). Hemolysis proxy score per training sample.- platelet_score
Optional numeric vector of length
nrow(X_train). Platelet contamination proxy. DefaultNULL(no platelet correction).- method
"huber"(default,MASS::rlmwithpsi.huber) or"rlm"(alias).- clip_max
Maximum absolute correction per feature in log-units. Default 2. Prevents over-correction from unstable slope estimates.
Value
Object of class hemolysis_rr_fit with components:
betas (features \(\times\) coefficients matrix), stable,
has_platelet, clip_max, train_hemo_range,
train_platelet_range, method, n_train.