Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Created August 26, 2015 21:57
Show Gist options
  • Save explodecomputer/15e49b9be99cf7640988 to your computer and use it in GitHub Desktop.
Save explodecomputer/15e49b9be99cf7640988 to your computer and use it in GitHub Desktop.
Bivariate heritability greater than 1
n <- 1000
# cor_g and cor_e both positive
g <- rnorm(n)
e <- rnorm(n) * 0.5
g1 <- g + rnorm(n)
g2 <- g + rnorm(n)
cor(g1,g2)
e1 <- e + rnorm(n)
e2 <- e + rnorm(n)
cor(e1,e2)
y1 <- g1 + e1
y2 <- g2 + e2
cor(y1,y2)
cor(g1, g2) * cor(g1, y1) * cor(g2, y2) / cor(y1,y2)
# cor_g positive, cor_e negative
g <- rnorm(n)
e <- rnorm(n) * 0.5
g1 <- g + rnorm(n)
g2 <- g + rnorm(n)
cor(g1,g2)
e1 <- -e + rnorm(n)
e2 <- e + rnorm(n)
cor(e1,e2)
y1 <- g1 + e1
y2 <- g2 + e2
cor(y1,y2)
cor(g1, g2) * cor(g1, y1) * cor(g2, y2) / cor(y1,y2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment