Repository navigation
Conversation
There was a problem hiding this comment.
I think scale should be the same as self.variance(mu) already in the common, regular use case, but we should be able to fix scale independently of variance(mu)
I'm not sure yet
|
We need to decide whether |
|
I think scale should multiply the variance function. In the default case, varfunc is identically 1, so the variance is scale * varfunc = scale. As an alternative, someone could conceivably use the log link and varfunc(mu) = mu as the varfunc. This would give Poisson-like behavior with a Gaussian model. However the issue would remain when we attempt to compare to statsmodels.OLS or R lm, where the loglike value that is returned is the maximum value of the llf (evaluated at the MLE for both regression parameters and scale). Our genmod llf function by default uses self.scale, which is not the MLE. It seems to me that what we should do is remove the special code from the Gaussian loglike function that switches the provided scale with the MLE. Then in the tests we would change the genmod.llf call to pass in the MLE for scale. Thus, for genmod we consistently return as llf the loglikelihood evaluated at the usual genmod params estimate and the usual genmod (approximately unbiased) estimate of scale. This will be consistent across all GLM families, since we don't currently have code to compute the scale MLE in general (I think R has this but I don't see it as a high priority or a new feature). |
|
The alternative is that we provide an option to calculate scale as the MLE. Then when we compare to R and Stata in the tests we would invoke this option for the Gaussian family. |
|
We have three issues with scale and loglike that require decision about definition or version that we use
The last is one of the main use cases for llf /loglike: A 4th issue will come up later, if we allow for non-native variance, like additional heteroscedasticity, estimating a variance function additionally to a mean function. We will have to adjust all statistics including loglike and llf for that case. |
|
coming back to the original question I think it's better to use MLE scale in loglike even if it's irrelevant. That makes it cleaner to say that maximizing the loglike actually calculates the MLE. (In the simple Gaussian case the estimate of the mean parameters doesn't depend on the scale estimate, so it's irrelevant, but in other cases we might want to have really MLE loglike.) scale as function argument should fix the scale so we can use any provided scale chosen by the calling function for calculating loglike. This allows us to override it in non-MLE cases |
There was a problem hiding this comment.
this doesn't use the scale that the user provides
|
The complication not discussed yet is that I believe obtaining the MLE of the scale parameter is not just a matter of changing the denominator of the unbiased scale estimate. This is only true in the Gaussian case. For example, I believe in the overdispersed Poisson case it would involve numerical optimization. We could add MLE as a scale_type option and then raise an exception if the family is not Gaussian. |
|
Quasi-Poisson wouldn't be MLE, from what I have seen the main choices for scale are based on Pearson or deviance residuals, (implemented but not used as far as I have seen). |
|
I added scaletype='mle' as an option in |
#2351
The issue in loglike seems to be whether the scale parameter is the MLE or the unbiased method of moments estimate. The calculations were a bit convoluted, but it boils down to this difference.
For the current code, if using the power family with exponent 1 we ignore the provided scale parameter and implicitly replace it with the MLE. If instead we try to use the provided scale parameter, tests fail because the provided scale is the unbiased estimate not the MLE.
I implemented a simple calculation of the loglike value that in my view should be the only thing there. The older code in the "if" block is needed to get the tests to pass in the special case of power link with exponent 1. We should rewrite the tests so the code in the if block can be removed.
I also fixed unrelated issues in the deviance and resid_deviance methods.