diff --git a/docs/python-api.md b/docs/python-api.md index ac53d3fce9..a8236daadf 100644 --- a/docs/python-api.md +++ b/docs/python-api.md @@ -321,6 +321,7 @@ Single site TreeSequence.Fst TreeSequence.genealogical_nearest_neighbours TreeSequence.genetic_relatedness + TreeSequence.genetic_relatedness_weighted TreeSequence.general_stat TreeSequence.segregating_sites TreeSequence.sample_count_stat diff --git a/docs/stats.md b/docs/stats.md index 222473b9de..c1a34f937d 100644 --- a/docs/stats.md +++ b/docs/stats.md @@ -71,6 +71,7 @@ appears beside the listed method. * Multi-way * {meth}`~TreeSequence.divergence` * {meth}`~TreeSequence.genetic_relatedness` + {meth}`~TreeSequence.genetic_relatedness_weighted` * {meth}`~TreeSequence.f4` {meth}`~TreeSequence.f3` {meth}`~TreeSequence.f2` @@ -590,6 +591,11 @@ and boolean expressions (e.g., {math}`(x > 0)`) are interpreted as 0/1. where {math}`m = \frac{1}{n}\sum_{k=1}^n x_k` with {math}`n` the total number of samples. +`genetic_relatedness_weighted` +: {math}`f(w_i, w_j, x_i, x_j) = \frac{1}{2}w_iw_j(x_i - m)(x_j - m)`, + + where {math}`m = \frac{1}{n}\sum_{k=1}^n x_k` with {math}`n` the total number + of samples. `Y2` : {math}`f(x_1, x_2) = \frac{x_1 (n_2 - x_2) (n_2 - x_2 - 1)}{n_1 n_2 (n_2 - 1)}` diff --git a/python/tskit/trees.py b/python/tskit/trees.py index 36fe147488..f80a245126 100644 --- a/python/tskit/trees.py +++ b/python/tskit/trees.py @@ -7705,11 +7705,14 @@ def genetic_relatedness_weighted( then the k-th column of output will be :math:`\sum_{a,b} W_{ai} W_{bj} C_{ab}`, where :math:`W` is the matrix of weights, and :math:`C_{ab}` is the - {meth}`.genetic_relatedness` between sample i and sample j. + :meth:`genetic_relatedness <.TreeSequence.genetic_relatedness>` between sample + a and sample b, summing over all pairs of samples in the tree sequence. :param numpy.ndarray W: An array of values with one row for each sample and one column for each set of weights. - :param list indexes: A list of 2-tuples, or None. + :param list indexes: A list of 2-tuples, or None (default). Note that if + indexes = None, then W must have exactly two columns and this is equivalent + to indexes = [(0,1)]. :param list windows: An increasing list of breakpoints between the windows to compute the statistic in. :param str mode: A string giving the "type" of the statistic to be computed