The numpy docs say the following about the ma.cov function:
allow_maskedbool, optional
If
True, masked values are propagated pair-wise: if a value is masked in x, the corresponding value is masked in y.
I was wondering if you can get it to work both ways (i.e. if a value is masked in y, the corresponding value is masked in x.)
I have a two-dimensional numpy array containing allele frequencies for a set of loci in multiple populations (initialised as site_freq = np.zeros((num_loci, num_pops), dtype=np.float64))
I want to compute variance of allele frequencies within populations (only using loci where frequency is > 0) and covariance of allele frequencies between populations (only using loci where the allele is segregating in both populations).
masked_freq=ma.masked_equal(site_freq, 0.0)
ma.var(masked_freq, axis=0)
seems to work ok, but
ma.cov(masked_freq, rowvar=False, allow_masked=True)
I am not so sure about. If for one population (call it x) a locus is not masked and is included in the variance calculation, how can I be sure the locus will not be included in the covariance calculation if it is masked in the other population (call it y).