nmfkc.ecv performs k-fold cross-validation by randomly holding out
individual elements of the data matrix (element-wise), assigning them a
weight of 0 via Y.weights, and evaluating the reconstruction error on
those held-out elements.
This method (also known as Wold's CV) is theoretically robust for determining
the optimal rank (Q) in NMF. This function supports vector input for Q,
allowing simultaneous evaluation of multiple ranks on the same folds.
Arguments
- Y
Observation matrix.
- A
Covariate matrix.
- Q
Vector of ranks to evaluate (e.g., 1:5).
- div
Number of folds (default: 5).
- seed
Integer seed for reproducibility.
- ...
Additional arguments passed to
nmfkc(e.g.,method="EU").
Value
A list with components:
- objfunc
Numeric vector containing the Mean Squared Error (MSE) for each Q.
- sigma
Numeric vector containing the Residual Standard Error (RMSE) for each Q. Only available if method="EU".
- objfunc.fold
List of length equal to Q vector. Each element contains the MSE values for the k folds.
- folds
A list of length
div, containing the linear indices of held-out elements for each fold (shared across all Q).