コード例 #1
0
ファイル: ttest_test.py プロジェクト: Alattack/catapult
 def testDegreesOfFreedom(self):
   """Tests calculation of estimated degrees of freedom."""
   # The formula used to estimate degrees of freedom for independent-samples
   # t-test is called the Welch-Satterthwaite equation. Note that since the
   # Welch-Satterthwaite equation gives an estimate of degrees of freedom,
   # the result is a floating-point number and not an integer.
   stats1 = ttest.SampleStats(mean=0.299, var=0.05, size=150)
   stats2 = ttest.SampleStats(mean=0.307, var=0.08, size=165)
   self.assertAlmostEqual(
       307.19879975, ttest._DegreesOfFreedom(stats1, stats2))
コード例 #2
0
 def testDegreesOfFreedom(self):
     """Tests calculation of estimated degrees of freedom."""
     # The formula used to estimate degrees of freedom for independent-samples
     # t-test is called the Welch-Satterthwaite equation. Note that since the
     # Welch-Satterthwaite equation gives an estimate of degrees of freedom,
     # the result is a floating-point number and not an integer.
     stats1 = ttest.SampleStats(mean=0.299, var=0.05, size=150)
     stats2 = ttest.SampleStats(mean=0.307, var=0.08, size=165)
     self.assertAlmostEqual(307.19879975,
                            ttest._DegreesOfFreedom(stats1, stats2))
コード例 #3
0
ファイル: ttest_test.py プロジェクト: Alattack/catapult
  def testDegreesOfFreedom_SmallSample_RaisesError(self):
    """Degrees of freedom can't be calculated if sample size is too small."""
    size_0 = ttest.SampleStats(mean=0, var=0, size=0)
    size_1 = ttest.SampleStats(mean=1.0, var=0, size=1)
    size_5 = ttest.SampleStats(mean=2.0, var=0.5, size=5)

    # An error is raised if the size of one of the samples is too small.
    with self.assertRaises(RuntimeError):
      ttest._DegreesOfFreedom(size_0, size_5)
    with self.assertRaises(RuntimeError):
      ttest._DegreesOfFreedom(size_1, size_5)
    with self.assertRaises(RuntimeError):
      ttest._DegreesOfFreedom(size_5, size_0)
    with self.assertRaises(RuntimeError):
      ttest._DegreesOfFreedom(size_5, size_1)

    # If both of the samples have a variance of 0, no error is raised.
    self.assertEqual(1.0, ttest._DegreesOfFreedom(size_1, size_1))
コード例 #4
0
    def testDegreesOfFreedom_SmallSample_RaisesError(self):
        """Degrees of freedom can't be calculated if sample size is too small."""
        size_0 = ttest.SampleStats(mean=0, var=0, size=0)
        size_1 = ttest.SampleStats(mean=1.0, var=0, size=1)
        size_5 = ttest.SampleStats(mean=2.0, var=0.5, size=5)

        # An error is raised if the size of one of the samples is too small.
        with self.assertRaises(RuntimeError):
            ttest._DegreesOfFreedom(size_0, size_5)
        with self.assertRaises(RuntimeError):
            ttest._DegreesOfFreedom(size_1, size_5)
        with self.assertRaises(RuntimeError):
            ttest._DegreesOfFreedom(size_5, size_0)
        with self.assertRaises(RuntimeError):
            ttest._DegreesOfFreedom(size_5, size_1)

        # If both of the samples have a variance of 0, no error is raised.
        self.assertEqual(1.0, ttest._DegreesOfFreedom(size_1, size_1))
コード例 #5
0
ファイル: ttest_test.py プロジェクト: Alattack/catapult
 def testDegreesOfFreedom_ZeroVariance_ResultIsOne(self):
   """The lowest possible value is returned for df if variance is zero."""
   stats = ttest.SampleStats(mean=1.0, var=0, size=10)
   self.assertEqual(1.0, ttest._DegreesOfFreedom(stats, stats))
コード例 #6
0
 def testDegreesOfFreedom_ZeroVariance_ResultIsOne(self):
     """The lowest possible value is returned for df if variance is zero."""
     stats = ttest.SampleStats(mean=1.0, var=0, size=10)
     self.assertEqual(1.0, ttest._DegreesOfFreedom(stats, stats))