Hello R-help Readers I'm currently in the process of trying to write a permutation test procedure for looking at differences between groups with a multivariate data set (something equivalent to ANOSIM - analaysis of similarities for those familiar with this test). As with other permutation tests, for cases where there are large numbers of possible permutations, randomly sampling from these is appropriate, and can be done simply using sample(vector_x) to create each random permutation. However, where sample sizes are small, it is more appropriate (I think) to exhaustively calculate all possible permutations. This is equivalent to determining all possible ways of assigning n samples to each of k groups = (kn)!/[(n!)^k*k!]. As a relative beginner at programming, I suspect that writing the code to determine (and list) these permutations is far beyond me. I am wondering, therefore, whether anyone out there has done somehting similar, or knows of any suitable routine to calculate these permutations that they would be willing to share with me. Thanks in advance. Nick ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Dr Nick Bond Department of Biological Sciences Monash University (Clayton Campus) Victoria, Australia, 3800 Ph: +61 3 9905 5606 Fax: +61 3 9905 5613 Email: Nick.Bond at sci.monash.edu.au ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Nick Bond wrote:> ...However, where sample sizes are small, it is more appropriate (I think) > to exhaustively calculate all possible permutations. This is equivalent > to determining all possible ways of assigning n samples to each of k > groups = (kn)!/[(n!)^k*k!].Perhaps this will do the job. Jim -------------- next part -------------- insert.value<-function(vec,newval,pos) { if(pos == 1) return(c(newval,vec)) lvec<-length(vec) if(pos > lvec) return(c(vec,newval)) return(c(vec[1:pos-1],newval,vec[pos:lvec])) } permute<-function(elem) { if(!missing(elem)) { if(length(elem) == 2) return(matrix(c(elem,elem[2],elem[1]),nrow=2)) last.matrix<-permute(elem[-1]) dim.last<-dim(last.matrix) new.matrix<-matrix(0,nrow=dim.last[1]*(dim.last[2]+1),ncol=dim.last[2]+1) for(row in 1:(dim.last[1])) { for(col in 1:(dim.last[2]+1)) new.matrix[row+(col-1)*dim.last[1],]<-insert.value(last.matrix[row,],elem[1],col) } return(new.matrix) } else cat("Usage: permute(elem)\n\twhere elem is a vector\n") }
On Wed, 16 Jan 2002, Nick Bond wrote:> However, where sample sizes are small, it is more appropriate (I think) > to exhaustively calculate all possible permutations. This is equivalent > to determining all possible ways of assigning n samples to each of k > groups = (kn)!/[(n!)^k*k!]. As a relative beginner at programming, I > suspect that writing the code to determine (and list) these permutations > is far beyond me. I am wondering, therefore, whether anyone out there > has done somehting similar, or knows of any suitable routine to > calculate these permutations that they would be willing to share with > me.The k=2 case is discussed in the first two "Programmers' Niche" columns of the R Newsletter. This should provide a starting point. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Seemingly Similar Threads
- [R-pkg-devel] Run garbage collector when too many open files
- Run garbage collector when too many open files
- Why the contrain does not work for selecting a particular range of data?
- [LLVMdev] Proposal: "load linked" and "store conditional" atomic instructions
- [LLVMdev] Floating point atomic load and add