Created
February 9, 2015 18:04
-
-
Save explodecomputer/67af81899dfe8d9b2d4a to your computer and use it in GitHub Desktop.
Simulate GRM for small number of SNPs with mother children pairs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nsnp <- 48 | |
n <- 1000 | |
mothers1 <- matrix(rbinom(n*nsnp*2, 1, 0.5), n) | |
kids1 <- matrix(rbinom(n*nsnp, 1, 0.5), n) | |
kids2 <- mothers1[, seq(1, 2*nsnp, 2)] | |
kids <- kids1 + kids2 | |
mothers <- matrix(0, n, nsnp) | |
for(i in 1:nsnp) | |
{ | |
mothers[,i] <- mothers1[,(i-1)*2 + 1] + mothers1[,i*2] | |
} | |
for(i in 1:10) print(cor(mothers[i,], kids[i,])) | |
X <- scale(rbind(mothers, kids)) | |
grm <- X %*% t(X) / nsnp / 2 | |
hist(grm[grm > 0.25], breaks=100) | |
hist(grm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment