def test_bbsr_three_good_predictors(self):

        x = PREDICTORS_Z.copy()
        y = scipy.stats.zscore(np.sum(PREDICTORS, axis=1).flatten())

        pp = np.array([1, 1, 2])
        weights = np.array([10, 10, 10])
        max_k = 3

        result = bayes_stats.bbsr(x, y, pp, weights, max_k)

        pp = np.array([1, 1, 1])
        betas = np.array([0.583039, 0.491769, 0.478452])
        betas_resc = np.array([1.0, 1.0, 1.0])

        np.testing.assert_array_almost_equal(result['pp'], pp)
        np.testing.assert_array_almost_equal(result['betas'], betas)
        np.testing.assert_array_almost_equal(result['betas_resc'], betas_resc)

        result_2 = bayes_stats.bbsr(x,
                                    y,
                                    pp,
                                    weights,
                                    max_k,
                                    ordinary_least_squares=True)

        np.testing.assert_array_almost_equal(result['pp'], result_2['pp'])
        np.testing.assert_array_almost_equal(result['betas'],
                                             result_2['betas'])
        np.testing.assert_array_almost_equal(result['betas_resc'],
                                             result_2['betas_resc'])
 def regression_maker(j, x, y, pp, weights):
     level = 0 if j % 100 == 0 else 2
     utils.Debug.allprint(base_regression.PROGRESS_STR.format(gn=genes[j],
                                                              i=j,
                                                              total=G),
                          level=level)
     data = bayes_stats.bbsr(x, utils.scale_vector(y), pp[j, :].flatten(),
                             weights[j, :].flatten(), nS)
     data['ind'] = j
     return j, data
Esempio n. 3
0
 def regression_maker(j):
     level = 0 if j % 100 == 0 else 2
     utils.Debug.allprint(base_regression.PROGRESS_STR.format(gn=self.genes[j], i=j, total=self.G),
                          level=level)
     data = bayes_stats.bbsr(self.X.values,
                             self.Y.iloc[j, :].values.flatten(),
                             self.pp.iloc[j, :].values.flatten(),
                             self.weights_mat.iloc[j, :].values.flatten(),
                             self.nS)
     data['ind'] = j
     return data
 def test_bbsr(self):
     # test when pp.sum() != 0
     X = np.array([[1, 0, 1], [2, 1, 0], [1, 1, 1], [0, 0, 1], [2, 1, 2]])
     y = np.array([0, 1, 0])
     pp = np.array([0, 1, 2, 1, 0])
     weights = np.array([1, 0, 2, 1, 5])
     max_k = 10
     result = bayes_stats.bbsr(X, y, pp, weights, max_k)
     pp = np.array([0, 1, 1, 1, 0])
     betas = np.array([0.0, 0.0, 0.0])
     betas_resc = np.array([0.0, 0.0, 0.0])
     dict = {'pp': pp, 'betas': betas, 'betas_resc': betas_resc}
     np.testing.assert_equal(result, dict)
 def test_bbsr_3(self):
     # test when betas and betas_resc are not zero
     X = np.array([[1, 3, 1], [2, 1, 0], [1, 10, 5], [2, 6, 1], [2, 1, 8]])
     y = np.array([2, 1, 4])
     pp = np.array([10, 3, 1, 5, 4])
     weights = np.array([10, 10, 10, 10, 10])
     max_k = 3
     result = bayes_stats.bbsr(X, y, pp, weights, max_k)
     pp = np.array([1, 0, 0, 1, 1])
     betas = ([0.0, 0.0, 0.53623188])
     betas_resc = ([0.0, 0.0, 0.83820926])
     check = {'pp': pp, 'betas': betas, 'betas_resc': betas_resc}
     for component in check.keys():
         for idx in range(0, len(check[component])):
             np.testing.assert_array_almost_equal(result[component][idx],
                                                  check[component][idx], 2)
        def regression_maker(j):
            level = 0 if j % 100 == 0 else 2
            utils.Debug.allprint(base_regression.PROGRESS_STR.format(
                gn=self.genes[j], i=j, total=self.G),
                                 level=level)

            data = bayes_stats.bbsr(
                self.X.values,
                utils.scale_vector(
                    self.Y.get_gene_data(j, force_dense=True, flatten=True)),
                self.pp.iloc[j, :].values.flatten(),
                self.weights_mat.iloc[j, :].values.flatten(),
                self.nS,
                ordinary_least_squares=self.ols_only)
            data['ind'] = j
            return data