示例#1
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for hierarchical regression"""
     #mle_sequential = glm.ordinal_estimation(ratio='sequential', distribution = core.NormalDistribution(), data = self._data_ordinal, response = 0, explanatories = {1,2,3,4})
     mle = glm.ordinal_estimation(ratio='sequential', data = self._data_ordinal, response = 0, explanatories = {1,2,3,4})  
     a = mle.estimated.predictor.alpha
     mle = glm.hierarchical_estimation(data = self._data_hierarchical, response = 0, explanatories = {1,2,3,4})
     A0 = mle[""].estimated.predictor.alpha[0]
     A1 = mle["12"].estimated.predictor.alpha[0]
     self.assertAlmostEqual(a[0], A0, places=3)
     self.assertAlmostEqual(a[1], A1, places=2)
     mle_sequential_cauchy = glm.ordinal_estimation(ratio='sequential', distribution = core.CauchyDistribution(), data = self._data_ordinal, response = 0, explanatories = {1,2,3,4})  
     estimator = glm.nominal_estimation(distribution = core.CauchyDistribution())      
     mle_hierarchical = glm.hierarchical_estimation(default = estimator, data = self._data_hierarchical, response = 0, explanatories = {1,2,3,4})
     alpha_sequential_cauchy = mle_sequential_cauchy.estimated.predictor.alpha
     alpha_hierarchical_root = mle_hierarchical[""].estimated.predictor.alpha[0]
     alpha_hierarchical_12 = mle_hierarchical["12"].estimated.predictor.alpha[0]
     self.assertAlmostEqual(alpha_sequential_cauchy[0], alpha_hierarchical_root, places=2)
     self.assertAlmostEqual(alpha_sequential_cauchy[1], alpha_hierarchical_12, places=2)
     mle_sequential_laplace = glm.ordinal_estimation(ratio='sequential', distribution = core.LaplaceDistribution(), data = self._data_ordinal, response = 0, explanatories = {1,2,3,4})               
     estimator_12 = glm.nominal_estimation(distribution = core.LaplaceDistribution())
     mle_hierarchical = glm.hierarchical_estimation(default = estimator, **{"12" : estimator_12}, data = self._data_hierarchical, response = 0, explanatories = {1,2,3,4})
     alpha_sequential_laplace = mle_sequential_laplace.estimated.predictor.alpha        
     alpha_hierarchical_root = mle_hierarchical[""].estimated.predictor.alpha[0]
     alpha_hierarchical_12 = mle_hierarchical["12"].estimated.predictor.alpha[0]
     self.assertAlmostEqual(alpha_sequential_cauchy[0], alpha_hierarchical_root, places=2)
     self.assertAlmostEqual(alpha_sequential_laplace[1], alpha_hierarchical_12, places=1)
     binary_estimator_cauchy = glm.binary_estimation(distribution = core.CauchyDistribution())
     binary_estimator_laplace = glm.binary_estimation(distribution = core.LaplaceDistribution())
     mle_hierarchical = glm.hierarchical_estimation(default = binary_estimator_cauchy, **{"12" : binary_estimator_laplace}, data = self._data_hierarchical, response = 0, explanatories = {1,2,3,4})
     alpha_hierarchical_root = mle_hierarchical[""].estimated.predictor.alpha
     alpha_hierarchical_12 = mle_hierarchical["12"].estimated.predictor.alpha       
     self.assertAlmostEqual(alpha_sequential_cauchy[0], alpha_hierarchical_root, places=3)
示例#2
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for canonical ordinal regression with complete design"""
     mle = glm.ordinal_estimation(data=self._data, response = 0, explanatories = {1, 2})
     alpha = mle.estimated.predictor.alpha
     delta = mle.estimated.predictor.delta
     self.assertAlmostEqual(mle.loglikelihood, self._loglikelihood, places=2)
     self._data.AirConditioning.sample_space = self._data.AirConditioning.sample_space.as_nominal()
     mle = glm.nominal_estimation(data=self._data, response = 0, explanatories = {1, 2})
     self.assertAlmostEqual(mle.loglikelihood, self._loglikelihood, places=2)
示例#3
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for ordinal regression with proportional design"""
     mle = glm.ordinal_estimation(ratio='sequential', Z='constrained', data=self._data, response = 0, explanatories = {1,2,3,4}, partial_proportional={1,2,3})
     alpha = mle.estimated.predictor.alpha
     delta = mle.estimated.predictor.delta
     for i in range(len(self._alpha)):
         x = int(alpha[i]*1000)/float(1000)
         self.assertEqual(x, self._alpha[i])
     for i in range(len(self._delta)):
         x = int(delta[i]*1000)/float(1000)
         self.assertEqual(x, self._delta[i]) 
示例#4
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for cumulative regression with proportional design"""
     #import ipdb
     #ipdb.set_trace()
     # beta_init = linalg.Vector([-0.66, 0.66, 0., 0., 0.])
     # mle = glm.ordinal_estimation(ratio='cumulative', Z='proportional', data=self._data, response = 0, explanatories = {1,2}, beta_init=beta_init)
     mle = glm.ordinal_estimation(ratio='cumulative', Z='proportional', data=self._data, response = 0, explanatories = {1, 2})
     alpha = mle.estimated.predictor.alpha
     delta = mle.estimated.predictor.delta
     self.assertAlmostEqual(mle.loglikelihood, self._loglikelihood, places=3)
     for i in range(len(self._alpha)):
         self.assertAlmostEqual(alpha[i], self._alpha[i], places=3)
     for i in range(len(self._delta)):
         self.assertAlmostEqual(delta[i], self._delta[i], places=3)
示例#5
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for ordinal regression with proportional design"""
     mle = glm.ordinal_estimation(ratio='sequential',
                                  Z='constrained',
                                  data=self._data,
                                  response=0,
                                  explanatories={1, 2, 3, 4},
                                  partial_proportional={1, 2, 3})
     alpha = mle.estimated.predictor.alpha
     delta = mle.estimated.predictor.delta
     for i in range(len(self._alpha)):
         x = int(alpha[i] * 1000) / float(1000)
         self.assertEqual(x, self._alpha[i])
     for i in range(len(self._delta)):
         x = int(delta[i] * 1000) / float(1000)
         self.assertEqual(x, self._delta[i])
示例#6
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for canonical ordinal regression with complete design"""
     mle = glm.ordinal_estimation(data=self._data,
                                  response=0,
                                  explanatories={1, 2})
     alpha = mle.estimated.predictor.alpha
     delta = mle.estimated.predictor.delta
     self.assertAlmostEqual(mle.loglikelihood,
                            self._loglikelihood,
                            places=2)
     self._data.AirConditioning.sample_space = self._data.AirConditioning.sample_space.as_nominal(
     )
     mle = glm.nominal_estimation(data=self._data,
                                  response=0,
                                  explanatories={1, 2})
     self.assertAlmostEqual(mle.loglikelihood,
                            self._loglikelihood,
                            places=2)
示例#7
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for cumulative regression with proportional design"""
     #import ipdb
     #ipdb.set_trace()
     # beta_init = linalg.Vector([-0.66, 0.66, 0., 0., 0.])
     # mle = glm.ordinal_estimation(ratio='cumulative', Z='proportional', data=self._data, response = 0, explanatories = {1,2}, beta_init=beta_init)
     mle = glm.ordinal_estimation(ratio='cumulative',
                                  Z='proportional',
                                  data=self._data,
                                  response=0,
                                  explanatories={1, 2})
     alpha = mle.estimated.predictor.alpha
     delta = mle.estimated.predictor.delta
     self.assertAlmostEqual(mle.loglikelihood,
                            self._loglikelihood,
                            places=3)
     for i in range(len(self._alpha)):
         self.assertAlmostEqual(alpha[i], self._alpha[i], places=3)
     for i in range(len(self._delta)):
         self.assertAlmostEqual(delta[i], self._delta[i], places=3)
示例#8
0
 def test_Fisher(self):
     """Test Fisher scoring estimation for hierarchical regression"""
     #mle_sequential = glm.ordinal_estimation(ratio='sequential', distribution = core.NormalDistribution(), data = self._data_ordinal, response = 0, explanatories = {1,2,3,4})
     mle = glm.ordinal_estimation(ratio='sequential',
                                  data=self._data_ordinal,
                                  response=0,
                                  explanatories={1, 2, 3, 4})
     a = mle.estimated.predictor.alpha
     mle = glm.hierarchical_estimation(data=self._data_hierarchical,
                                       response=0,
                                       explanatories={1, 2, 3, 4})
     A0 = mle[""].estimated.predictor.alpha[0]
     A1 = mle["12"].estimated.predictor.alpha[0]
     self.assertAlmostEqual(a[0], A0, places=3)
     self.assertAlmostEqual(a[1], A1, places=2)
     mle_sequential_cauchy = glm.ordinal_estimation(
         ratio='sequential',
         distribution=core.CauchyDistribution(),
         data=self._data_ordinal,
         response=0,
         explanatories={1, 2, 3, 4})
     estimator = glm.nominal_estimation(
         distribution=core.CauchyDistribution())
     mle_hierarchical = glm.hierarchical_estimation(
         default=estimator,
         data=self._data_hierarchical,
         response=0,
         explanatories={1, 2, 3, 4})
     alpha_sequential_cauchy = mle_sequential_cauchy.estimated.predictor.alpha
     alpha_hierarchical_root = mle_hierarchical[
         ""].estimated.predictor.alpha[0]
     alpha_hierarchical_12 = mle_hierarchical[
         "12"].estimated.predictor.alpha[0]
     self.assertAlmostEqual(alpha_sequential_cauchy[0],
                            alpha_hierarchical_root,
                            places=2)
     self.assertAlmostEqual(alpha_sequential_cauchy[1],
                            alpha_hierarchical_12,
                            places=2)
     mle_sequential_laplace = glm.ordinal_estimation(
         ratio='sequential',
         distribution=core.LaplaceDistribution(),
         data=self._data_ordinal,
         response=0,
         explanatories={1, 2, 3, 4})
     estimator_12 = glm.nominal_estimation(
         distribution=core.LaplaceDistribution())
     mle_hierarchical = glm.hierarchical_estimation(
         default=estimator,
         **{"12": estimator_12},
         data=self._data_hierarchical,
         response=0,
         explanatories={1, 2, 3, 4})
     alpha_sequential_laplace = mle_sequential_laplace.estimated.predictor.alpha
     alpha_hierarchical_root = mle_hierarchical[
         ""].estimated.predictor.alpha[0]
     alpha_hierarchical_12 = mle_hierarchical[
         "12"].estimated.predictor.alpha[0]
     self.assertAlmostEqual(alpha_sequential_cauchy[0],
                            alpha_hierarchical_root,
                            places=2)
     self.assertAlmostEqual(alpha_sequential_laplace[1],
                            alpha_hierarchical_12,
                            places=1)
     binary_estimator_cauchy = glm.binary_estimation(
         distribution=core.CauchyDistribution())
     binary_estimator_laplace = glm.binary_estimation(
         distribution=core.LaplaceDistribution())
     mle_hierarchical = glm.hierarchical_estimation(
         default=binary_estimator_cauchy,
         **{"12": binary_estimator_laplace},
         data=self._data_hierarchical,
         response=0,
         explanatories={1, 2, 3, 4})
     alpha_hierarchical_root = mle_hierarchical[
         ""].estimated.predictor.alpha
     alpha_hierarchical_12 = mle_hierarchical[
         "12"].estimated.predictor.alpha
     self.assertAlmostEqual(alpha_sequential_cauchy[0],
                            alpha_hierarchical_root,
                            places=3)