def test_hommola_vs_mantel(self): # we don't compare p-values because the two methods use different # permutation strategies r_mantel, p_mantel, _ = mantel(self.hdist, self.pdist, method="pearson", permutations=0, alternative="greater") r_hommola, p_hommola, _ = hommola_cospeciation(self.hdist, self.pdist, self.interact_1to1, permutations=0) self.assertAlmostEqual(r_hommola, r_mantel) npt.assert_equal(p_hommola, p_mantel)
def test_zero_permutations(self): obs_r, obs_p, obs_perm_stats = hommola_cospeciation(self.hdist, self.pdist, self.interact, 0) exp_p = np.nan exp_r = 0.83170965463247915 exp_perm_stats = np.array([]) npt.assert_equal(obs_p, exp_p) self.assertAlmostEqual(obs_r, exp_r) npt.assert_equal(obs_perm_stats, exp_perm_stats)
def test_hommola_cospeciation_sig(self): np.random.seed(1) obs_r, obs_p, obs_perm_stats = hommola_cospeciation(self.hdist, self.pdist, self.interact, 9) exp_p = 0.1 exp_r = 0.83170965463247915 exp_perm_stats = np.array( [-0.14928122, 0.26299538, -0.21125858, 0.24143838, 0.61557855, -0.24258293, 0.09885203, 0.02858, 0.42742399] ) self.assertAlmostEqual(obs_p, exp_p) self.assertAlmostEqual(obs_r, exp_r) npt.assert_allclose(obs_perm_stats, exp_perm_stats)
def test_hommola_cospeciation_no_sig(self): np.random.seed(1) obs_r, obs_p, obs_perm_stats = hommola_cospeciation( self.hdist, self.pdist, self.interact_ns, 9) exp_p = .6 exp_r = -0.013679391379114569 exp_perm_stats = np.array([-0.22216543, -0.14836061, -0.04434843, 0.1478281, -0.29105645, 0.56395839, 0.47304992, 0.79125657, 0.06804138]) self.assertAlmostEqual(obs_p, exp_p) self.assertAlmostEqual(obs_r, exp_r) npt.assert_allclose(obs_perm_stats, exp_perm_stats)
def test_hommola_vs_mantel(self): # we don't compare p-values because the two methods use different # permutation strategies r_mantel, p_mantel, _ = mantel(self.hdist, self.pdist, method='pearson', permutations=0, alternative='greater') r_hommola, p_hommola, _ = hommola_cospeciation(self.hdist, self.pdist, self.interact_1to1, permutations=0) self.assertAlmostEqual(r_hommola, r_mantel) npt.assert_equal(p_hommola, p_mantel)
def test_hommola_cospeciation_asymmetric(self): np.random.seed(1) obs_r, obs_p, obs_perm_stats = hommola_cospeciation( self.hdist_4x4, self.pdist, self.interact_5x4, 9) exp_p = 0.2 exp_r = 0.85732140997411233 exp_perm_stats = np.array([-0.315244162496, -0.039405520312, 0.093429386594, -0.387835875941, 0.183711730709, 0.056057631956, 0.945732487487, 0.056057631956, -0.020412414523]) self.assertAlmostEqual(obs_p, exp_p) self.assertAlmostEqual(obs_r, exp_r) npt.assert_allclose(obs_perm_stats, exp_perm_stats)
def test_permutations_too_few(self): with self.assertRaises(ValueError): hommola_cospeciation(self.h_dist_3x3, self.p_dist_3x3, self.interact_3x3, -1)
def test_par_interaction_not_equal(self): with self.assertRaises(ValueError): hommola_cospeciation(self.h_dist_3x3, self.p_dist_3x3, self.interact_3x2)
def test_dm_too_small(self): with self.assertRaises(ValueError): hommola_cospeciation(self.h_dist_2x2, self.p_dist_3x3, self.interact_3x3)