R 4组之间的限制排列,每个重复2次

R 4组之间的限制排列,每个重复2次,r,sas,permutation,R,Sas,Permutation,我试图比较4组,每组2个样本(重复),以了解微阵列项目中10000多个基因组之间的差异。我使用排列的方法计算F统计量,因为样本量对于标准t检验来说太小了 样本数据: 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

我试图比较4组,每组2个样本(重复),以了解微阵列项目中10000多个基因组之间的差异。我使用排列的方法计算F统计量,因为样本量对于标准t检验来说太小了

样本数据:

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
使用F-统计量和无均值差异的空值,我能够计算R中每个基因的obs F-值。但在进行排列时,我知道需要考虑8C2*6C2*4C2*2C2不同的成对排列。我无法在R中为这2520个排列编码

在R或SAS宏中是否有一个包可以帮助我获得排列的确切顺序?我尝试了'permute'包中的allPerms函数和'cominat'包中的permn函数,但我得到了所有可能的置换,而不是感兴趣的受限置换。我在Pearl和python中看到过做受限置换的代码,但我对这两种代码都不太熟悉,无法修改代码

例如,对于2组(G1和G2),设置为每个重复2次(A1、A2和B1、B2):

我想得到4组中排列的确切顺序,每个设置2个样本,即2520行和8列


谢谢

最后我自己编写了一个函数来实现4、6或8个样本设置,成对排列:

>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)
>库(combinat)
>#用于显示不在主数据集中的列的函数

>“%w/o%”排列我看到你给我的电子邮件中有这个问题的内容,但我想我会在这里回复以作记录;你说得对,permute不能这么做。允许它出现在我的待办事项列表中,但允许从排列集合中随机抽取而不生成所有排列是非常重要的,如果我要将其添加到包中,我需要集合中的所有排列和随机排列。谢谢你,加文!我去看看!
>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)