Dear all,

I'm having some problems getting my recursive function to work. At first I 
though that maybe my data was too big and I increase option(expressions=50000). 
Then I thought that I would try it on some smaller data. Still not working. :( 
I would have thought there should be a function for this already, so any 
suggestions are welcomed for other methods. I did try igraph but couldn't get 
cliques() to give anything useful. Also a quick play with hclust and cut, again 
nothing too useful.

Basically the function is trying to find uniquely connected subgraphs. So the 
sub-network is only connected by itself and not to other nodes. If everything 
is connected then the list (connectedList) should be length of 1 and have every 
index in the 1st slot.

cheers,

Paul


findconnection<-function(mat, cutoff){
        toList<-function(mat, connectList, cutoff, i, idx){
                idx<-which(mat[,idx] < cutoff)
                if(length(idx) >= 1){
                        connectList[[i]]<-idx
                        for(z in 1:length(idx)){
                                connectList<-toList(mat, connectList, cutoff, 
i, idx[z])
                        }
                }else{
                        return(connectList)
                }
        }
        
        connectList<-list()
        for(i in 1:ncol(mat)){
                connectList<-toList(mat, connectList, cutoff, i, i)
        }
        return(unique(connectList)) 
}

foomat<-matrix(sample(c(1,0.5,0), 100, replace=T), nrow=10) ## example data
> foomat
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]  0.0  0.5  0.0  0.5  0.5  0.0  0.5  1.0  0.5   0.0
 [2,]  0.0  1.0  1.0  0.0  0.0  1.0  0.0  1.0  0.5   1.0
 [3,]  1.0  1.0  1.0  1.0  0.5  0.0  0.5  0.5  0.5   0.5
 [4,]  0.0  0.5  0.0  0.0  0.5  0.5  0.5  0.0  1.0   0.0
 [5,]  0.5  0.5  1.0  1.0  0.5  1.0  1.0  0.5  0.5   0.5
 [6,]  0.0  0.5  0.0  0.5  0.5  0.5  0.5  0.5  1.0   1.0
 [7,]  1.0  1.0  0.0  1.0  0.0  0.5  1.0  1.0  0.5   0.5
 [8,]  0.5  1.0  0.0  0.5  1.0  0.0  1.0  0.0  0.0   0.0
 [9,]  0.0  0.5  0.0  0.0  0.5  0.0  0.5  0.0  0.5   0.5
[10,]  1.0  1.0  0.5  1.0  0.0  1.0  0.0  0.0  0.0   0.5
> pb<-findconnection(foomat, 0.01)
Error: C stack usage is too close to the limit
Error during wrapup: 

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to