| nmfre | R Documentation |
Estimates the NMF-RE model
Y = X(\Theta A + U) + \mathcal{E}
where Y (P \times N) is a non-negative observation matrix,
X (P \times Q) is a non-negative basis matrix learned from the data,
\Theta (Q \times K) is a non-negative coefficient matrix capturing
systematic covariate effects on latent scores,
A (K \times N) is a covariate matrix, and
U (Q \times N) is a random effects matrix capturing
unit-specific deviations in the latent score space.
NMF-RE can be viewed as a mixed-effects latent-variable model defined on a
reconstruction (mean) structure. The non-negativity constraint on X
induces sparse, parts-based loadings, achieving measurement-side variable
selection without an explicit sparsity penalty. Inference on \Theta
provides covariate-side variable selection by identifying which covariates
significantly affect which components.
Estimation is an outer–inner ECM: an inner loop (fixed \lambda) runs a
ridge/BLUP update for U, an update for X (by default the exact
minimization under the column sums; see X.update), and
a fixed-effect update for \Theta; an outer loop runs the EM M-steps for
(\sigma^2, \tau^2). The variance components are estimated from the data;
the effective degrees of freedom df_U are reported only as a diagnostic.
nmfre() performs optimization only. Hypothesis tests and
standard errors for \Theta are obtained separately with
nmfre.inference (sandwich SE + wild bootstrap), mirroring the
nmfkc / nmfkc.inference split.
nmfre(
Y,
A = NULL,
rank = 2,
C.signed = TRUE,
X.update = c("exact", "semi"),
epsilon = 1e-05,
maxit = 5000,
...
)
Y |
Observation matrix (P x N), non-negative. |
A |
Covariate matrix (K x N). Default is a row of ones (intercept only). |
rank |
Integer. Rank of the basis matrix |
C.signed |
Logical. Whether the fixed-effect coefficients |
X.update |
The |
epsilon |
Convergence tolerance for relative change in objective (default 1e-5). |
maxit |
Maximum number of iterations. Default |
... |
Additional arguments for initialization, variance control, dfU control, optimization, and inference settings.
|
A list of class "nmfre" with components.
The model is Y = X(\Theta A + U) + \mathcal{E}.
Core matrices
XBasis matrix X (P \times Q), columns normalized to sum to 1.
X.probRow-wise soft-clustering probabilities from the
non-negative X (each row normalized to sum to 1), as in nmfkc.
X.clusterHard-clustering label for each row of X
(argmax over X.prob).
CCoefficient matrix \Theta (Q \times K).
URandom effects matrix U (Q \times N).
Variance components
sigma2Residual variance \hat{\sigma}^2.
tau2Random effect variance \hat{\tau}^2.
lambdaRidge penalty \lambda = \sigma^2 / \tau^2.
Convergence diagnostics
convergedLogical. Whether the algorithm converged.
stop.reasonCharacter string describing why iteration stopped.
iterNumber of iterations performed.
maxitMaximum iterations setting used.
epsilonConvergence tolerance used.
objfuncFinal objective function value
\|Y - X(\Theta A + U)\|^2 + \lambda \|U\|^2.
rel.change.finalFinal relative change in objective.
objfunc.iterNumeric vector of the fixed-\lambda
penalized objective \|Y - X(\Theta A + U)\|^2 + \lambda\|U\|^2
per iteration. Monotone within an inner loop but not across
outer iterations (the penalty jumps when \lambda is updated).
rss.traceNumeric vector of \|Y - X(\Theta A + U)\|^2 per iteration.
nll.traceNumeric vector of the marginal negative
log-likelihood \ell(X,\Theta,\sigma^2,\tau^2) per iteration
(random effects integrated out). This is the ECM-monotone quantity and
is what plot.nmfre displays.
Degeneracy diagnostic
degeneracyA list for detecting a degenerate fit, in which
two columns of X approach each other while the corresponding rows
of C grow with opposite signs (with Q \ge 2 and a signed
C: two bases suffice, so it can happen at Q = 2 as well,
e.g. when the rank exceeds what the data support; the fit does not
settle and those rows of C are not interpretable). In simulations such fits usually had a clearly lower
marginal likelihood than a fit from another start, so the default
X.init = "mix2" refits from other starts while flag is
TRUE and keeps the fit with the larger likelihood:
max.cosine (largest cosine similarity between two columns of
X) and its pair; cancellation
(\max_k \sum_q |c_{qk}| / \|X c_{\cdot k}\|_1, large when a composite
effect is a difference of large opposite terms); kappa.X (condition
number of X); and flag (max.cosine >= 0.9 or
cancellation >= 5). The thresholds were set on two simulation
designs; read the measures as well. summary() prints a line when
flag is TRUE.
X.init.searchWith X.init = "mix2": one row per fit
(start, seed, marginal nll, degenerate,
converged, chosen). summary() prints the start
kept and how far the others stopped from it.
Effective degrees of freedom (dfU) diagnostics
dfUFinal effective degrees of freedom
\mathrm{df}_U = N \sum_q d_q / (d_q + \lambda),
where d_q are eigenvalues of X'X.
dfU.capUpper bound imposed on \mathrm{df}_U.
dfU.cap.rateRate used to compute the cap.
lambda.enforcedFinal \lambda enforced to satisfy the cap.
dfU.hit.capLogical. Whether the cap was binding.
dfU.hit.iterIteration at which the cap first bound.
dfU.frac\mathrm{df}_U / (NQ), fraction of maximum df.
dfU.cap.frac\mathrm{df}_U^{\mathrm{cap}} / (NQ).
Fitted matrices
BFixed-effect scores \Theta A (Q \times N).
B.probColumn-normalized probabilities from
\max(\Theta A, 0).
B.blupBLUP scores \Theta A + U (Q \times N).
B.blup.posNon-negative BLUP scores
\max(\Theta A + U, 0) (Q \times N).
B.blup.probColumn-normalized probabilities from
\max(\Theta A + U, 0).
XBFitted values from fixed effects
X \Theta A (P \times N).
XB.blupFitted values including random effects
X(\Theta A + U) (P \times N).
Fit statistics
r.squaredPearson \mathrm{cor}(Y, X(\Theta A + U))^2
(BLUP prediction).
r.squared.uncenteredUncentered
1 - \|Y - X(\Theta A + U)\|_F^2 / \|Y\|_F^2 (BLUP;
baseline = zero matrix).
r.squared.centeredRow-mean centered
1 - \|Y - X(\Theta A + U)\|_F^2 / \|Y - \bar Y_{p\cdot}\|_F^2
(BLUP; baseline = per-row mean).
r.squared.fixedPearson \mathrm{cor}(Y, X\Theta A)^2
(fixed-only prediction).
r.squared.fixed.uncentered, r.squared.fixed.centeredUncentered
and centered R^2 for the fixed-only prediction.
ICCTrace-based Intraclass Correlation Coefficient.
In the NMF-RE model, the conditional covariance of the n-th
observation column is
\mathrm{Var}(Y_n) = \tau^2 X X^\top + \sigma^2 I_P,
a P \times P matrix. Unlike a standard random intercept model
where the design matrix Z is a simple indicator (so the ICC
reduces to \tau^2 / (\sigma^2 + \tau^2)), the basis matrix
X plays the role of Z in a random slopes model,
making the variance contribution of U depend on X.
To obtain a scalar summary, we take the trace of each component:
\mathrm{ICC} = \frac{\tau^2 \, \mathrm{tr}(X^\top X)}
{\tau^2 \, \mathrm{tr}(X^\top X) + \sigma^2 P}.
This equals the average (over P dimensions) proportion of
per-column variance attributable to the random effects.
Sign convention
C.signedLogical. Whether C was sign-free (TRUE) or non-negative (FALSE).
Identification region and orientation
Under the working model the fits giving the same distribution are
(XO, O^\top\Theta) with O orthogonal, O\mathbf 1=\mathbf 1
and XO\ge0 (and O^\top\Theta\ge0 for C.signed = FALSE):
the identification region. X\Theta is constant on it. For
Q=3 the O form a circle, and the arc through the fit is the
local identification region. The ends of the arc are found numerically
(a grid of 7200 angles refined by root finding, constraints met to
10^{-10}; an arc shorter than 10^{-7} is reported as a point);
the range of each entry of \Theta and of X over the arc is
then computed in closed form. A width of 0 means the fit cannot be moved
within the region, to this resolution (a row of X on one basis only
pins it). For Q\le2 the region is a point up to relabelling. For
Q\ge4 the bases pinned by anchors are removed one at a time: if a row
of X is non-zero, outside the bases already removed, on one basis
only (and, for C.signed = FALSE, if a column of C is), every
admissible O keeps that basis, because a non-negative row of O
with sum 1 and length 1 is a unit vector. Zeros are exact zeros unless
ident.zero.tol is set. If at most two bases remain the region is a
point up to relabelling; if three remain their local region (an arc, a
point, or the whole circle) is computed as for Q=3; if 4 to 7 remain
it is searched numerically (ident.search): the ranges then come from
points reached along paths from the fit that are feasible at each step,
and are approximate, not certified bounds (finding no other
representation is evidence, not a proof). Feasible transformations found
elsewhere in the family show that the fit is not unique globally; they are
counted (identification$search$global.nonperm) but not used in the
ranges, since they need not belong to the local region. The geomin
orientation and the profile intervals' use of the region are for
Q=3 only. By default (orient = "geomin") the
representation returned is the member of the local region that minimizes
the geomin criterion on the row shares of X (rows of zeros left out;
as rotated loadings in exploratory factor analysis), which defines the
reported coefficients when the region has positive width; nothing moves
when the region is a point. The search is local: it finds the minimizer
over the whole identification region only when the local region contains
it. With orient = "none" the representation returned is the point
where the algorithm stopped, which depends on the start. The likelihood
and X\Theta do not change.
C.ident.lower, C.ident.upper, C.ident.widthRange
of each entry of C over the local identification region and its
width (Q x K matrices; absent when the region is not computed).
X.ident.lower, X.ident.upper, X.ident.widthThe
same for X (P x Q matrices).
identificationList: width (largest entry of
C.ident.width; NA when not computed), arc and
full.circle of the region, method ("exact",
"anchors", "anchors+exact", "search",
"anchors+search" or "none"; "exact" means the arc
computed as above, in closed form over an arc whose ends are found
numerically, not a certified computation), pinned (bases pinned
by anchors, Q\ge4), Q.rest (bases left after them),
search (counts of the numerical search), and orient, the orientation
applied (rule, angle, O, moved: largest
change of C, the geomin criterion before and after,
eps, note). nmfre.inference adds its
identifiability diagnostic to this list.
Standard errors, z-values, p-values, and confidence intervals for
\Theta are not computed here; obtain them by passing the fit
to nmfre.inference.
Satoh, K. (2026). Wild Bootstrap Inference for Non-Negative Matrix Factorization with Random Effects. arXiv:2603.01468. https://arxiv.org/abs/2603.01468
nmfre.inference,
nmfkc.DOT, summary.nmfre
# Example 1. cars data
Y <- matrix(cars$dist, nrow = 1)
A <- rbind(intercept = 1, speed = cars$speed)
res <- nmfre(Y, A, rank = 1, maxit = 5000)
summary(res)
# Example 2. Orthodont data (nlme)
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)
# Fit (sign-free Theta by default; variances estimated by EM/ECM)
res <- nmfre(Y, A, rank = 1)
summary(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.