Data
library(BGLR)
data(mice)
W <- mice.X
dim(W)
[1] 1814 10346
p <- colSums(W)/(2 * nrow(W))
maf <- ifelse(p > 0.5, 1 - p, p) # or pmin(p, 1-p)
maf.index <- which(maf < 0.1)
p2 <- p[-maf.index]
W2 <- W[, -maf.index]
dim(W2)
[1] 1814 9340
VanRaden Method 1
W3 <- scale(W2, center = TRUE, scale = FALSE)
G1 <- tcrossprod(W3)/sum(2 * p2 * (1 - p2))
# Genomic relationship between individuals 1 and 5
G1[1, 5]
[1] 0.1230863
# Genomic relationship between individuals 1 and 10
G1[1, 10]
[1] 0.1968405
VanRaden Method 2
Wcs <- scale(W2, center = TRUE, scale = TRUE)
G2 <- tcrossprod(Wcs)/ncol(Wcs)
# Genomic relationship between individuals 1 and 5
G2[1, 5]
[1] 0.1002654
# Genomic relationship between individuals 1 and 10
G2[1, 10]
[1] 0.2014496
# Cor between G1 and G2
cor(G1[upper.tri(G1)], G2[upper.tri(G2)])
[1] 0.9958993