Esempio n. 1
0
    def test_t_two_sample_switch(self):
        """t_two_sample should call t_one_observation if 1 item in sample."""
        sample = np.array([4.02, 3.88, 3.34, 3.87, 3.18])
        x = np.array([3.02])
        np.testing.assert_allclose(t_two_sample(x, sample),
                                   (-1.5637254, 0.1929248))
        np.testing.assert_allclose(t_two_sample(sample, x),
                                   (1.5637254, 0.1929248))

        # can't do the test if both samples have single item
        self.assertEqual(t_two_sample(x, x), (None, None))

        # Test special case if t=0.
        np.testing.assert_allclose(t_two_sample([2], [1, 2, 3]), (0.0, 1.0))
        np.testing.assert_allclose(t_two_sample([1, 2, 3], [2]), (0.0, 1.0))
Esempio n. 2
0
    def test_t_two_sample_switch(self):
        """t_two_sample should call t_one_observation if 1 item in sample."""
        sample = np.array([4.02, 3.88, 3.34, 3.87, 3.18])
        x = np.array([3.02])
        np.testing.assert_allclose(t_two_sample(x, sample),
                                   (-1.5637254, 0.1929248))
        np.testing.assert_allclose(t_two_sample(sample, x),
                                   (1.5637254, 0.1929248))

        # can't do the test if both samples have single item
        self.assertEqual(t_two_sample(x, x), (None, None))

        # Test special case if t=0.
        np.testing.assert_allclose(t_two_sample([2], [1, 2, 3]), (0.0, 1.0))
        np.testing.assert_allclose(t_two_sample([1, 2, 3], [2]), (0.0, 1.0))
Esempio n. 3
0
 def test_t_two_sample(self):
     """t_two_sample should match example on p.225 of Sokal and Rohlf"""
     I = np.array([7.2, 7.1, 9.1, 7.2, 7.3, 7.2, 7.5])
     II = np.array([8.8, 7.5, 7.7, 7.6, 7.4, 6.7, 7.2])
     np.testing.assert_allclose(t_two_sample(I, II),
                                (-0.1184, 0.45385 * 2),
                                atol=10e-3)
Esempio n. 4
0
 def test_t_two_sample(self):
     """t_two_sample should match example on p.225 of Sokal and Rohlf"""
     I = np.array([7.2, 7.1, 9.1, 7.2, 7.3, 7.2, 7.5])
     II = np.array([8.8, 7.5, 7.7, 7.6, 7.4, 6.7, 7.2])
     np.testing.assert_allclose(t_two_sample(I, II),
                                (-0.1184, 0.45385 * 2),
                                atol=10e-3)
Esempio n. 5
0
    def test_t_two_sample_no_variance(self):
        """t_two_sample should properly handle lists that are invariant"""
        # By default should return (None, None) to mimic R's t.test.
        x = np.array([1, 1., 1])
        y = np.array([0, 0, 0.0])
        self.assertEqual(t_two_sample(x, x), (None, None))
        self.assertEqual(t_two_sample(x, y), (None, None))

        # Test none_on_zero_variance=False on various tail types. We use
        # self.assertEqual instead of assert_allclose because the latter
        # sees inf and -inf as being equal.

        # Two tailed: a < b
        self.assertEqual(t_two_sample(y, x, none_on_zero_variance=False),
                         (float('-inf'), 0.0))

        # Two tailed: a > b
        self.assertEqual(t_two_sample(x, y, none_on_zero_variance=False),
                         (float('inf'), 0.0))

        # One-tailed 'high': a < b
        self.assertEqual(t_two_sample(y, x, tails='high',
                                      none_on_zero_variance=False),
                         (float('-inf'), 1.0))

        # One-tailed 'high': a > b
        self.assertEqual(t_two_sample(x, y, tails='high',
                                      none_on_zero_variance=False),
                         (float('inf'), 0.0))

        # One-tailed 'low': a < b
        self.assertEqual(t_two_sample(y, x, tails='low',
                                      none_on_zero_variance=False),
                         (float('-inf'), 0.0))

        # One-tailed 'low': a > b
        self.assertEqual(t_two_sample(x, y, tails='low',
                                      none_on_zero_variance=False),
                         (float('inf'), 1.0))

        # Should still receive (None, None) if the lists have no variance and
        # have the same single value.
        self.assertEqual(t_two_sample(x, x, none_on_zero_variance=False),
                         (None, None))
        self.assertEqual(t_two_sample(x, [1, 1], none_on_zero_variance=False),
                         (None, None))
Esempio n. 6
0
    def test_t_two_sample_no_variance(self):
        """t_two_sample should properly handle lists that are invariant"""
        # By default should return (None, None) to mimic R's t.test.
        x = np.array([1, 1., 1])
        y = np.array([0, 0, 0.0])
        self.assertEqual(t_two_sample(x, x), (None, None))
        self.assertEqual(t_two_sample(x, y), (None, None))

        # Test none_on_zero_variance=False on various tail types. We use
        # self.assertEqual instead of assert_allclose because the latter
        # sees inf and -inf as being equal.

        # Two tailed: a < b
        self.assertEqual(t_two_sample(y, x, none_on_zero_variance=False),
                         (float('-inf'), 0.0))

        # Two tailed: a > b
        self.assertEqual(t_two_sample(x, y, none_on_zero_variance=False),
                         (float('inf'), 0.0))

        # One-tailed 'high': a < b
        self.assertEqual(t_two_sample(y, x, tails='high',
                                      none_on_zero_variance=False),
                         (float('-inf'), 1.0))

        # One-tailed 'high': a > b
        self.assertEqual(t_two_sample(x, y, tails='high',
                                      none_on_zero_variance=False),
                         (float('inf'), 0.0))

        # One-tailed 'low': a < b
        self.assertEqual(t_two_sample(y, x, tails='low',
                                      none_on_zero_variance=False),
                         (float('-inf'), 0.0))

        # One-tailed 'low': a > b
        self.assertEqual(t_two_sample(x, y, tails='low',
                                      none_on_zero_variance=False),
                         (float('inf'), 1.0))

        # Should still receive (None, None) if the lists have no variance and
        # have the same single value.
        self.assertEqual(t_two_sample(x, x, none_on_zero_variance=False),
                         (None, None))
        self.assertEqual(t_two_sample(x, [1, 1], none_on_zero_variance=False),
                         (None, None))