Sorry if this question is too basic for the forum. I am trying to determine the number of recurrently mutated genes expected by chance given an equal likelihood of mutation for all genes. There are about 20,000 genes and I have ~400 mutations spread across ~100 individuals. I want to determine the probability of the same gene being mutated in multiple individuals. I have tried the following simulation. I'm surprised that I'm always getting the same number of recurrences. Am I making some mistake?
var = 400
individuals = 100
genes = 2e4
mutated_genes <- sample(rep(c(1,0), c(var,genes*individuals-var)))
sample_mat <- matrix(mutated_genes, ncol = individuals, nrow = genes)
trials <- 1e4
recurrences <- vector(mode = "list", length = trials)
for (i in seq_len(trials)){
# print(i)
new_rows <- sample(nrow(sample_mat))
new_cols <- sample(ncol(sample_mat))
new_mat <- sample_mat[new_rows, new_cols]
recurrences[[i]] <- rowSums(new_mat)
}
n_recurrences <- sapply(recurrences, function(x) sum(x > 1))
summary(n_recurrences)
```