Skip to content

Commit

Permalink
Add Manova unit tests and fix other unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tpsatish95 committed Mar 25, 2019
1 parent c9ce9db commit 0c97d6a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.3.0] - 2019-02-07
- Refactor the mgcpy package structure
- Add Manova
- Fix two sample tests
- Add scripts for k sample test power curves
- Update sphinx docs
Expand Down
9 changes: 1 addition & 8 deletions mgcpy/benchmarks/unit_tests/power_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import pickle

import h5py
import numpy as np
import pytest
from mgcpy.benchmarks.power import power, power_given_data
from mgcpy.benchmarks.simulations import (circle_sim, joint_sim,
multi_indep_sim, multi_noise_sim,
sin_sim, square_sim, ubern_sim,
w_sim)
from mgcpy.benchmarks.simulations import joint_sim
from mgcpy.independence_tests.dcorr import DCorr
from mgcpy.independence_tests.rv_corr import RVCorr
from scipy.spatial.distance import pdist, squareform


def test_power():
Expand Down
4 changes: 2 additions & 2 deletions mgcpy/hypothesis_tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_k_sample():

# k sample case
salaries = salary_data["Current Annual Salary"].values
department_labels = salary_data["Department"].values
department_labels = salary_data["Department"].values.reshape(-1, 1)
u, v = k_sample_transform(salaries[:100], department_labels[:100], is_y_categorical=True)
mgc = MGC()
p_value, p_value_metadata = mgc.p_value(u, v)
Expand All @@ -43,7 +43,7 @@ def test_k_sample():
0.22417797, 0.45241074, -1.03024521, 0.6615743, 0.27216365, 2.4188678, 0.20561134, 0.71095061, -1.02478312, 0.54512964,
0.16582386, -0.39648338, -0.77905918, -0.33196771, 0.69407125, -0.81484451, 3.01568098, -0.49053868, -0.60987204, 1.72967348])
# assign half of them as samples from 1 and the other half as samples from 2
y = np.concatenate([np.repeat(1, 50), np.repeat(2, 50)], axis=0)
y = np.concatenate([np.repeat(1, 50), np.repeat(2, 50)], axis=0).reshape(-1, 1)

u, v = k_sample_transform(x, y, is_y_categorical=True)
mgc = MGC()
Expand Down
22 changes: 22 additions & 0 deletions mgcpy/independence_tests/unit_tests/manova_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np
import pytest
from mgcpy.independence_tests.manova import Manova
from mgcpy.benchmarks.hypothesis_tests.three_sample_test.power import generate_three_two_d_gaussians
from mgcpy.hypothesis_tests.transforms import k_sample_transform


def test_local_corr():
np.random.seed(0)
matrix_X, matrix_Y, matrix_Z = generate_three_two_d_gaussians(2, 100, 3)

data = np.concatenate([matrix_X, matrix_Y, matrix_Z], axis=0)
labels = np.concatenate([np.repeat(1, matrix_X.shape[0]), np.repeat(2, matrix_Y.shape[0]), np.repeat(3, matrix_Z.shape[0])], axis=0).reshape(-1, 1)

matrix_U, matrix_V = k_sample_transform(data, labels, is_y_categorical=True)

# Against linear simulations
manova = Manova()
test_stat = manova.test_statistic(matrix_U, matrix_V)[0]

assert manova.get_name() == 'manova'
assert np.allclose(test_stat, 0.06, atol=1.e-2)

0 comments on commit 0c97d6a

Please sign in to comment.