basiscor
computes the correlation matrix between basis vectors, i.e.
the columns of its basis matrix -- which is the model's first matrix factor.
profcor
computes the correlation matrix between basis profiles,
i.e. the rows of the coefficient matrix -- which is the model's second
matrix factor.
basiscor(x, y, ...) profcor(x, y, ...)
basis
or coef
.basis
or coef
, and dimensions compatible with x
.
If missing the correlations are computed between x
and y=x
.cor
.Each generic has methods defined for computing correlations between NMF models
and/or compatible matrices.
The computation is performed by the base function cor
.
signature(x = "NMF", y = "matrix")
: Computes the correlations between the basis vectors of x
and
the columns of y
.
signature(x = "matrix", y = "NMF")
: Computes the correlations between the columns of x
and the the basis vectors of y
.
signature(x = "NMF", y = "NMF")
: Computes the correlations between the basis vectors of x
and y
.
signature(x = "NMF", y = "missing")
: Computes the correlations between the basis vectors of x
.
signature(x = "NMF", y = "matrix")
: Computes the correlations between the basis profiles of x
and
the rows of y
.
signature(x = "matrix", y = "NMF")
: Computes the correlations between the rows of x
and the basis
profiles of y
.
signature(x = "NMF", y = "NMF")
: Computes the correlations between the basis profiles of x
and y
.
signature(x = "NMF", y = "missing")
: Computes the correlations between the basis profiles of x
.
# generate two random NMF models
a <- rnmf(3, 100, 20)
b <- rnmf(3, 100, 20)
# Compute auto-correlations
basiscor(a)
## [,1] [,2] [,3]
## [1,] 1.00000000 0.031692962 -0.130764317
## [2,] 0.03169296 1.000000000 0.005822748
## [3,] -0.13076432 0.005822748 1.000000000
profcor(a)
## [,1] [,2] [,3]
## [1,] 1.00000000 0.01844804 -0.3558334
## [2,] 0.01844804 1.00000000 -0.4002484
## [3,] -0.35583337 -0.40024844 1.0000000
# Compute correlations with b
basiscor(a, b)
## [,1] [,2] [,3]
## [1,] -0.12364568 0.0318066 -0.10049324
## [2,] 0.25546157 -0.2613076 0.10991557
## [3,] -0.09445275 0.1756572 0.01520068
profcor(a, b)
## [,1] [,2] [,3]
## [1,] 0.2791156 0.3824726 -0.179987068
## [2,] 0.1829474 -0.3038400 0.100952866
## [3,] -0.3415462 0.3049951 -0.007022731
# try to recover the underlying NMF model 'a' from noisy data
res <- nmf(fitted(a) + rmatrix(a), 3)
# Compute correlations with the true model
basiscor(a, res)
## [,1] [,2] [,3]
## [1,] -0.31181600 0.8721197 0.2896024
## [2,] 0.06017881 -0.1009603 0.9139113
## [3,] 0.92772281 0.1700795 -0.1742550
profcor(a, res)
## [,1] [,2] [,3]
## [1,] -0.5849075 0.84442507 0.1132048
## [2,] -0.2235612 -0.46983743 0.9746677
## [3,] 0.9477745 0.01338298 -0.5489273
# Compute correlations with a random compatible matrix
W <- rmatrix(basis(a))
basiscor(a, W)
## [,1] [,2] [,3]
## [1,] 0.040376132 0.196558218 -0.19100255
## [2,] -0.008386611 -0.006604350 -0.06910496
## [3,] 0.049164413 0.008146703 -0.06187523
identical(basiscor(a, W), basiscor(W, a))
## [1] FALSE
H <- rmatrix(coef(a))
profcor(a, H)
## [,1] [,2] [,3]
## [1,] 0.4419684 0.4538796 0.01153729
## [2,] 0.2976432 0.3639700 -0.48356340
## [3,] -0.2106585 -0.1186591 -0.10612098
identical(profcor(a, H), profcor(H, a))
## [1] FALSE