Ejemplo n.º 1
0
    def test_spearmanr2(self):
        # Test that _spearnmanr2 returns the same result that stats.spearmanr
        # would
        n, m = tuple(np.random.randint(2, 5, size=2))
        mean = np.random.uniform(-1, 1, size=m)
        cov = np.random.uniform(0, 1.0 / m, size=(m, m))
        cov = (cov + cov.T) / 2
        cov.flat[::m + 1] = 1.0
        X1 = np.random.multivariate_normal(mean, cov, size=n)
        X2 = np.random.multivariate_normal(mean, cov, size=n)
        expected = scipy.stats.spearmanr(X1, X2, axis=1)[0][:n, n:]
        np.testing.assert_almost_equal(_spearmanr2(X1, X2, axis=1),
                                       expected,
                                       decimal=9)

        expected = scipy.stats.spearmanr(X1, X2, axis=0)[0][:m, m:]
        np.testing.assert_almost_equal(_spearmanr2(X1, X2, axis=0),
                                       expected,
                                       decimal=9)
Ejemplo n.º 2
0
    def test_spearmanr2(self):
        # Test that _spearnmanr2 returns the same result that stats.spearmanr
        # would
        n, m = tuple(np.random.randint(2, 5, size=2))
        mean = np.random.uniform(-1, 1, size=m)
        cov = np.random.uniform(0, 1./m, size=(m, m))
        cov = (cov + cov.T) / 2
        cov.flat[::m + 1] = 1.0
        X1 = np.random.multivariate_normal(mean, cov, size=n)
        X2 = np.random.multivariate_normal(mean, cov, size=n)
        expected = scipy.stats.spearmanr(X1, X2, axis=1)[0][:n, n:]
        np.testing.assert_almost_equal(
            _spearmanr2(X1, X2, axis=1),
            expected,
            decimal=9
        )

        expected = scipy.stats.spearmanr(X1, X2, axis=0)[0][:m, m:]
        np.testing.assert_almost_equal(
            _spearmanr2(X1, X2, axis=0),
            expected,
            decimal=9,
        )