nmfre.ecv: NMF-RE element-wise cross-validation for rank selection

View source: R/nmfre.R

nmfre.ecvR Documentation

NMF-RE element-wise cross-validation for rank selection

Description

Selects the basis rank Q for nmfre by Wold-style element-wise (entry-holdout) cross-validation that exercises the random effects. For each fold the held-out entries are hidden and filled by iterative imputation: fit the NMF-RE model on the current matrix, replace the held-out entries with the BLUP prediction X(\Theta A + U), and repeat. The score is the held-out prediction RMSE (sigma); the selected rank minimizes it.

Because the held-out entries of a column are predicted using the random effect u_n fitted from that column's retained entries, this evaluates the full NMF-RE model (including U) — unlike nmfkc.ecv, which masks entries by zero weight and predicts from the fixed-effect fit X\Theta A only. The two scores are therefore not directly comparable.

Usage

nmfre.ecv(Y, A = NULL, rank = 1:3, C.signed = TRUE, ...)

Arguments

Y

Observation matrix (P x N), non-negative.

A

Covariate matrix (K x N). Default is a row of ones (intercept only).

rank

Integer vector of ranks Q to evaluate (default 1:3).

C.signed

Logical. Sign convention for \Theta passed to each nmfre fit (TRUE = sign-free, default; FALSE = non-negative). The basis update rule follows this choice automatically.

...

Additional arguments:

  • nfolds: Number of folds (default 5; legacy nfold also accepted).

  • rounds: Iterative-imputation rounds per fold (default 4).

  • seed: RNG seed for the fold assignment (default 1).

  • print.trace: Logical; print per-rank scores (default FALSE).

  • Convergence controls forwarded to nmfre: epsilon (default 1e-5), epsilon.outer (default 1e-3), inner.maxit (default 1500), outer.maxit (default 80), maxit (default 40000). CV does not need the tight tolerances of a final fit, so these are loosened by default.

Value

A list of class "nmfre.ecv" with components:

rank

The ranks evaluated.

sigma

Named numeric vector of held-out RMSE per rank (same field name as nmfkc.ecv).

best

The rank minimizing sigma.

nfolds, rounds, C.signed

Settings used.

See Also

nmfre, nmfre.inference, nmfkc.ecv

Examples


if (requireNamespace("nlme", quietly = TRUE)) {
  Y <- matrix(nlme::Orthodont$distance, 4, 27)
  male <- ifelse(nlme::Orthodont$Sex[seq(1, 108, 4)] == "Male", 1, 0)
  A <- rbind(intercept = 1, male = male)
  cv <- nmfre.ecv(Y, A, rank = 1:3)
  cv$best
  plot(cv)
}


nmfkc documentation built on July 14, 2026, 1:07 a.m.