Skip to contents

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, K is fixed; if NULL (default), K is chosen by cross-validation along with lambda. When autotune = FALSE, NULL means G-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-validate lambda (and K).

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 each NA with that column's median (the medians are stored on the fit and reapplied at predict()); "omit" drops rows with any NA in x (subsetting y to match). Either way a warning is emitted. NaN / Inf in x are always a hard error, and a missing class label y always hard-stops (y is never imputed or dropped). For the formula method the model frame is built with na.action = na.pass and this rule is applied downstream. When x carries 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; pass na.action = "omit" to drop such rows if that matters.

encoding

How factor / character columns in a data-frame x are converted to numeric predictors: "onehot" (default) reproduces the legacy model.matrix(~ ., x) indicator expansion exactly; "means", "integer", and "auto" defer to rr_encode_factors(). The recipe is stored on the fit and replayed at predict(). Ignored for a numeric matrix x or the formula interface.

encoding_spec

Optional explicit encoding recipe passed to rr_encode_factors() as spec; 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 from getOption("roadrunner.nthreads") when set) uses RcppParallel::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 of nthreads. Ignored when autotune = 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.

Value

An object of S3 class "plda".