# Heritability from Random Regression models

## heritability

• ASReml does not have a built in procedure to calculate the heritability at a particular AGE based on a random regression model. You will need to do it manually using a matrix manpulation program (such as R).
• If you have only only 5 ages, you should use an unstructered model rather than a quartic random regression. It will give the variances directly.
• To calculate the genetic variance under the random regression model, you need to identify the pol() coefficients used by ASReml (they are reported in the .res file) for the particular age of interest.

Then use these to pre and post multiply the variance matrix.
``` polcoeff <- c(1.000, .125, .325, .425) # values from .res file
rrmat <- matrix(c(
7.695   ,   0.2049 ,    -0.7956 ,     0.7513,
0.9376   ,    2.721 ,     0.3095 ,    -0.3744,
-3.456   ,   0.7996 ,      2.453 ,    -0.7301,
3.042   ,  -0.9014 ,     -1.669 ,      2.131 ),4,4)
# values from .asr file (but Upper is correlation)

rrmat[lower.tri(rrmat)]<- 0
rrmat <- rrmat+t(rrmat)-diag(diag(rrmat))
rrmat

[1,]  7.6950  0.9376 -3.4560  3.0420
[2,]  0.9376  2.7210  0.7996 -0.9014
[3,] -3.4560  0.7996  2.4530 -1.6690
[4,]  3.0420 -0.9014 -1.6690  2.1310
>

t(polcoeff) %*% rrmat %*% polcoeff
[,1]
[1,] 8.463358
```
Thus you have the genetic variance for the age corresponding to the coefficients used. Then proceed with the heritability depending on the structure of the rest of the model.