## Population genetics course resources: Quantitative traits 2.

The second quantitative trait code post. The set up is the same as in the last QT post. I simulate parents with L genotypes drawn binomially from the population, and then make kids from these parents.

This one makes the parental mid-point vs child phenotype regression plot. You get to specify the number of loci (L) and environmental variance (environ.var), and genetic.var=1. The slope of the regression of child_pheno ~ (mum_pheno+dad_pheno)/2 is h^2, i.e. genetic.var/(environ.var+genetic.var). What I find really quite neat is how few loci you need for the h^2 regression to work.

Ideas for this year: Use height loci? Add in dominance and other relationships, or get the students to do this. They struggle to understand the dominance variance (and to be honest I always do too).

This slideshow requires JavaScript.

```

##Paste this in first
par.off.corr<-function(L=20, environ.var,print.slope=FALSE){
##Quantitative genetics sims
allele.freq<-0.5   ###each locus is assumed to have the same allele frequencies. This is just to simplify the coding, in reality these results work when each locus has its own frequency (and the coding wouldn't be too much harder).

Num_inds=1000

##MAKE A MUM
## For each mother, at each locus we draw an allele (either 0 or 1) from the population allele frequency.
##We do this twice for each mother two represent the two haplotypes in the mother
mum.hap.1<-replicate(Num_inds, rbinom(L,1,allele.freq) )
mum.hap.2<-replicate(Num_inds, rbinom(L,1,allele.freq) )
##type mum.hap.1[,1] to see the 1st mothers 1st haplotype

##Each mothers genotype at each locus is either 0,1,2
mum.geno<-mum.hap.1+mum.hap.2

mum.pheno<-mum.pheno-mean(mum.pheno)

##MAKE A DAD (same code as make a mum, only said in a deeper voice)

### Make a child

child.pheno<-child.pheno-mean(child.pheno)

##Calculate midpoints, linear model and plots

lm(child.pheno~parental.midpoint) ##linear model between child and mid point
##the slope of this line is the narrow sense heritability.

# plot parental midpoint against offsprings phenotype.
layout(1) ###done in case this is run after the code with 3 plots
plot(parental.midpoint,child.pheno,xlab="Parental midpoint",ylab="Child's phenotype",cex=1.5,main=paste("L =",L,"environ.var=",environ.var,"genetic.var=1"))
## plot the regression in red
abline(h=0,col="grey",lwd=2)
abline(v=0,col="grey",lwd=2)
abline(lm(child.pheno~parental.midpoint),col="red",lwd=2)

if(print.slope) text(x=-2,y=3,label=paste("slope= ",format(lm(child.pheno~parental.midpoint)\$coeff,digit=3)),col="red",lwd=4)

abline(0,1,col="blue",lwd=3)

}

for(environ.var in c(0.00001,0.5,1,2)){
png(file=paste("parent_offspring_regression_varg_1_vare_",format(environ.var,dig=1),".png",sep=""))
par.off.corr(L=200, environ.var=environ.var,print.slope=TRUE)
dev.off()
}

```
This entry was posted in popgen teaching, Programming exercises, teaching. Bookmark the permalink.