nmfkc: Non-negative Matrix Factorization with Kernel Covariates

Lifecycle: experimental GitHub version

nmfkc is an R package that extends Non-negative Matrix Factorization (NMF) by incorporating covariates using kernel methods. It supports advanced features like rank selection via cross-validation, time-series modeling (NMF-VAR), supervised classification (NMF-LAB), structural equation modeling with equilibrium interpretation (NMF-SEM), and mixed-effects modeling with random effects (NMF-RE).

Installation

# install.packages("remotes")
remotes::install_github("ksatohds/nmfkc")
library(nmfkc)

Help and Usage

browseVignettes("nmfkc")
ls("package:nmfkc")
?nmfkc

Citation

citation("nmfkc")

Quick Example

library(nmfkc)

# Decompose a matrix Y into basis X and coefficient B with rank = 2
X_true <- cbind(c(1, 0, 1), c(0, 1, 0))
B_true <- cbind(c(1, 0), c(0, 1), c(1, 1))
Y <- X_true %*% B_true

res <- nmfkc(Y, rank = 2, epsilon = 1e-6)
plot(res)     # Convergence plot
summary(res)  # Summary statistics

See browseVignettes("nmfkc") for detailed examples covering rank selection, kernel NMF, time-series, classification, NMF-SEM, and NMF-RE.

Comparison with Standard NMF

Feature Standard NMF nmfkc
Handles covariates No Yes (Linear / Kernel)
Structural equation modeling No Yes (NMF-SEM)
Mixed-effects / Random effects No Yes (NMF-RE)
Classification No Yes (NMF-LAB)
Time series modeling No Yes (NMF-VAR)
Nonlinearity No Yes (Kernel)
Clustering support Limited Yes (Hard/Soft)
Rank selection / CV Limited (ad hoc) Yes (Element-wise CV, Column-wise CV)

Statistical Model

The nmfkc package builds upon the standard NMF framework by incorporating external information (covariates):

\[Y(P,N) \approx X(P,Q) \times C(Q,R) \times A(R,N)\]

Extensions

Main Functions

Function Description
nmfkc() Core NMF with covariates (\(Y \approx XCA\)); supports kernel matrices and formula interface
nmfre() / nmfre.inference() NMF with Random Effects + wild bootstrap inference
nmf.sem() / nmf.sem.inference() NMF Structural Equation Model + inference for path coefficients
nmfae() / nmfae.inference() NMF Autoencoder + inference
nmfkc.rank() Rank selection via elbow, cross-validation, ECV, and CPCC
nmfkc.inference() Sandwich SE and wild bootstrap p-values for nmfkc
nmfkc.DOT() / nmfkc.ar.DOT() / nmf.sem.DOT() / nmfae.DOT() Graphviz path diagrams; render with plot()

S3 methods coef(), fitted(), residuals(), plot(), summary(), predict() are available for all model classes. See ?nmfkc or browseVignettes("nmfkc") for the full function list.

References