Returns the residual matrix \(Y - \hat{Y}\) from a fitted NMF model.
Requires the original observation matrix Y to be supplied.
For nmfre objects, residuals are computed from the BLUP
reconstruction (\(Y - X(B_{blup})\)) by default. Set
type = "fixed" to use fixed-effects only.
See also
nmfkc, nmfae, nmfre,
nmf.sem, fitted.nmf
Examples
Y <- matrix(runif(50), 5, 10)
result <- nmfkc(Y, rank = 2)
#> Y(5,10)~X(5,2)B(2,10)...
#> 0sec
residuals(result, Y)
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.03932869 0.01211109 0.09328417 0.1854943496 0.10714171 -0.21789073
#> [2,] -0.06931658 0.11677514 0.15404965 -0.0003232773 0.13684125 -0.13694704
#> [3,] 0.02027536 -0.20117599 -0.15972580 -0.1362279697 -0.01335808 0.14407427
#> [4,] -0.01454579 0.11408894 -0.11052999 -0.2256276981 -0.01153430 0.14886973
#> [5,] 0.11242263 -0.05758333 -0.08376215 0.2122206750 -0.23419550 0.05358534
#> [,7] [,8] [,9] [,10]
#> [1,] -0.10961650 -0.12365553 -0.152619253 0.01874115
#> [2,] -0.14830670 -0.11815375 -0.050574787 0.03609031
#> [3,] 0.36034912 0.11236173 -0.007766607 0.05500918
#> [4,] -0.02560332 0.04254222 0.153937641 0.03931061
#> [5,] -0.07586746 0.08968673 0.045248172 -0.20557764