tskit: Sample_sets incorrect in genetic_relatedness_matrix

In #2823 we added support for the genetic_relatedness_matrix function as a follow-up usage of divergence_matrix using sample sets. This doesn’t work when the sample_sets have a length > 1. It’s not clear what the problem is, but it’s something to do with the conversion of the divergence matrix into the GRM via the normalisation function (currently kludged to observationally work with single-sample sets)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I don’t really have an opinion on how the stat should be defined, but I think it’s fine to change change older definitions if we like - they haven’t been around for that long, and I doubt many people are using them.

Okay - the behavior observed above is expected, since recall that diversity and divergence are defined “without replacement”, e.g. (docs for diversity)

Mean pairwise genetic diversity: the average over all n choose 2 pairs of sample nodes, of the density of sites at which the two carry different alleles, per unit of chromosome length.

and also (docstring for divergence_matrix)

    #    Finds the mean divergence  between pairs of samples from each set of
    #     samples and in each window. Returns a numpy array indexed by (window,
    #     sample_set, sample_set).  Diagonal entries are corrected so that the
    #     value gives the mean divergence for *distinct* samples, but it is not
    #     checked whether the sample_sets are disjoint (so offdiagonals are not
    #     corrected).

So, the diagonal of D_i_alt as computed above should be multiplied by 2 since it’s diploids; more generally the ith diagonal it should be multiplied by n[i]/(n[i]-1) if n[i] is the size of the ith sample set.

I’ll figure out what’s going on in the code and tidy things up.