2016-03-09 9 views
1

我試圖比較4個組和每個2個樣本(重複)以瞭解每個組之間對於來自微陣列項目的10,000多個基因的差異。我使用排列方法並計算F統計量,因爲樣本量對於標準t檢驗來說太小。4組之間的限制性排列和每組2次重複

樣本數據:

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中的代碼可以執行受限制的permuations,但是我並不熟悉修改代碼。

例如, 2組(G1和G2)與2設定複製各(A1,A2和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 

我想和2個樣品的每個設置得到在4組排列的確切順序即2520行和8列。

謝謝!

+0

我看到你的email給我這個問題的內容,但認爲我會在此回覆記錄;你是對的,**置換**不能這樣做。允許它在我的待辦事項列表中,但允許從該組置換中隨機抽取而不產生所有置換,並且如果要將其添加到包中,則需要來自該組的所有置換和隨機置換。有[在Sage功能](http://doc.sagemath.org/html/en/reference/combinat/sage/combinat/set_partition_ordered.html#sage.combinat.set_partition_ordered.OrderedSetPartition) –

+1

謝謝加文!我會檢查出來的! –

回答

1

我結束了編碼函數自己實現一個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)