Ejemplo n.º 1
0
class TestGLMGaussHACGroupsum(CheckDiscreteGLM):
    cov_type = 'hac-groupsum'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {
        'time': pd.Series(np.tile(np.arange(7), 5)[:-1]),
        # time index is just made up to have a test case
        # check for GH#3606
        'maxlags': 2,
        'use_correction': 'hac',
        'df_correction': False
    }
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)
        cls.res1b = mod1.fit(disp=False, **cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False, **cls.fit_kwargs)

    def test_kwd(self):
        # test corrected keyword name
        assert_allclose(self.res1b.bse, self.res1.bse, rtol=1e-12)
Ejemplo n.º 2
0
class TestGLMGaussHACPanel(CheckDiscreteGLM):
    cov_type = 'hac-panel'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {
        'time': np.tile(np.arange(7), 5)[:-1],
        # time index is just made up to have a test case
        'maxlags': 2,
        'kernel': sw.weights_uniform,
        'use_correction': 'hac',
        'df_correction': False
    }
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)
        cls.res1b = mod1.fit(cov_type='nw-panel', cov_kwds=cls.cov_kwds)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False, **cls.fit_kwargs)

    def test_kwd(self):
        # test corrected keyword name
        assert_allclose(self.res1b.bse, self.res1.bse, rtol=1e-12)
Ejemplo n.º 3
0
class TestGLMGaussHAC(CheckDiscreteGLM):
    cov_type = 'HAC'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {'maxlags': 2}
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False, **cls.fit_kwargs)
Ejemplo n.º 4
0
class TestGLMGaussClu(CheckDiscreteGLM):
    cov_type = 'cluster'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {'groups': group}
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):  # TODO: de-dup with other setup_classes
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False, **cls.fit_kwargs)
Ejemplo n.º 5
0
class TestGLMGaussNonRobust(CheckDiscreteGLM):
    cov_type = 'nonrobust'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {}
    fit_kwargs = {"cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False, **cls.fit_kwargs)
Ejemplo n.º 6
0
class TestGLMGaussHACUniform2(TestGLMGaussHACUniform):
    # GH#4524
    cov_type = 'HAC'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {"kernel": sw.weights_uniform, "maxlags": 2}
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(**cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        # check kernel as string
        kwds2 = {'kernel': 'uniform', 'maxlags': 2}
        cls.res2 = mod2.fit(cov_type=cls.cov_type, cov_kwds=kwds2)
Ejemplo n.º 7
0
class TestGLMGaussHAC2(CheckDiscreteGLM):
    cov_type = 'HAC'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {'kernel': 'bartlett', 'maxlags': 2}
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        # check kernel specified as string
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False,
                            cov_type=cls.cov_type,
                            cov_kwds={'maxlags': 2})
Ejemplo n.º 8
0
class TestGLMGaussHACUniform(CheckDiscreteGLM):
    cov_type = 'HAC'
    mod_kwargs = {"family": families.Gaussian()}
    cov_kwds = {'kernel': sw.weights_uniform, 'maxlags': 2}
    fit_kwargs = {"cov_type": cov_type, "cov_kwds": cov_kwds}

    @classmethod
    def setup_class(cls):
        mod1 = cls.model_cls(endog, exog, **cls.mod_kwargs)
        cls.res1 = mod1.fit(disp=False, **cls.fit_kwargs)

        mod2 = OLS(endog, exog)
        cls.res2 = mod2.fit(disp=False, **cls.fit_kwargs)

        # for debugging
        cls.res3 = mod2.fit(cov_type=cls.cov_type, cov_kwds={'maxlags': 2})
        # TODO: Should something be done with res3?

    def test_cov_options(self):
        # check keyword `weights_func
        kwdsa = {'weights_func': sw.weights_uniform, 'maxlags': 2}
        res1a = self.res1.model.fit(cov_type=self.cov_type, cov_kwds=kwdsa)
        res2a = self.res2.model.fit(cov_type=self.cov_type, cov_kwds=kwdsa)

        assert_allclose(res1a.bse, self.res1.bse, rtol=1e-12)
        assert_allclose(res2a.bse, self.res2.bse, rtol=1e-12)

        # regression test for bse values
        bse = np.array([2.82203924, 4.60199596, 11.01275064])
        assert_allclose(res1a.bse, bse, rtol=1e-6)

        assert res1a.cov_kwds['weights_func'] is sw.weights_uniform

        kwdsb = {'kernel': sw.weights_bartlett, 'maxlags': 2}
        res1a = self.res1.model.fit(cov_type='HAC', cov_kwds=kwdsb)
        res2a = self.res2.model.fit(cov_type='HAC', cov_kwds=kwdsb)
        assert_allclose(res1a.bse, res2a.bse, rtol=1e-12)

        # regression test for bse values
        bse = np.array([2.502264, 3.697807, 9.193303])
        assert_allclose(res1a.bse, bse, rtol=1e-6)