From 3c8f5224bd0a65333858806e2d85516bad588c8a Mon Sep 17 00:00:00 2001 From: Slobodan Ilic Date: Fri, 12 Jan 2018 09:27:18 +0100 Subject: [PATCH] Modify functionality for one case MR, in the style of NUM/DEN --- src/cr/cube/crunch_cube.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cr/cube/crunch_cube.py b/src/cr/cube/crunch_cube.py index d1525a083..5ae01114e 100644 --- a/src/cr/cube/crunch_cube.py +++ b/src/cr/cube/crunch_cube.py @@ -432,14 +432,12 @@ def _mr_proportions(self, axis, weighted): else: res = table[:, :, 0] / (table[:, :, 0] + table[:, :, 1]) elif self.dimensions[2].type == 'multiple_response': - # This is the case of CA x MR, should work fine, but please check - # slight mismatch between this and whaam - if axis == 1: - res = (table[:, :, :, 0] / - np.sum(table[:, :, :, 0], 1)) - else: - res = (table[:, :, :, 0] / - (table[:, :, :, 0] + table[:, :, :, 1])) + margin = ( + self.margin(axis=axis)[:, np.newaxis] + if axis == 1 else + self.margin(axis=0) + ) + return self.as_array() / margin return res[np.ix_(*valid_indices)]