Exemplo n.º 1
0
    def test_proper_initialise(self):
        """jackknife should initialise correctly"""
        # Scalar
        pmcc_stat = stat_maker(pmcc, data, 1)
        test_knife = JackknifeStats(data.shape[1], pmcc_stat)
        self.assertEqual(test_knife.n, data.shape[1])
        self.assertEqual(test_knife._jackknifed_stat, None)

        # Vector
        mean_stat = stat_maker(mean, data, 1)
        test_knife = JackknifeStats(data.shape[1], mean_stat)
        self.assertEqual(test_knife.n, data.shape[1])
        self.assertEqual(test_knife._jackknifed_stat, None)
Exemplo n.º 2
0
    def test_jackknife_stats(self):
        """jackknife results should match Sokal & Rolf example"""
        # Scalar
        pmcc_stat = stat_maker(pmcc, data, 1)
        test_knife = JackknifeStats(data.shape[1], pmcc_stat)
        assert_allclose(test_knife.jackknifed_stat, 1.2905845)
        assert_allclose(test_knife.standard_error, 0.2884490)
        self.assertTrue(test_knife._jackknifed_stat != None)

        # Vector
        mean_stat = stat_maker(mean, data, 1)
        test_knife = JackknifeStats(data.shape[1], mean_stat)
        expected_jk_stat = data.mean(axis=1)
        got_jk_stat = test_knife.jackknifed_stat
        expected_standard_err = [30.69509346, 1.87179671]
        got_standard_err = test_knife.standard_error

        for index in [0, 1]:
            assert_allclose(got_jk_stat[index], expected_jk_stat[index])
            assert_allclose(got_standard_err[index], expected_standard_err[index])
Exemplo n.º 3
0
 def test_tabular_properties(self):
     """constructs tabular properties"""
     pmcc_stat = stat_maker(pmcc, data, 1)
     test_knife = JackknifeStats(data.shape[1], pmcc_stat)
     ss = test_knife.sub_sample_stats
     self.assertEqual(ss.shape, (12, 2))
     ss = test_knife.sample_stat
     pvs = test_knife.pseudovalues
     self.assertEqual(pvs.shape, (12, 2))
     ss = test_knife.summary_stats
     self.assertEqual(ss.shape, (1, 3))
Exemplo n.º 4
0
    def test_jackknife_stats(self):
        """jackknife results should match Sokal & Rolf example"""
        # Scalar
        pmcc_stat = stat_maker(pmcc, data, 1)
        test_knife = JackknifeStats(data.shape[1], pmcc_stat)
        self.assertFloatEqual(test_knife.JackknifedStat, 1.2905845)
        self.assertFloatEqual(test_knife.Exception, 0.2884490)
        self.assertTrue(test_knife._jackknifed_stat is not None)

        # Vector
        mean_stat = stat_maker(mean, data, 1)
        test_knife = JackknifeStats(data.shape[1], mean_stat)
        expected_jk_stat = data.mean(axis=1)
        got_jk_stat = test_knife.JackknifedStat
        expected_standard_err = [30.69509346, 1.87179671]
        got_standard_err = test_knife.Exception

        for index in [0, 1]:
            self.assertFloatEqual(got_jk_stat[index], expected_jk_stat[index])
            self.assertFloatEqual(got_standard_err[index],
                                  expected_standard_err[index])
Exemplo n.º 5
0
    def test_tables(self):
        """jackknife should work for calculators return scalars or vectors"""
        # Scalar
        pmcc_stat = stat_maker(pmcc, data, 1)
        test_knife = JackknifeStats(data.shape[1], pmcc_stat)
        expected_subsample_stats = [
            1.4151,
            1.3946,
            1.4314,
            1.1889,
            1.1323,
            1.3083,
            1.3561,
            1.3453,
            1.2412,
            1.3216,
            1.2871,
            1.3664,
        ]
        expected_pseudovalues = [
            0.1968,
            0.4224,
            0.0176,
            2.6852,
            3.3084,
            1.3718,
            0.8461,
            0.9650,
            2.1103,
            1.2253,
            1.6049,
            0.7333,
        ]
        test_knife.jackknife()
        got_subsample_stats = test_knife._subset_statistics
        got_pseudovalues = test_knife._pseudovalues
        for index in range(data.shape[1]):
            np.testing.assert_almost_equal(
                got_subsample_stats[index], expected_subsample_stats[index], 4
            )
            np.testing.assert_approx_equal(
                got_pseudovalues[index], expected_pseudovalues[index], 4
            )

        # Vector
        mean_stat = stat_maker(mean, data, 1)
        test_knife = JackknifeStats(data.shape[1], mean_stat)

        test_knife.jackknife()
        expected_pseudovalues = data.transpose()
        expected_subsample_stats = [
            [198.9091, 11.8336],
            [197.0909, 11.7609],
            [204.2727, 12.1155],
            [209.2727, 12.9155],
            [178.4545, 11.0791],
            [192.4545, 11.7882],
            [204.2727, 13.0145],
            [184.2727, 11.7055],
            [206.0909, 12.7618],
            [193.3636, 11.7436],
            [184.2727, 11.5745],
            [194.2727, 12.2773],
        ]
        got_subsample_stats = test_knife._subset_statistics
        got_pseudovalues = test_knife._pseudovalues

        for index1 in range(data.shape[1]):
            for index2 in range(data.shape[0]):
                np.testing.assert_almost_equal(
                    got_subsample_stats[index1][index2],
                    expected_subsample_stats[index1][index2],
                    4,
                )
                np.testing.assert_almost_equal(
                    got_pseudovalues[index1][index2],
                    expected_pseudovalues[index1][index2],
                    4,
                )