Beispiel #1
0
    def setup_class(cls):
        model = "I(food/income) ~ income + persons"
        cls.income_fit = BetaModel.from_formula(model, income).fit()

        model = cls.model = "methylation ~ gender + CpG"
        Z = cls.Z = patsy.dmatrix("~ age", methylation)
        mod = BetaModel.from_formula(model, methylation, exog_precision=Z,
                                     link_precision=links.identity())
        cls.meth_fit = mod.fit()
        mod = BetaModel.from_formula(model, methylation, exog_precision=Z,
                                     link_precision=links.Log())
        cls.meth_log_fit = mod.fit()
Beispiel #2
0
 def setup_class(cls):
     formula = "methylation ~ gender + CpG"
     mod = BetaModel.from_formula(formula, methylation,
                                  exog_precision_formula="~ age",
                                  link_precision=links.Log())
     cls.res1 = mod.fit(cov_type="eim")
     cls.res2 = resultsb.results_meth
Beispiel #3
0
 def test_precision_formula(self):
     m = BetaModel.from_formula(self.model, methylation,
                                exog_precision_formula='~ age',
                                link_precision=links.identity())
     rslt = m.fit()
     assert_close(rslt.params, self.meth_fit.params, 1e-10)
     assert isinstance(rslt.params, pd.Series)
Beispiel #4
0
    def setup_class(cls):

        formula = "I(food/income) ~ income + persons"
        exog_prec = patsy.dmatrix("~ persons", income)
        mod_income = BetaModel.from_formula(formula,
                                            income,
                                            exog_precision=exog_prec,
                                            link_precision=links.Log())
        res_income = mod_income.fit(method="newton")

        mod_restricted = BetaModel.from_formula(formula,
                                                income,
                                                link_precision=links.Log())
        res_restricted = mod_restricted.fit(method="newton")

        cls.res1 = res_income
        cls.resr = res_restricted
Beispiel #5
0
    def test_scores(self):
        model, Z = self.model, self.Z
        for link in (links.identity(), links.log()):
            mod2 = BetaModel.from_formula(model, methylation, exog_precision=Z,
                                          link_precision=link)
            rslt_m = mod2.fit()

            # evaluate away from optimum to get larger score
            analytical = rslt_m.model.score(rslt_m.params * 1.01)
            numerical = rslt_m.model._score_check(rslt_m.params * 1.01)
            assert_allclose(analytical, numerical, rtol=1e-6, atol=1e-6)
            assert_allclose(link.inverse(analytical[3:]),
                            link.inverse(numerical[3:]), rtol=5e-7, atol=5e-6)