0

私は hardy-weinberg を使用して非常に単純なシミュレーションを行っています (すべての遺伝学中毒者向け)。 100代の流れ。Rの行列を理解しようとして立ち往生しています。

N = 30 # Size population in each line
lineN = 100 # Number of family lines
Genes0 = array(NA, dim=c(lineN, 2*N)) 

# Randomly form genotypes by sample function / 30:70 probabilites
# In sample x=c(0:1) represents a and A (30:70) alleles of a gene
for (i in 1:lineN) {
    Genes0[i, ] = sample(x=c(0:1), size=10, replace=T, prob=c(0.3,0.7)) 
}

generationN = 100
ParentGenes = Genes0
for (g in 1:generationN) {
  ChildGenes = array(NA, dim=c(lineN, 2*N))
  for (i in 1:lineN) {
    ChildGenes[i, ] = sample(ParentGenes[i, ], replace=T)
  }
}
  ParentGenes = ChildGenes
    table(ChildGenes)/(lineN*2*N) # Allele frequencies

    #Convert allele to genotypes: AA <=> 2; Aa / aA <=> 1; aa <=> 0.
    Genotypes = array(NA, dim=c(lineN, N))
    for  (j in 1:N) {
        Genotypes[, j] = ChildGenes[, 2*j-1] + ChildGenes[, 2*j]
    }
    table(Genotypes)/(lineN*N) # Genotype frequencies.
4

1 に答える 1