Skip to content

Commit

Permalink
TST: Add test for offset exposure null
Browse files Browse the repository at this point in the history
Add test for statsmodels#6953
  • Loading branch information
bashtage committed Aug 7, 2020
1 parent 29c9603 commit 88b7b2d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions statsmodels/genmod/tests/test_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2377,3 +2377,27 @@ def test_glm_bic_warning(iris):
model = GLM(y, X, family=sm.families.Binomial()).fit()
with pytest.warns(FutureWarning, match="The bic"):
assert isinstance(model.bic, float)


def test_output_exposure_null(reset_randomstate):
# GH 6953

x0 = [np.sin(i / 20) + 2 for i in range(1000)]
rs = np.random.RandomState(0)
# Variable exposures for each observation
exposure = rs.randint(100, 200, size=1000)
y = [np.sum(rs.poisson(x, size=e)) for x, e in zip(x0, exposure)]
x = add_constant(x0)

model = GLM(
endog=y, exog=x, exposure=exposure, family=sm.families.Poisson()
).fit()
null_model = GLM(
endog=y, exog=x[:, 0], exposure=exposure, family=sm.families.Poisson()
).fit()
null_model_without_exposure = GLM(
endog=y, exog=x[:, 0], family=sm.families.Poisson()
).fit()
assert_allclose(model.llnull, null_model.llf)
# Check that they are different
assert np.abs(null_model_without_exposure.llf - model.llnull) > 1

0 comments on commit 88b7b2d

Please sign in to comment.