diff options
author | Frederick Muriuki Muriithi | 2021-11-09 10:16:50 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-11-09 10:16:50 +0300 |
commit | 89691df0d7ba096fb7a154aca3adf40f8dfaa8ae (patch) | |
tree | 8a6541abc927d554b6b57c1634763687d136db42 /gn3 | |
parent | b38be1a60ea04e3087d36ff68e7b047922295d4e (diff) | |
download | genenetwork3-89691df0d7ba096fb7a154aca3adf40f8dfaa8ae.tar.gz |
Implement remaining part of `partial_correlation_recursive` function
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi
* gn3/computations/partial_correlations.py: implement remaining portion of
`partial_correlation_recursive` function.
* tests/unit/computations/test_partial_correlations.py: add parsing for new
data format and update tests
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/computations/partial_correlations.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index 9d73197..07a67be 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -332,4 +332,29 @@ def partial_correlation_recursive( (corrs["rxy"] - corrs["rxz"] * corrs["ryz"]) / (math.sqrt(1 - corrs["rxz"]**2) * math.sqrt(1 - corrs["ryz"]**2))), ROUND_TO) - return round(0, ROUND_TO) + + remaining_cols = [ + colname for colname, series in data.items() + if colname not in ("x", "y", "z0") + ] + + new_xdata = tuple(data["x"]) + new_ydata = tuple(data["y"]) + zc = tuple( + tuple(row_series[1]) + for row_series in data[remaining_cols].iterrows()) + + rxy_zc = partial_correlation_recursive( + new_xdata, new_ydata, zc, method=method, + omit_nones=omit_nones) + rxz0_zc = partial_correlation_recursive( + new_xdata, tuple(data["z0"]), zc, method=method, + omit_nones=omit_nones) + ryz0_zc = partial_correlation_recursive( + new_ydata, tuple(data["z0"]), zc, method=method, + omit_nones=omit_nones) + + return round( + ((rxy_zc - rxz0_zc * ryz0_zc) /( + math.sqrt(1 - rxz0_zc**2) * math.sqrt(1 - ryz0_zc**2))), + ROUND_TO) |