Skip to content

Commit

Permalink
REF/TST: sandwich arrays add score_obs, add GLM-Poisson tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josef-pkt committed Aug 20, 2014
1 parent be78ac8 commit 0bf6607
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions statsmodels/discrete/tests/test_sandwich_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import numpy as np
import pandas as pd
import statsmodels.discrete.discrete_model as smd
from statsmodels.genmod.generalized_linear_model import GLM
from statsmodels.genmod import families
import statsmodels.stats.sandwich_covariance as sc
from statsmodels.base.covtype import get_robustcov_results
from statsmodels.tools.tools import add_constant

from numpy.testing import assert_allclose
Expand Down Expand Up @@ -217,6 +220,57 @@ def setup_class(cls):
cls.corr_fact = np.sqrt(corr_fact)


class TestGLMPoissonClu(CheckCountRobustMixin):

@classmethod
def setup_class(cls):
cls.res2 = results_st.results_poisson_clu
mod = smd.Poisson(endog, exog)
mod = GLM(endog, exog, family=families.Poisson())
cls.res1 = mod.fit()
cls.get_robust_clu()


class TestGLMPoissonCluGeneric(CheckCountRobustMixin):

@classmethod
def setup_class(cls):
cls.res2 = results_st.results_poisson_clu
mod = GLM(endog, exog, family=families.Poisson())
cls.res1 = res1 = mod.fit()

get_robustcov_results(cls.res1._results, 'cluster',
groups=group,
use_correction=True,
df_correction=True, #TODO has no effect
use_t=False, #True,
use_self=True)
cls.bse_rob = cls.res1.bse

nobs, k_vars = res1.model.exog.shape
k_params = len(res1.params)
#n_groups = len(np.unique(group))
corr_fact = (nobs-1.) / float(nobs - k_params)
# for bse we need sqrt of correction factor
cls.corr_fact = np.sqrt(corr_fact)


class TestGLMPoissonHC1Generic(CheckCountRobustMixin):

@classmethod
def setup_class(cls):
cls.res2 = results_st.results_poisson_hc1
mod = GLM(endog, exog, family=families.Poisson())
cls.res1 = mod.fit()

#res_hc0_ = cls.res1.get_robustcov_results('HC1')
get_robustcov_results(cls.res1._results, 'HC1', use_self=True)
cls.bse_rob = cls.res1.bse
nobs, k_vars = mod.exog.shape
corr_fact = (nobs) / float(nobs - 1.)
# for bse we need sqrt of correction factor
cls.corr_fact = np.sqrt(1./corr_fact)


class TestNegbinClu(CheckCountRobustMixin):

Expand Down
2 changes: 2 additions & 0 deletions statsmodels/stats/sandwich_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def _get_sandwich_arrays(results):
# assume we have a results instance
if hasattr(results.model, 'jac'):
xu = results.model.jac(results.params)
elif hasattr(results.model, 'score_obs'):
xu = results.model.score_obs(results.params)
else:
xu = results.model.exog * results.resid[:, None]

Expand Down

0 comments on commit 0bf6607

Please sign in to comment.