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.00000 -0.22539 0.04746
## [2,] -0.22539  1.00000 0.01396
## [3,]  0.04746  0.01396 1.00000
profcor(a)
##          [,1]     [,2]     [,3]
## [1,]  1.00000 -0.15633  0.07961
## [2,] -0.15633  1.00000 -0.01011
## [3,]  0.07961 -0.01011  1.00000
# Compute correlations with b
basiscor(a, b)
##          [,1]     [,2]     [,3]
## [1,]  0.13918  0.18983 -0.21230
## [2,] -0.02359 -0.12293  0.11838
## [3,]  0.07774  0.05237  0.06242
profcor(a, b)
##         [,1]    [,2]     [,3]
## [1,] -0.1245  0.2783 -0.11670
## [2,]  0.2344  0.1143 -0.03819
## [3,]  0.2888 -0.4145  0.18809

# 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.21476 -0.08249  0.9150
## [2,]  0.94672  0.23391 -0.4014
## [3,] -0.03902  0.92432  0.2603
profcor(a, res)
##          [,1]     [,2]     [,3]
## [1,] -0.02423 -0.19351  0.99094
## [2,]  0.92600  0.06939 -0.20129
## [3,] -0.31095  0.94392  0.07301

# Compute correlations with a random compatible matrix
W <- rmatrix(basis(a))
basiscor(a, W)
##           [,1]     [,2]      [,3]
## [1,] -0.003359 -0.01087  0.179082
## [2,] -0.135339  0.27243 -0.083516
## [3,] -0.045671 -0.05013  0.008125
identical(basiscor(a, W), basiscor(W, a))
## [1] FALSE

H <- rmatrix(coef(a))
profcor(a, H)
##          [,1]    [,2]    [,3]
## [1,]  0.01558 -0.2946  0.1403
## [2,] -0.08800  0.5352 -0.1909
## [3,]  0.14349  0.2588 -0.2547
identical(profcor(a, H), profcor(H, a))
## [1] FALSE