コード例 #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)
コード例 #2
0
def plot_sample(plot,
                coll,
                calc_stat,
                x,
                title,
                xlabel,
                ylabel,
                color,
                label,
                stderr=False):
    if stderr:
        print '\tJackknifing the statistic and standard error'
        jk = JackknifeStats(coll.N, calc_stat)
        y = jk.JackknifedStat
        stderr = jk.StandardError
    else:
        stderr = None
        y = calc_stat(range(coll.N))
    plot(x,
         y=y,
         color=color,
         label=label,
         stderr=stderr,
         ylabel=ylabel,
         xlabel=xlabel,
         title=title)
コード例 #3
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.assertAlmostEqual(test_knife.JackknifedStat, 1.2905845)
     self.assertAlmostEqual(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.assertAlmostEqual(got_jk_stat[index], expected_jk_stat[index])
         self.assertAlmostEqual(got_standard_err[index],
                                expected_standard_err[index])
コード例 #4
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]):
         self.assertAlmostEqual(got_subsample_stats[index],
                                expected_subsample_stats[index], places=4)
         self.assertAlmostEqual(got_pseudovalues[index],
                                expected_pseudovalues[index], places=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]):
             self.assertAlmostEqual(got_subsample_stats[index1][index2],
                                    expected_subsample_stats[index1][index2],
                                    places=4)
             self.assertAlmostEqual(got_pseudovalues[index1][index2],
                                    expected_pseudovalues[index1][index2],
                                    places=4)
コード例 #5
0
ファイル: test_jackknife.py プロジェクト: chungtseng/pycogent
 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]):
         self.assertAlmostEqual(got_subsample_stats[index],
                                expected_subsample_stats[index], places=4)
         self.assertAlmostEqual(got_pseudovalues[index],
                                expected_pseudovalues[index], places=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]):
             self.assertAlmostEqual(got_subsample_stats[index1][index2],
                                    expected_subsample_stats[index1][index2],
                                    places=4)
             self.assertAlmostEqual(got_pseudovalues[index1][index2],
                                    expected_pseudovalues[index1][index2],
                                    places=4)