1

I have some genetic data, which looks like:

gene<-c("gene_1","gene_1","gene_2","gene_2","gene_3","gene_3")
label<-rep(c("before","after"),6)
exp<-c(1,2,3,1,5,2,5,3,4,2,6,5)
participant<-c(rep("id_1",6),rep("id_2",6))

df<-data.frame(participant,gene,label,exp)

I have performed a paired t-test on this data. I now want to do some permutation testing, as outlined here - https://statlab.github.io/permute/user/one-sample.html. I am struggling with how to do this in R.

I have written some code which allows me to permutate the labels in a for loop in an unpaired way:

df$label<- sample(c("Before","After"), size = length(df$label), replace = TRUE)

However, I want to do this in a paired way, i.e. for every gene in every participant, there is still exactly one before sample and one after sample (although these labels may sometimes be swapped). Using the above code, this is not always the case, e.g. both of the id_1, gene_1 samples may be labelled "After".

I want a for loop which will give me all possible permutations of the data for swapping the labels in this way (e.g. id_1, gene_1 labels switched, then id_1, gene_2 labels switched, so on then id_1, gene_1 AND id_1, gene_2 labels switched, and so on). This way I can repeat my normalization and paired t-test within each for loop, i.e. for all possible permutations of the data.

Thanks in advance for any help!

EmmaH
  • 85
  • 6

0 Answers0