Skip to content

Commit

Permalink
Merge 7fc056e into f9b064f
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Apr 19, 2021
2 parents f9b064f + 7fc056e commit 97c5cd8
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 185 deletions.
23 changes: 13 additions & 10 deletions src/cr/cube/matrix/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def t_stats(self):
[
[
_PairwiseSignificaneBetweenSubvariablesHelper(
self._cube_measures.weighted_cube_counts.weighted_counts,
self._cube_measures.cube_overlaps.overlaps,
self._cube_measures.cube_overlaps.valid_overlaps,
row_idx,
Expand Down Expand Up @@ -567,6 +568,7 @@ def p_vals(self):
[
[
_PairwiseSignificaneBetweenSubvariablesHelper(
self._cube_measures.weighted_cube_counts.weighted_counts,
self._cube_measures.cube_overlaps.overlaps,
self._cube_measures.cube_overlaps.valid_overlaps,
row_idx,
Expand Down Expand Up @@ -1261,7 +1263,8 @@ def blocks(self):
class _PairwiseSignificaneBetweenSubvariablesHelper(object):
"""Helper for calculating overlaps significance between subvariables."""

def __init__(self, overlaps, valid_overlaps, row_idx, idx_a, idx_b):
def __init__(self, counts, overlaps, valid_overlaps, row_idx, idx_a, idx_b):
self._counts = counts
self._overlaps = overlaps
self._valid_overlaps = valid_overlaps
self._row_idx = row_idx
Expand Down Expand Up @@ -1312,15 +1315,15 @@ def _column_proportions(self):
the total of selected counts from that column (to which the cell belongs).
"""
# ---pa and pb are the selected counts of the
# ---cells at [row_idx, A], [row_idx, B],
pa = self._overlaps[self._row_idx, self._idx_a, self._idx_a]
pb = self._overlaps[self._row_idx, self._idx_b, self._idx_b]
# ---Sa and Sb are the totals of the selected
# ---counts from columns A and B.
Sa, Sb, _ = self._selected_counts
# ---pa/Sa and pb/Sb represent the column proportions of selected counts
return (pa / Sa, pb / Sb)
# ---pa and pb are the column percentages of weighted counts
# ---of the cells at positions [row_idx, A] and [row_idx, B]
pa = self._counts[self._row_idx, self._idx_a] / np.sum(
self._counts[:, self._idx_a], axis=0
)
pb = self._counts[self._row_idx, self._idx_b] / np.sum(
self._counts[:, self._idx_b], axis=0
)
return (pa, pb)

@lazyproperty
def _selected_counts(self):
Expand Down
104 changes: 52 additions & 52 deletions tests/fixtures/overlaps/cat-x-mr-gender-x-all-pets-owned.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,43 @@
]
}
],
"weight": null
"weight": "http://127.0.0.1:8080/datasets/2d72499978a24736b9018a096d13bd80/variables/e0afa901440841409aa7d73cc02831f9/"
},
"query_environment": {
"filter": []
},
"result": {
"dimensions": [
{
"derived": false,
"references": {
"alias": "Gender",
"name": "Gender",
"view": {
"show_numeric_values": false
}
},
"derived": false,
"type": {
"ordinal": false,
"class": "categorical",
"categories": [
{
"numeric_value": null,
"missing": false,
"id": 1,
"name": "Male",
"missing": false
"name": "Male"
},
{
"numeric_value": null,
"missing": false,
"id": 2,
"name": "Female",
"missing": false
"name": "Female"
},
{
"numeric_value": null,
"missing": true,
"id": -1,
"name": "No Data",
"missing": true
"name": "No Data"
}
]
}
Expand All @@ -80,6 +80,8 @@
"references": {
"alias": "allpets",
"uniform_basis": false,
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned",
"subreferences": [
{
"alias": "allpets_1",
Expand All @@ -93,9 +95,7 @@
"alias": "allpets_3",
"name": "Bird"
}
],
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned"
]
},
"derived": true,
"type": {
Expand Down Expand Up @@ -148,8 +148,6 @@
"references": {
"alias": "allpets",
"uniform_basis": false,
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned",
"subreferences": [
{
"alias": "allpets_1",
Expand All @@ -163,7 +161,9 @@
"alias": "allpets_3",
"name": "Bird"
}
]
],
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned"
},
"type": {
"ordinal": false,
Expand Down Expand Up @@ -201,40 +201,40 @@
"measures": {
"count": {
"data": [
6,
4,
10,
2,
6,
12,
6,
6,
8,
2,
4,
14,
8,
0,
12,
4,
6,
10,
0,
0,
0,
0,
0,
0,
0,
0,
0
4.8,
3.2,
8.0,
1.6,
4.8,
9.6,
4.8,
4.8,
6.4,
2.4,
4.8,
16.8,
9.6,
0.0,
14.4,
4.8,
7.2,
12.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
],
"n_missing": 6,
"metadata": {
"references": {},
"derived": true,
"type": {
"integer": true,
"integer": false,
"missing_rules": {},
"missing_reasons": {
"No Data": -1
Expand Down Expand Up @@ -332,6 +332,8 @@
"references": {
"alias": "allpets",
"uniform_basis": false,
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned",
"subreferences": [
{
"alias": "allpets_1",
Expand All @@ -345,9 +347,7 @@
"alias": "allpets_3",
"name": "Bird"
}
],
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned"
]
},
"derived": true,
"type": {
Expand Down Expand Up @@ -454,6 +454,8 @@
"references": {
"alias": "allpets",
"uniform_basis": false,
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned",
"subreferences": [
{
"alias": "allpets_1",
Expand All @@ -467,9 +469,7 @@
"alias": "allpets_3",
"name": "Bird"
}
],
"description": "Do you have any of these animals as pets? Please select all that apply.",
"name": "All pets owned"
]
},
"derived": true,
"type": {
Expand Down Expand Up @@ -497,7 +497,7 @@
"missing": 0
},
"weighted": {
"selected": 40,
"selected": 40.0,
"other": 0,
"missing": 0
}
Expand All @@ -509,19 +509,19 @@
"missing": 0
},
"weighted": {
"selected": 40,
"selected": 40.0,
"other": 0,
"missing": 0
}
}
},
"unfiltered": {
"unweighted_n": 40,
"weighted_n": 40
"weighted_n": 40.0
},
"filtered": {
"unweighted_n": 40,
"weighted_n": 40
"weighted_n": 40.0
},
"counts": [
6,
Expand Down
98 changes: 0 additions & 98 deletions tests/fixtures/overlaps/mr-x-mr.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,104 +324,6 @@
],
"missing": 0,
"measures": {
"count": {
"data": [
3,
0,
0,
2,
1,
0,
0,
3,
0,
0,
2,
0,
1,
1,
0,
0,
2,
0,
0,
0,
1,
1,
0,
0,
0,
1,
0,
2,
1,
1,
4,
0,
0,
0,
4,
0,
1,
1,
0,
0,
2,
0,
0,
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
3,
2,
1,
4,
2,
0,
0,
6,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"n_missing": 0,
"metadata": {
"references": {},
"derived": true,
"type": {
"integer": true,
"missing_rules": {},
"missing_reasons": {
"No Data": -1
},
"class": "numeric"
}
}
},
"valid_overlap": {
"data": [
3,
Expand Down
Loading

0 comments on commit 97c5cd8

Please sign in to comment.