def test_bayes_factor_poisson(self): """ Check the Bayes factor function for Poisson distributions.""" res = es.bayes_factor(self.rand_s3, self.rand_s4, distribution='poisson', num_iters=2000) self.assertEqual(res.treatment_statistics.sample_size, 1000) self.assertEqual(res.control_statistics.sample_size, 1000) self.assertAlmostEqual(res.treatment_statistics.mean, 0.96599999999999997) self.assertAlmostEqual(res.control_statistics.mean, 2.9249999999999998) self.assertAlmostEqual(res.treatment_statistics.variance, 0.868844) self.assertAlmostEqual(res.control_statistics.variance, 2.901375) self.assertAlmostEqual(res.delta, -1.9589999999999999) value025 = find_value_by_key_with_condition(res.confidence_interval, 'percentile', 2.5, 'value') value975 = find_value_by_key_with_condition(res.confidence_interval, 'percentile', 97.5, 'value') np.testing.assert_almost_equal(value025, -2.0713281392132465, decimal=5) np.testing.assert_almost_equal(value975, -1.8279692168150592, decimal=5) self.assertEqual(res.p, None) self.assertEqual(res.statistical_power, None) self.assertEqual(res.stop, True)
def test_bayes_factor(self): """ Check the Bayes factor function.""" res = es.bayes_factor(self.rand_s1, self.rand_s2, num_iters=2000) self.assertEqual(res.treatment_statistics.sample_size, 1000) self.assertEqual(res.control_statistics.sample_size, 1000) self.assertAlmostEqual(res.treatment_statistics.mean, -0.045256707490195384) self.assertAlmostEqual(res.control_statistics.mean, 0.11361694031616358) self.assertAlmostEqual(res.treatment_statistics.variance, 0.9742344563121542) self.assertAlmostEqual(res.control_statistics.variance, 0.9373337542827797) self.assertAlmostEqual(res.delta, -0.15887364780635896) value025 = find_value_by_key_with_condition(res.confidence_interval, 'percentile', 2.5, 'value') value975 = find_value_by_key_with_condition(res.confidence_interval, 'percentile', 97.5, 'value') np.testing.assert_almost_equal(value025, -0.24293384641452503, decimal=5) np.testing.assert_almost_equal(value975, -0.075064346336461404, decimal=5) self.assertEqual(res.p, None) self.assertEqual(res.statistical_power, None) self.assertEqual(res.stop, True)
def do_delta(f): print(f.iloc[0,1]) return early_stopping_to_dataframe(f.columns[2], *es.bayes_factor( x=f.iloc[:, 2], y=baseline_metric, distribution=distribution ))
def test_bayes_factor(self): """ Check the Bayes factor function. """ res = es.bayes_factor(self.rand_s1, self.rand_s2, num_iters=2000) self.assertEqual(res['stop'], True) self.assertAlmostEqual(res['delta'], -0.15887364780635896) self.assertAlmostEqual(res['interval'][02.5], -0.24644586591251214) self.assertAlmostEqual(res['interval'][97.5], -0.075698253541557695) self.assertEqual(res['n_x'], 1000) self.assertEqual(res['n_y'], 1000) self.assertAlmostEqual(res['mu_x'], -0.045256707490195384) self.assertAlmostEqual(res['mu_y'], 0.11361694031616358)
def test_bayes_factor_poisson(self): """ Check the Bayes factor function for Poisson distributions. """ stop, delta, CI, n_x, n_y, mu_x, mu_y = es.bayes_factor( self.rand_s3, self.rand_s4, distribution='poisson') self.assertEqual(stop, 1) self.assertAlmostEqual(delta, -1.9589999999999999) self.assertAlmostEqual(CI['lower'], -2.0713332592866109) self.assertAlmostEqual(CI['upper'], -1.8258221195574416) self.assertEqual(n_x, 1000) self.assertEqual(n_y, 1000) self.assertAlmostEqual(mu_x, 0.96599999999999997) self.assertAlmostEqual(mu_y, 2.9249999999999998)
def test_bayes_factor(self): """ Check the Bayes factor function. """ stop, delta, CI, n_x, n_y, mu_x, mu_y = es.bayes_factor( self.rand_s1, self.rand_s2) self.assertEqual(stop, 1) self.assertAlmostEqual(delta, -0.15887364780635896) self.assertAlmostEqual(CI['lower'], -0.2488832923198368) self.assertAlmostEqual(CI['upper'], -0.074066551390901375) self.assertEqual(n_x, 1000) self.assertEqual(n_y, 1000) self.assertAlmostEqual(mu_x, -0.045256707490195384) self.assertAlmostEqual(mu_y, 0.11361694031616358)
def test_bayes_factor_poisson(self): """ Check the Bayes factor function for Poisson distributions. """ res= es.bayes_factor(self.rand_s3, self.rand_s4, distribution='poisson', num_iters=2000) self.assertEqual (res['stop'], True) self.assertAlmostEqual (res['delta'], -1.9589999999999999) value025 = find_list_of_dicts_element(res['confidence_interval'], 'percentile', 2.5, 'value') value975 = find_list_of_dicts_element(res['confidence_interval'], 'percentile', 97.5, 'value') self.assertAlmostEqual (value025, -2.0713281392132465) self.assertAlmostEqual (value975, -1.8279692168150592) self.assertEqual (res['treatment_sample_size'], 1000) self.assertEqual (res['control_sample_size'], 1000) self.assertAlmostEqual (res['treatment_mean'], 0.96599999999999997) self.assertAlmostEqual (res['control_mean'], 2.9249999999999998)
def test_bayes_factor_poisson(self): """ Check the Bayes factor function for Poisson distributions. """ res = es.bayes_factor(self.rand_s3, self.rand_s4, distribution='poisson', num_iters=2000) self.assertEqual(res['stop'], True) self.assertAlmostEqual(res['delta'], -1.9589999999999999) self.assertAlmostEqual(res['interval'][02.5], -2.0713281392132465) self.assertAlmostEqual(res['interval'][97.5], -1.8279692168150592) self.assertEqual(res['n_x'], 1000) self.assertEqual(res['n_y'], 1000) self.assertAlmostEqual(res['mu_x'], 0.96599999999999997) self.assertAlmostEqual(res['mu_y'], 2.9249999999999998)
def test_bayes_factor(self): """ Check the Bayes factor function. """ res = es.bayes_factor(self.rand_s1, self.rand_s2, num_iters=2000) self.assertEqual (res['stop'], True) self.assertAlmostEqual (res['delta'], -0.15887364780635896) value025 = find_list_of_dicts_element(res['confidence_interval'], 'percentile', 2.5, 'value') value975 = find_list_of_dicts_element(res['confidence_interval'], 'percentile', 97.5, 'value') self.assertAlmostEqual (value025, -0.24293384641452503) self.assertAlmostEqual (value975, -0.075064346336461404) self.assertEqual (res['treatment_sample_size'], 1000) self.assertEqual (res['control_sample_size'], 1000) self.assertAlmostEqual (res['treatment_mean'], -0.045256707490195384) self.assertAlmostEqual (res['control_mean'], 0.11361694031616358)
def test_bayes_factor_with_nan_input(self): """ Check the Bayes factor function with input that contains nan values.""" res = es.bayes_factor(self.rand_s5, self.rand_s6, num_iters=2000) self.assertEqual(res.stop, True)