Linkage disequilibrium
Mice data
library(BGLR)
data(mice)
W <- mice.X[, 1:10]
genetics package
We will compute \(r^2\) of Hill and Robertson (1968) using the genetics package.
Approach 1
library(genetics)
G <- makeGenotypes(W, convert = c(colnames(W)), method = as.genotype.allele.count)
r2_1 <- LD(G)
r2_1$r^2
Approach 2
m <- ncol(W)
r2_2 <- matrix(0, nrow=m, ncol=m)
colnames(r2_2) <- rownames(r2_2) <- colnames(W)
for (i in 1:(m-1)) {
for (j in (i+1):m) {
g1 <- W[,i]
g2 <- W[,j]
g1[g1==0] <- "A/A"
g1[g1==1] <- "A/T"
g1[g1==2] <- "T/T"
g1 <- genotype(g1)
g2[g2==0] <- "G/G"
g2[g2==1] <- "G/C"
g2[g2==2] <- "C/C"
g2 <- genotype(g2)
ldobj <- LD(g1, g2)
r2_2[i,j] <- r2_2[j,i] <- ldobj$r^2
}
}
r2_2