Skip to content

Instantly share code, notes, and snippets.

@explodecomputer
Created March 10, 2017 22:37
Show Gist options
  • Save explodecomputer/c0cb7411a6fdf0e59b8cb9b5dfdc77be to your computer and use it in GitHub Desktop.
Save explodecomputer/c0cb7411a6fdf0e59b8cb9b5dfdc77be to your computer and use it in GitHub Desktop.
genetic models of parent - offspring behaviour
n <- 10000
gm <- rbinom(n, 2, 0.5)
gp <- rbinom(n, 2, 0.5)
# approximate child genotypes
gc <- round((gm + gp) / 2)
cor(gm, gc)^2
cor(gp, gc)^2
# non-genetic
wp <- rnorm(n)
wm <- rnorm(n)
wc <- scale(wp + wm + rnorm(n))
summary(lm(wc ~ wp + wm))
# causal model
xp <- scale(gp + rnorm(n))
xm <- scale(gm + rnorm(n))
xc <- scale(xp + xm + rnorm(n))
xcr <- residuals(lm(xc ~ gc))
summary(lm(xc ~ xp + xm))
summary(lm(xcr ~ xp + xm))
summary(lm(xc ~ xp + xm + gp + gm))
summary(lm(xc ~ gp + gm))
# pleiotropic model
yp <- scale(gp + rnorm(n))
ym <- scale(gm + rnorm(n))
yc <- scale(gc + rnorm(n))
ycr <- residuals(lm(yc ~ gc))
summary(lm(yc ~ yp + ym))
summary(lm(ycr ~ yp + ym))
summary(lm(yc ~ yp + ym + gp + gm))
summary(lm(ycr ~ yp + ym + gp + gm))
summary(lm(yc ~ gp + gm))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment