1

I have a symmetric but sparse matrix of 0's and 1's representing whether or not there is an edge or link between two objects --- an adjacency matrix. I am attempting to work with the command PAM in the cluster package in R, which requires either a dissimilarity-matrix (and in particular the upper-triangular of this matrix) or a distance.

Below find a representative matrix (although my matrix has many more edges and nodes and unlike this matrix is in fact sparse).

0  1 0 0
1  0 0 0
0  0 0 1
0  0 1 0

I require an upper-triangular version of my matrix which means that I need to obtain this matrix. my problem is that is that my matrix at least is singular so Matrix commands such as a regular LU decomposition or Choleski decomposition do not work with it.

here is the error message that I got when I tried my 64 * 64 sparse matrix:

Warning message:
In .local(x, ...) :
Exact singularity detected during LU decomposition: U[i,i]=0, i=20.

I have read over several posts here on sparse matrices including "Large Sparse Matrix to Triangular Matrix R"

but they do not seem to do exactly what I want.

I am wondering if anyone has advice on what R commands I should try to obtain my desired matrix. If necessary, I can attempt to program up my own function but I would rather not do so.

Community
  • 1
  • 1
Jourdan Gold
  • 55
  • 1
  • 2
  • 10
  • If your matrix is 64x64, what is wrong with the first try in the linked question? `x <- x * upper.tri(x)` – Blue Magister Feb 01 '13 at 20:11
  • If what you need is to cluster your data using the affinity matrix, then you may try spectral clustering. – Min Lin Feb 03 '13 at 09:34
  • @Blue Magister The problem with doing this seems to be that R converts it to logical. This confused me but after rereading your comment, thanks. I tried using as.numeric(lower.tri(x)) and it seems to give me somewhat what I want. I also wrote n R function that does exactly what I want since I have a symmetic matrix and only require n*(n-1)/2 elements. – Jourdan Gold Feb 04 '13 at 14:38
  • @Min Lin do you think that this is better in the sense of producing more accurate results than using a a method such as partitioning along metoids (PAM) and if so why. Also realize that my ultimate goal is data reduction so the clustering is a means to an end. Futher what R clustering function would you recommend to perform the clustering. – Jourdan Gold Feb 04 '13 at 14:51
  • Yes I do think it is better, since spectral clustering can discover the intrinsic manifold of the data, and do clustering on the manifold. Once you understand how spectral works, implementation is nothing more than eigen vector calculation and kmeans. – Min Lin Feb 05 '13 at 06:56

0 Answers0