1

I am trying to compare 4 groups with 2 samples each (replicates) to understand the differences among each group for a set of 10,000+ genes from a micro array project. I am using the method of permutations and calculating an F statistic as the sample size is too small for a standard t test.

Sample Data:

Gene    A1  A2  B1  B2  C1  C2  D1  D2
gene1  1.1 1.2 4.2 4.1 8.2 8.2 5.9 6.1 
gene2  2.7 2.6 3.1 2.9 7.2 7.8 7.1 7.0
.
.
gene10000 10.1 11.1 2.9 3.1 3.8 3.7 7.2 7.3

Using an F-statistic and a null of no mean difference, I was able to calculate the obs F- value for each gene in R. But when doing permutations, I understand that there will be 8C2 * 6C2 * 4C2 *2C2 different pairwise permutations which need to be accounted for. I am unable to code for these 2520 permutations in R.

Is there a package that I could look for in R or SAS macro that would help me getthe EXACT ORDER of the permutations? I tried the allPerms function from the 'permute' package and the permn function from the 'cominat' package but I get all possible permutations and not the restricted permutations of interest. I have seen codes in Pearl and python to do restricted permuations but I am not so well versed in either to modify the code.

For Eg. for 2 group (G1 and G2) setting with 2 replicates each (A1, A2 and B1, B2):

    G1   G2    
  A1 A2 B1 B2 
P1: A1 A2 B1 B2 
P2: A1 B1 A2 B2 
P3: A1 B2 A2 B1 
P4: A2 B1 A1 B2 
P5: A2 B2 A1 B1 
P6: B1 B2 A1 A2

I want to get the exact order of permutations in a 4 group with 2 samples each setting i.e. 2520 rows and 8 columns.

Thanks!

2
  • I saw your email to me with the content of this question but thought I'd respond here for the record; you are right, permute can't do this. Allowing it is on my to do list but it is non-trivial to allow for random draws from the set of permutations without generating all the permutations and I need both all permutations and random permutations from the set if I am to add this to the package. There are functions in Sage for this Mar 10, 2016 at 15:25
  • 1
    Thanks Gavin! I'll check that out!
    – M. R
    Mar 10, 2016 at 20:32

1 Answer 1

1

I ended up coding a function myself to achieve for a 4, 6 or 8 sample setting, the pairwise permutations:

>library(combinat)
> # function to show columns not in master data set
>"%w/o%" <- function(x, y) x[!x %in% y] #--  x without y
> permutations <- function(n, data)  {
  if(n %% 2 == 0)
  {
   if(n==2|n==4)
   {
    x <- t(combn(data,2))
    p <- nrow(x)
    A <- matrix(nrow= p , ncol = n )
    all <- matrix(data= c(rep(data)), nrow= p, ncol = n, byrow=T)
    for(i in 1: p)
    {
     A[i,] <- cbind(all[i,] %w/o% x[i,], x[i,])
    }
    return(matrix(A))
}
else if(n==6)
  {
   x <- t(combn(data,2))
   p <- nrow(x)
   A <- matrix(nrow= p*n , ncol = n ) # n=6
   all <- matrix(data= c(rep(data)), nrow= p, ncol = n, byrow=T)
   for( j in 1 :p)
   {
    absent <- all[j,] %w/o% x[j,]
    mat <- matrix(permutations(n-2, absent), ncol =n-2)
    present <- matrix(rep(x[j,], each = n), ncol =2)
    A[(j-1)*n+1:n,] <- cbind(present, mat)
   }
   return(matrix(A))
  }
else if(n==8)
  {
   x <- t(combn(data,2))
   p <- nrow(x)
   A <- matrix(nrow= 6*15*p , ncol = n ) # n=8
   all <- matrix(data= c(rep(data)), nrow= p, ncol = n, byrow=T)
   for( j in 1:p)
    {
    absent <- all[j,] %w/o% x[j,]
    mat <- matrix(permutations(n-2, absent), ncol =n-2)
    present <- matrix(rep(x[j,], each = 90), ncol =2)
    A[(j-1)*90+1:90,] <- cbind(present, mat)
   }
   return(matrix(A))
  }
}
   else 
    return("NA");
}

# m<- matrix(permutations(6, LETTERS[1:6]), ncol =6)
m <- matrix(permutations(8, LETTERS[1:8]), ncol =8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.