## --- Example 1 from Percy and Kinghorn (2005) ---
## No. alleles: 2
## No. individuals: 1
## Individual genotype probabilities:
## Pr(11, 12, 22) = (.1, .5, .4)
##
## Hardy-Weinberg probabilities:
## Pr(1, 2) = (.75, .25)
## Pr(11, 12, (.75^2, 2*.75*.25,
## 22) = .25^2)
## = (.5625, .3750,
## .0625)
gp <- c(.1, .5)
hwp <- c(.5625, .3750)
gpi(gp=gp, hwp=hwp)
## --- Example 1 from Percy and Kinghorn (2005) extended ---
## No. alleles: 2
## No. individuals: 2
## Individual genotype probabilities:
## Pr_1(11, 12, 22) = (.1, .5, .4)
## Pr_2(11, 12, 22) = (.2, .5, .3)
(gp <- matrix(c(.1, .5, .2, .5), nrow=2, ncol=2, byrow=TRUE))
gpi(gp=gp, hwp=hwp)
## --- Example 2 from Percy and Kinghorn (2005) ---
## No. alleles: 3
## No. individuals: 1
## Individual genotype probabilities:
## Pr(11, 12, 13, (.1, .5, .0,
## 22, 23 = .4, .0,
## 33) .0)
##
## Hardy-Weinberg probabilities:
## Pr(1, 2, 3) = (.75, .25, .0)
## Pr(11, 12, 13, (.75^2, 2*.75*.25, .0,
## 22, 23, = 0.25^2, .0,
## 33) .0)
## = (.5625, .3750, .0
## .0625, .0,
## .0)
gp <- c(.1, .5, .0, .4, .0)
hwp <- c(.5625, .3750, .0, .0625, .0)
gpi(gp=gp, hwp=hwp)
## --- Example 3 from Percy and Kinghorn (2005) ---
## No. alleles: 5
## No. individuals: 1
## Hardy-Weinberg probabilities:
## Pr(1, 2, 3, 4, 5) = (.2, .2, .2, .2, .2)
## Pr(11, 12, 13, ...) = (Pr(1)^2, 2*Pr(1)+Pr(2), 2*Pr(1)*Pr(3), ...)
##
## Individual genotype probabilities:
## Pr(11, 12, 13, ...) = gp / 2
## Pr(12) = Pr(12) + .5
(hwp <- rep(.2, times=5) %*% t(rep(.2, times=5)))
hwp <- c(hwp[upper.tri(hwp, diag=TRUE)])
(hwp <- hwp[1:(length(hwp) - 1)])
gp <- hwp / 2
gp[2] <- gp[2] + .5
gp
gpi(gp=gp, hwp=hwp)
## --- Simulate gp for n alleles and i individuals ---
n <- 3
i <- 10
kAll <- (n*(n+1)/2) # without -1 here!
k <- kAll - 1
if(require("gtools")) {
gp <- rdirichlet(n=i, alpha=rep(x=1, times=kAll))[, 1:k]
hwp <- as.vector(rdirichlet(n=1, alpha=rep(x=1, times=kAll)))[1:k]
gpi(gp=gp, hwp=hwp)
}
Run the code above in your browser using DataLab