Penalized Fisher's linear discriminant (Witten & Tibshirani 2011) with L1 or fused-lasso penalties, multi-class support, and built-in cross-validation.
Usage
plda(x, ...)
# Default S3 method
plda(
x,
y,
K = NULL,
lambda = NULL,
penalty = c("L1", "fused"),
lambda2 = NULL,
autotune = TRUE,
nfold = 5L,
lambda_grid = NULL,
maxit = 100L,
tol = 0.000001,
na.action = c("impute", "omit"),
encoding = c("onehot", "means", "integer", "auto"),
encoding_spec = NULL,
nthreads = 0L,
...
)
# S3 method for class 'formula'
plda(formula, data = NULL, ...)Arguments
- x
Numeric predictor matrix or a data frame (factor / character columns are expanded to a numeric model matrix via
model.matrix(~ ., x), with the intercept column dropped), or a formula for the formula interface.- ...
Passed to methods.
- y
Factor (or coercible) class label of length
nrow(x).- K
Number of discriminant vectors (
<= G-1). If supplied,Kis fixed; ifNULL(default),Kis chosen by cross-validation along withlambda. Whenautotune = FALSE,NULLmeansG-1.- lambda
Magnitude penalty. Required when
autotune = FALSE.- penalty
"L1"(default) or"fused".- lambda2
Fused-lasso difference penalty (used when
penalty = "fused").- autotune
If
TRUE(default), cross-validatelambda(andK).- nfold
CV folds.
- lambda_grid
Optional CV grid.
- maxit
MM solver maximum iterations.
- tol
MM solver convergence tolerance.
- na.action
Strategy for missing values in the predictors
x."impute"(default) replaces eachNAwith that column's median (the medians are stored on the fit and reapplied atpredict());"omit"drops rows with anyNAinx(subsettingyto match). Either way a warning is emitted.NaN/Infinxare always a hard error, and a missing class labelyalways hard-stops (yis never imputed or dropped). For the formula method the model frame is built withna.action = na.passand this rule is applied downstream. Whenxcarries factor / character columns,NAs in those columns are imputed on the expanded indicator scale (median of the 0/1 dummies), not on the original level; passna.action = "omit"to drop such rows if that matters.- encoding
How factor / character columns in a data-frame
xare converted to numeric predictors:"onehot"(default) reproduces the legacymodel.matrix(~ ., x)indicator expansion exactly;"means","integer", and"auto"defer torr_encode_factors(). The recipe is stored on the fit and replayed atpredict(). Ignored for a numeric matrixxor the formula interface.- encoding_spec
Optional explicit encoding recipe passed to
rr_encode_factors()asspec; when supplied the default"onehot"model-matrix path is bypassed.- nthreads
Integer. Number of worker threads for the cross-validation autotune (
autotune = TRUE).0(the default, taken fromgetOption("roadrunner.nthreads")when set) usesRcppParallel::defaultNumThreads(). The CV fold loop is parallelised with fixed per-fold output slots and a serial-order reduction, so the fitted discriminants are byte-identical regardless ofnthreads. Ignored whenautotune = FALSE(a single fit is already sequential).- formula
A model formula; response on the left, predictors on the right.
- data
A data frame (or environment) containing the formula variables.