# Heritability calculations

## Introduction

ASReml includes a post-analysis procedure to calculate functions of variance components. Its intended use is when the variance components are either simple variances or are variances and covariances in an unstructured matrix. The functions covered are linear combinations of the variance components (for example, phenotypic variance), a ratio of two components (for example, heritabilities) and the correlation based on three components (for example, genetic correlation). The user must prepare a .pin file. For example
``` F phenvar 1 + 2 # pheno  var
F genvar 1 * 4  # geno var
H herit 4 3     # heritability
```
The .pin file specifies the functions to be calculated. The user re-runs ASReml with the -P command line option specifying the .pin file as the input file. ASReml reads the model information from the .asr and .vvp files and calculates the requested functions. These are reported in the .pvc file.

## Syntax

Three operations are defined, indicated by the first letter of each line
• F calculates a linear function of the variance parameters,
• H calculates a ratio of two variances,
• R calculates a correlation.

Functions of the variance components are specified in the .pin file in lines of the form
letter label coefficients
• letter (either F, H or R ) must occur in column 1
• label names the result,
• coefficients is the list of coefficients for the linear function.

#### Linear combinations of components

First ASReml extracts the variance components from the .asr file and their variance matrix from the .vvp file. Each linear function formed by an F line is added to the list of components. Thus, the number of coefficients increases by one each F line.

We seek to calculate k + c'v, cov(c'v, v) and var(c'v) where v is the vector of existing variance components, c is the vector of coefficients for the linear function and k is an optional offset which is usually omitted but would be 1 to represent the residual variance in a probit analysis and 3.289 to represent the residual variance in a logit analysis. The general form of the directive is

F label a + b*cbc+d+m*k
where a, b, c and d are subscripts to existing components va vb vcand vdand cb/var> is a multiplier for vb/var>. m is a number bigger than the current length of v to flag the special case of adding the offset k. Where matrices are to be combined the form
F label a:b * k + c:d
can be used, as in the Coopworth data example, see UserGuide.

For example, after fitting a model like
ywt ~ mu sex age !r sire
ASReml will have estimated two variance components, Sire and Residual respectively. To calculate heritability, the .pin file is
``` F phenvar 1 + 2 # pheno var
F genvar 1 * 4  # geno var
H herit 4 3     # heritability
```
F phenvar 1 + 2 gives a third component which is the sum of the variance components, that is, the phenotypic variance, and
F genvar 1 * 4 gives a fourth component which is the sire variance component multiplied by 4, that is, the genotypic variance.

#### Heritability

Heritabilities are requested by lines in the .pin file beginning with an H. The specific form of the directive in this case is
H label n d
This calculates vnvd and its standard error where n and d are integers pointing to the variance components to be used as the numerator and denominator respectively in the heritability calculation.

In the example above
H herit 4 3
calculates the heritability as the ratio of component 4 (from second line of .pin) to component 3 (from first line of .pin), that is, genetic variance / phenotypic variance.

#### Correlation

Correlations are requested by lines in the .pin file beginning with an R. The specific form of the directive is
R label a ab b
This calculates the correlation r = va/sqrt(vavb and the associated standard error. a, b and ab are integers indicating the position of the components to be used.

Alternatively,
R label a:n
calculates all the correlations in the lower triangular row-wise matrix represented by components a to n and the associated standard errors.
For example, after fitting a trivariate sire model gfw fd lwt ~ Trait Tr.sex !r Tr.sire, the Residual matrix is in positions 1:6 and the Sire matrix is in positions 7:12. A .pin file is
``` F phenvar 1:6 + 7:12  # defines 13:18
F addvar 7:12*4       # defines 19:24
H heritgfw 19 13
H heritfd  21 15
H heritlwt 24 18
R phencorrAB 13 14 15
R phencorrAC 13 16 18
R phencorrBC 15 17 18
R gencorr 7:12
```
In the example
R phencorrAB 13 14 15
calculates the phenotypic correlation for the first two traits from components 13, 14 and 15, and
R gencorr 7:12
calculates the set of three genetic correlations.

## Another example

This example relates to the bivariate sire model in bsiremod.as:
``` Bivariate sire model
sire !I
ywt fat
bsiremod.asd
ywt fat ~ Trait !r Trait.sire
1 2 1
0 # ASReml will count units
Trait 0 US
3*0
Trait.sire
2
Trait 0 US
3*0
sire
```
which estimates six variance components
``` Source            Model  terms     Gamma     Component    Comp/SE   % C
Residual        UnStruct     1   26.2197       26.2197      18.01   0 U
Residual        UnStruct     1   2.85090       2.85090       9.55   0 U
Residual        UnStruct     2   1.71556       1.71556      18.00   0 U
Tr.sire         UnStruct     1   16.5262       16.5262       2.69   0 U
Tr.sire         UnStruct     1   1.14422       1.14422       1.94   0 U
Tr.sire         UnStruct     2  0.132847      0.132847       1.88   0 U
```
A .pin file to calculate heritabilities and correlations is
``` F phenvar 1:3 + 4:6
H heritA 10 7
H heritB 12 9
R phencorr 7 8 9
R gencorr 4:6
```
Labelling the initial six components
 V1 error variance for ywt V2 error covariance for ywt and fat V3 error variance for fat V4 sire variance component for ywt V5 sire covariance for ywt and fat V6 sire variance for fat
F phenvar 1:3 + 4:6 calculates
 V7 phenotypic variance for ywt V8 phenotypic covariance for ywt and fat V9 phenotypic variance for fat
F addvar 4:6 * 4 calculates
 V10 additive genetic variance for ywt V11 additive genetic covariance for ywt and fat V12 additive genetic variance for fat
H heritA 10 7 calculates the heritabilty for ywt
H heritB 12 9 calculates the heritabilty for fat
R phencorr 7 8 9 calculates the phenotypic correlation
R gencorr 4:6 calculates the genetic correlation

The result is:
```   7 phenvar  1     42.75       6.297
8 phenvar  2     3.995      0.6761
9 phenvar  3     1.848      0.1183