Correlations in NMF Models

Description

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.

Usage

basiscor(x, y, ...)

profcor(x, y, ...)

Arguments

x
a matrix or an object with suitable methods basis or coef.
y
a matrix or an object with suitable methods basis or coef, and dimensions compatible with x. If missing the correlations are computed between x and y=x.
...
extra arguments passed to cor.

Details

Each generic has methods defined for computing correlations between NMF models and/or compatible matrices. The computation is performed by the base function cor.

Methods

  1. basiscorsignature(x = "NMF", y = "matrix"): Computes the correlations between the basis vectors of x and the columns of y.

  2. basiscorsignature(x = "matrix", y = "NMF"): Computes the correlations between the columns of x and the the basis vectors of y.

  3. basiscorsignature(x = "NMF", y = "NMF"): Computes the correlations between the basis vectors of x and y.

  4. basiscorsignature(x = "NMF", y = "missing"): Computes the correlations between the basis vectors of x.

  5. profcorsignature(x = "NMF", y = "matrix"): Computes the correlations between the basis profiles of x and the rows of y.

  6. profcorsignature(x = "matrix", y = "NMF"): Computes the correlations between the rows of x and the basis profiles of y.

  7. profcorsignature(x = "NMF", y = "NMF"): Computes the correlations between the basis profiles of x and y.

  8. profcorsignature(x = "NMF", y = "missing"): Computes the correlations between the basis profiles of x.

Examples



# 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.000000000  0.002832302  0.001811307
## [2,] 0.002832302  1.000000000 -0.023472377
## [3,] 0.001811307 -0.023472377  1.000000000
profcor(a)
##            [,1]        [,2]       [,3]
## [1,] 1.00000000  0.04038058  0.1831802
## [2,] 0.04038058  1.00000000 -0.1175582
## [3,] 0.18318015 -0.11755822  1.0000000
# Compute correlations with b
basiscor(a, b)
##            [,1]        [,2]        [,3]
## [1,] -0.1506997  0.25794134  0.01496264
## [2,] -0.1760592  0.12459513  0.07039194
## [3,]  0.2147027 -0.07054977 -0.14761369
profcor(a, b)
##              [,1]       [,2]        [,3]
## [1,] -0.337083519  0.0395968  0.12809773
## [2,]  0.486266550  0.4112057 -0.01741619
## [3,]  0.008375222 -0.1303696  0.08691115
# 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.16366147  0.16669351  0.8988624
## [2,] -0.01525924  0.92270111 -0.1579711
## [3,]  0.90359590 -0.09109778  0.2158581
profcor(a, res)
##             [,1]       [,2]       [,3]
## [1,] -0.07781368  0.1353395  0.9762089
## [2,] -0.05590908  0.9677684 -0.1113971
## [3,]  0.93949410 -0.1546548  0.2578186
# Compute correlations with a random compatible matrix
W <- rmatrix(basis(a))
basiscor(a, W)
##            [,1]       [,2]        [,3]
## [1,]  0.1080098 0.02537842 -0.03644463
## [2,]  0.1117260 0.02301282 -0.03037381
## [3,] -0.1136428 0.03562125 -0.06558372
identical(basiscor(a, W), basiscor(W, a))
## [1] FALSE
H <- rmatrix(coef(a))
profcor(a, H)
##             [,1]         [,2]        [,3]
## [1,]  0.10997052  0.374311391 -0.22244290
## [2,] -0.10906414 -0.234772365 -0.18484354
## [3,]  0.06612178 -0.001655487 -0.09258184
identical(profcor(a, H), profcor(H, a))
## [1] FALSE