Skip to content

Commit

Permalink
update tests with links to matching whaam/R ones
Browse files Browse the repository at this point in the history
  • Loading branch information
malecki committed Mar 13, 2018
1 parent fba09a6 commit 8749265
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 106 deletions.
162 changes: 57 additions & 105 deletions tests/integration/test_crunch_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,25 +715,29 @@ def test_calculate_standard_error_axis_0(self):
'''Calculate standard error across columns.'''
cube = CrunchCube(FIXT_ECON_GENDER_X_IDEOLOGY_WEIGHTED)
axis = 0
np.set_printoptions(precision=15, suppress=True)
print np.array_repr(cube.standardized_residuals, precision=15)

expected = np.array([
[
0.0556176,
0.0332214,
0.0202155,
0.0295626,
0.0430823,
0.0713761
-0.715899626017458,
-0.536708837208206,
-1.485149675785275,
1.114743776586886,
3.355236023985286,
-2.077040949965248
],
[
0.0556176,
0.0332214,
0.0202155,
0.0295626,
0.0430823,
0.0713761,
],
0.715899626017462,
0.536708837208211,
1.485149675785279,
-1.114743776586884,
-3.355236023985284,
2.07704094996525
]
])
actual = cube._calculate_standard_error(axis=axis)
actual = cube.standardized_residuals

np.testing.assert_almost_equal(actual, expected)

def test_pvals(self):
Expand Down Expand Up @@ -808,119 +812,67 @@ def test_z_scores_from_r_row_margin(self):
cube = CrunchCube(FIXT_MR_X_CAT_PROFILES_STATS_WEIGHTED)
expected = np.array([
[
-1.35700098973668,
3.39819222765456,
3.47632774910236,
1.39986424142017,
2.33910237706402,
-6.92590429515317,
-0.237453687452224,
0.736452470486666
],
[
1.3528312160513,
-3.38775031004662,
-3.4656457377556,
-1.39556275813377,
-2.33191481595459,
6.90462247318263,
0.236724043078395,
-0.734189509622821,
],
])
actual = cube.standardized_residuals
np.testing.assert_almost_equal(actual, expected)

def test_z_scores_from_r_col_margin(self):
cube = CrunchCube(FIXT_MR_X_CAT_PROFILES_STATS_WEIGHTED)
expected = np.array([
[
-1.33325107235154,
3.4170985193131,
3.56231261682056,
1.42672343792323,
2.41444184160409,
-6.85140362038577,
-0.220890470186746,
0.722988145330955,
-1.465585354569577,
3.704125875262655,
3.823689449491973,
1.53747452587281 ,
2.584734165643072,
-7.488143461076757,
-0.248968750486873,
0.794143540856786
],
[
1.33325107235152,
-3.41709851931311,
-3.56231261682057,
-1.42672343792324,
-2.41444184160409,
6.85140362038576,
0.220890470186742,
-0.72298814533095,
],
1.465585354569564,
-3.704125875262655,
-3.823689449491981,
-1.537474525872799,
-2.584734165643066,
7.488143461076757,
0.248968750486873,
-0.794143540856781
]
])
actual = cube.standardized_residuals
np.testing.assert_almost_equal(actual, expected)

def test_z_scores_admit_by_dept_unweighted_rows(self):
"""see
https://github.com/Crunch-io/whaam/blob/master/base/stats/tests/zvalues-spec.js#L42
"""
cube = CrunchCube(FIXT_ADMIT_X_DEPT_UNWEIGHTED)
expected = np.array([
[
17.3006739150679,
12.1555052876046,
-2.61883165552036,
-3.12585957287982,
-7.73178794867428,
-23.9433203846143,
18.04029230689576 ,
13.018394979149804,
-2.576739836814013,
-3.059526328377408,
-7.230244530709987,
-19.321410263144653
],
[
-17.2790610621901,
-12.1403200324679,
2.6155600821955,
3.12195459533981,
7.72212901884083,
23.9134092110139,
-18.040292306895765,
-13.018394979149804,
2.576739836814013,
3.059526328377408,
7.230244530709987,
19.321410263144653
]
])
actual = cube._calculate_statistics(axis=1)
np.testing.assert_almost_equal(actual, expected)

def test_z_scores_admit_by_dept_unweighted_cols(self):
cube = CrunchCube(FIXT_ADMIT_X_DEPT_UNWEIGHTED)
expected = np.array([
[
18.7216214725448,
13.3291986335621,
-2.67980030430232,
-3.19261047229265,
-8.09694682104735,
-32.0139892315214,
],
[
-18.7216214725448,
-13.3291986335621,
2.67980030430231,
3.19261047229265,
8.09694682104735,
32.0139892315214,
],
])
actual = cube._calculate_statistics(axis=0)
actual = cube.standardized_residuals
np.testing.assert_almost_equal(actual, expected)

def test_z_scores_admit_by_gender_weighted_rows(self):
""" see
https://github.com/Crunch-io/whaam/blob/master/base/stats/tests/zvalues-spec.js#L67
"""
cube = CrunchCube(FIXT_ADMIT_X_GENDER_WEIGHTED)
expected = np.array([
[9.80281743121017, -9.80281743121017],
[-9.71107624617507, 9.71107624617506],
[9.42561984520692 , -9.425619845206922],
[-9.425619845206922, 9.42561984520692 ]
])
actual = cube._calculate_statistics(axis=1)
actual = cube.standardized_residuals
np.testing.assert_almost_equal(actual, expected)

def test_z_scores_admit_by_gender_weighted_cols(self):
cube = CrunchCube(FIXT_ADMIT_X_GENDER_WEIGHTED)
expected = np.array([
[9.75089877074671, -9.72361434000118],
[-9.75089877074672, 9.72361434000117],
])
actual = cube._calculate_statistics(axis=0)
np.testing.assert_almost_equal(actual, expected)

def test_selected_crosstab_dim_names(self):
cube = CrunchCube(FIXT_SELECTED_CROSSTAB_4)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_headers_and_subtotals.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_subtotals_pvals_2d_cube_with_hs_on_row(self):
'''Ensure that pvals shape is the same as table shape with H%S'''
cube = CrunchCube(FIXT_ECON_BLAME_X_IDEOLOGY_ROW_HS)
expected = 6, 6
actual = cube.pvals(axis=0, include_transforms_for_dims=[0, 1]).shape
actual = cube.pvals(include_transforms_for_dims=[0, 1]).shape

# Only assert the shape of the table, as the pvals are going to be
# rewritten soon.
Expand Down

0 comments on commit 8749265

Please sign in to comment.