Skip to content

Commit

Permalink
[#177824342]: invert tstats mean sign calculation to respect the corr…
Browse files Browse the repository at this point in the history
…ect color shading in exporter
  • Loading branch information
ernestoarbitrio committed Apr 20, 2021
1 parent 714fd31 commit ea3a624
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/cr/cube/matrix/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def pairwise_indices(p_vals, t_stats):
"""1D ndarray of tuples of int pairwise indices of each column."""
significance = p_vals < alpha
if only_larger:
significance = np.logical_and(t_stats > 0, significance)
significance = np.logical_and(t_stats < 0, significance)
col_signif = np.empty((len(significance),), dtype=object)
col_signif[:] = [tuple(np.where(sig_row)[0]) for sig_row in significance]
return col_signif
Expand Down
2 changes: 1 addition & 1 deletion src/cr/cube/matrix/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def _t_stats(self):
t_stats.append(np.full(means.shape, np.nan))
else:
combined_variance = variance[:, col - offset] + variance.T
diff = means[:, col - offset] - means.T
diff = means.T - means[:, col - offset]
n = col_bases[:, col - offset] + col_bases.T
t_stats.append(diff.T * np.sqrt(n.T / combined_variance.T))
return t_stats
Expand Down
38 changes: 19 additions & 19 deletions tests/expectations/num-arr-means-grouped-by-cat-hs-t-stats-col-7.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
[
[
float("NaN"),
-1.70521377,
-2.07569522,
1.70521377,
2.07569522,
float("NaN"),
-1.70521377,
1.70521377,
float("NaN"),
-1.60530814,
0.0,
1.60530814,
-0.0,
float("NaN"),
],
[
float("NaN"),
1.29347475,
0.0,
-1.29347475,
-0.0,
float("NaN"),
1.4061553,
-1.4061553,
float("NaN"),
1.29347475,
-1.29347475,
float("NaN"),
float("NaN"),
],
[
float("NaN"),
0.58756965,
-4.18330013,
-0.58756965,
4.18330013,
float("NaN"),
0.27920779,
-0.27920779,
float("NaN"),
-4.11298756,
0.0,
4.11298756,
-0.0,
float("NaN"),
],
[
float("NaN"),
-1.32797346,
-0.6882472,
1.32797346,
0.6882472,
float("NaN"),
-1.32797346,
1.32797346,
float("NaN"),
-0.68972588,
0.0,
0.68972588,
-0.0,
float("NaN"),
],
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
[-1.70521377, -2.07569522, -1.70521377, -1.60530814, 0.0],
[1.29347475, 0.0, 1.4061553, 1.29347475, float("NaN")],
[0.58756965, -4.18330013, 0.27920779, -4.11298756, 0.0],
[-1.32797346, -0.6882472, -1.32797346, -0.68972588, 0.0],
[1.70521377, 2.07569522, 1.70521377, 1.60530814, -0.0],
[-1.29347475, -0.0, -1.4061553, -1.29347475, float("NaN")],
[-0.58756965, 4.18330013, -0.27920779, 4.11298756, -0.0],
[1.32797346, 0.6882472, 1.32797346, 0.68972588, -0.0],
]
17 changes: 8 additions & 9 deletions tests/integration/test_pairwise_significance.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,12 @@ def test_pairwise_significance_all_empty(self):
class TestMeanDifferenceSignificance(object):
def test_mean_diff_significance_for_numeric_array_grouped_by_cat(self):
slice_ = Cube(NA.NUM_ARR_MULTI_NUMERIC_MEASURES_GROUPED_BY_CAT).partitions[0]

assert slice_.pairwise_significance_means_t_stats(0) == pytest.approx(
np.array(
[
[0.0, 0.7482866, 4.61524529, 5.29463547],
[0.0, 4.64371041, 7.14738681, 3.67511747],
[0.0, -3.13387218, -6.35310465, -2.3932706],
[-0.0, -0.7482866, -4.61524529, -5.29463547],
[-0.0, -4.64371041, -7.14738681, -3.67511747],
[-0.0, 3.13387218, 6.35310465, 2.3932706],
]
)
)
Expand Down Expand Up @@ -732,10 +731,10 @@ def test_mean_diff_significance_for_numeric_array_x_mr(self):
assert slice_.pairwise_significance_means_t_stats(0) == pytest.approx(
np.array(
[
[0.0, -1.3056921, 1.1842639],
[0.0, -1.7117695, 1.6297401],
[-0.0, 1.3056921, -1.1842639],
[-0.0, 1.7117695, -1.6297401],
[np.nan, np.nan, np.nan],
[np.nan, 5.8872721, 4.4442801],
[np.nan, -5.8872721, -4.4442801],
]
),
nan_ok=True,
Expand Down Expand Up @@ -808,8 +807,8 @@ def test_mean_diff_significance_for_cat_x_cat(self):
np.array(
[
[np.nan, np.nan, np.nan, np.nan],
[-14.1421356, 0.0, -3.1066887, np.nan],
[-1.75662013, 0.0, np.nan, np.nan],
[14.1421356, -0.0, 3.1066887, np.nan],
[1.75662013, -0.0, np.nan, np.nan],
]
),
nan_ok=True,
Expand Down

0 comments on commit ea3a624

Please sign in to comment.