LDAK can both add and subtract kinship matrices. The latter can be useful for Genomic Paritioning or Adaptive MultiBLUP; suppose that you wish to construct two kinship matrices, one corresponding to a region (subset of predictors) and one to the rest of the genome. Rather than calculate both from scratch, you can instead compute the regional kinship matrix, then obtain its complement by subtracting this from the genome-wide kinship matrix.

Ideally all kinship matrices involved have been derived from the same datafile, using the same predictor weightings and (subset of) samples.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

--add-grm <output> --mgrm <kinstems>

LDAK will add the kinship matrices specified in <kinstems> and save with stem <output>.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

There are three ways to subtract kinship matrices. The first takes the form

--sub-grm <output> --mgrm <kinstems>

Suppose <kinstems> provides the stems of K kinship matrices; LDAK will subtract kinship matrices 2, 3, ..., K from the first kinship matrix; the resulting kinship matrix will be saved with stem <output>. An alternative way to do this would be to first create a file called <predictors_to_exclude> which contains all the predictors used to create kinship matrices 2, 3, ..., K, then use the command

--sub-grm <output> --grm <kinfile> --exclude <predictors_to_exclude>

For this it is necessary to use --bfile/--gen/--sp/--speed <prefix> to provide the datafiles used to make the first kinship matrix. A third way to achieve the same is to create a file called <predictors_to_extract> which indicates which predictors used to make the first kinship matrix will remain after subtracting those used to make kinship matricse 2, 3, ..., K, then use the command

--sub-grm <output> --grm <kinfile> --extract <predictors_to_extract>

Again, it is necessary to use --bfile/--gen/--sp/--speed <prefix> to provide the datafiles used to make the first kinship matrix.

_ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

When a predictor is included in more than one kinship matrix, its mean and variance must be the same for all occurrences. If the original kinship matrices were not created from the same datafiles, you should use the option --same-data NO. If they were not created using LDAK, you will need to use --kinship-details NO (this is not possible when using --sub-grm with --exclude or --extract).

_ _ _ _ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Example: for this we use the files alist.txt and slist.txt in the Test Datasets, as well as the three kinship matrices computed for the example in Get Kinships.

The file alist.txt has three rows, which provide the stems of the three kinship matrices (partitions/kinships.1, partitions/kinships.2 and partitions/kinships.3). Running the command

../ldak.out --add-grm partitions/kinships.A --mgrm alist.txt

will merge the three kinship matrices together. The resulting kinship matrix, which has stem partitions/kinships.A, will be identical to the kinship matrix saved with stem partitions/kinships.all.

The file slist.txt also has three rows (partitions/kinships.A, partitions/kinship.1 and partitions/kinships.2). Running the command

../ldak.out --sub-grm partitions/kinships.B --mgrm slist.txt

will subtract the kinship matrices with stems partitions/kinships.1 and partitions/kinships.2 from the kinship matrix with stem partitions/kinships.A. The resulting kinship matrix, which has stem partitions/kinships.B will be identical to the kinship matrix saved with stem partitions/kinships.3. Note that this command would return an error if either of the kinship matrices with stems partitions/kinships.1 and partitions/kinships.2 contained predictors which were not present in the kinship matrix with stem partitions/kinships.A.

We could achieve the same using either

cat partitions/kinships.A.grm.detais,list1 list2 > list12

../ldak.out --sub-grm partitions/kinships.B --grm partitions/kinships.A --exclude list12 --bfile test

or

awk '(NR==FNR){arr[$1];next}!($1 in arr){print $1}' list12 partitions/kinships.A.grm.details | grep -v "Predictor" > listrest

../ldak.out --sub-grm partitions/kinships.B --grm partitions/kinships.A --extract listrest