You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GLMResults.null uses the model.attribute exposure without backtransforming from log
If I change it to using exp(exposure), then the unit tests still pass. This means that this case is not unit tested.
There are unit tests for null_deviance but not for llnull.
If I fix GLMResults.null directly with exp(exposure), then tests pass.
If I replace kwargs by model._get_init_kwds() (and pop family), then I get one test failure
_____________________ TestGlmBinomial.test_null_deviance ______________________
self = <statsmodels.genmod.tests.test_glm.TestGlmBinomial object at 0x0000000009
C7CAC8>
def test_null_deviance(self):
assert_almost_equal(self.res1.null_deviance, self.res2.null_deviance,
> self.decimal_null_deviance)
E AssertionError:
E Arrays are not almost equal to 4 decimals
E ACTUAL: 35455.297320077821
E DESIRED: 34345.3688931
..\eclipse_ws\statsmodels\statsmodels_py34_pr\statsmodels\genmod\tests\test_glm.
py:151: AssertionError
I don't understand why we should be using WLS if family is binomial.
AFAIR:
WLS with only a constant just computes the (prior-)weighted mean. This is the MLE if we have a canonical link, which is the case with Binomial. In this case using GLM or WLS should be equivalent for fittedvalues (params will be link transformed in one case and not in the other).
WLS will be incorrect with a non-canonical link, where we don't have (prior-weighted) mean residual =0.
test_glm.py has a comment, which I don't know what it means, or what's the reason for the comment
#TODO:
#Non-Canonical Links for the Binomial family require the algorithm to be
#slightly changed
???
I need some examples and unit tests to work through Null model cases.
for computing the null prediction, deviance, llf, the link function doesn't matter if offset and exposure are zero. Any link is just a equivalent reparameterization of a constant.
e.g. binomial-Logit and binomial-Probit null_deviance are the same.
So using WLS assuming the canonical link is just the most convenient way to compute null fittedvalues, mu.
deviance and loglike only depend on mu (and scale) and don't directly depend on link function.
i.e. there is no bug in the current code by using WLS if offset and exposure are both zero.
so there are only bugs in the GLM path in GLMResults.null
exposure not logged
wrong endog in case of Binomial with n_trials, which is used if either offset or exposure is a model attribute e.g. offset=np.zeros(nobs) produces the wrong results in this case, which is the case when I used model._get_init_kwds() for offset and exposure.
another bug is (no full support for weights in 0.9 in some fringes)
null currently ignores prior weights, freq and var_weights in the GLM path, (but not in the WLS path)
Activity
josef-pkt commentedon May 6, 2018
PR coming up later today,
josef-pkt commentedon May 6, 2018
something strange:
If I fix GLMResults.null directly with
exp(exposure), then tests pass.If I replace kwargs by model._get_init_kwds() (and pop family), then I get one test failure
using pdb
the only difference I can see is that we are not using WLS directly in GLM.null
I don't understand why we should be using WLS if family is binomial.
AFAIR:
WLS with only a constant just computes the (prior-)weighted mean. This is the MLE if we have a canonical link, which is the case with Binomial. In this case using GLM or WLS should be equivalent for fittedvalues (params will be link transformed in one case and not in the other).
WLS will be incorrect with a non-canonical link, where we don't have (prior-weighted) mean residual =0.
test_glm.pyhas a comment, which I don't know what it means, or what's the reason for the comment???
I need some examples and unit tests to work through Null model cases.
josef-pkt commentedon May 6, 2018
In the binomial case, model.endog is not the original endog, but the proportion.
That is we cannot recreate the model using the attached model.endog.
josef-pkt commentedon May 6, 2018
partial correction:
for computing the null prediction, deviance, llf, the link function doesn't matter if offset and exposure are zero. Any link is just a equivalent reparameterization of a constant.
e.g. binomial-Logit and binomial-Probit null_deviance are the same.
So using WLS assuming the canonical link is just the most convenient way to compute null fittedvalues, mu.
deviance and loglike only depend on mu (and scale) and don't directly depend on link function.
i.e. there is no bug in the current code by using WLS if offset and exposure are both zero.
josef-pkt commentedon May 6, 2018
so there are only bugs in the GLM path in GLMResults.null
offset=np.zeros(nobs)produces the wrong results in this case, which is the case when I usedmodel._get_init_kwds()for offset and exposure.another bug is (no full support for weights in 0.9 in some fringes)
nullcurrently ignores prior weights, freq and var_weights in the GLM path, (but not in the WLS path)BUG/REF: fix GLM `null`, init keywords closes statsmodels#4597, see s…