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
{{ message }}
Repository navigation
ENH/REF/SUMM GMM round 3: cleanup and more enhancements #2640
check if score is more accurate and faster using equation for 1st derivative (using derivative of moment conditions Dg W g)
check test coverage of inherited methods (e.g. I recently had to fix t_test that raised exception)
unclear yet
separation of cov_type from weights method: there is no option even though we have separate calculations
e.g. AFAIR: maxiter=1 uses initial weightmatrix, but calculated cov_params based on covariance of moments after the fit. This is the main usecase.
Extensions and internal usage
hypothesis testing:
check Wald test,
add score/LM test,
refactor compare Q for fixed weights
Internal usage will not be necessary for GMM itself, but provides cases to check how well it works
write models that use GMM: I don't have any current plans for this, make IVPoisson official (out of test suite)
use GMM for specific inference questions: That's my current objective for internal use of GMM
get GMM representation of a model, e.g. easy for GLM
conditional moment tests on top of GMM representation of a model
covariance matrix of combined equations, example treatment effects, McFadden has some other examples for two stage estimation (e.g. heckman)
reading Davidson MacKinnon "Econometric Theory and Methods" chapter on GMM again (selective reading and paying attention to different details than before)
pages 376ff have the general correlated observation case explicitly for nonlinear moment conditions with optimal instruments. It reads now a bit similar to GEE (as more general version) but with the two cases: completely unknown or completely known covariance of errors (up to scale factor).
(GEE has working correlation which is not assumed to be correctly specified)
The same correlation across observations structure goes through large parts of the GMM chapter 9.
(I didn't read this carefully before because of their focus on instruments)
Possible extension: something like GEEGMM with working correlation or working heteroscedasticity (extend the idea of GMM to noncluster case, which is already allowed in GEE)
computational definition:
It looks like Davidson MacKinnon use instruments to convert moment conditions to exactly identified structure, similar to the first order condition of GMM optimization. I haven't tried to figure out the details yet. (It might become "3-D" because IVGMM only allows a 1-D residual. across moments and across observations???, eg. combine two IV moment conditions like in treatment effect models or multi-parameter distributions)
This might take us already in a similar route as DynamicPanelGMM, for which I haven't even figured out a prototype yet.
Going through a bit of the math we can just prewhiten an array of generic moment conditions to get to working independence of observations. see #1948 for correlation and prewhitening tools.
Calculating auxiliary parameters like autocorrelation coefficients might need more structure than generic moment conditions provide (e.g. 1-D residuals or score_factor)
As examples: We should be able to replicate GLSAR and GLSHet as GMM models, and be able to extend them to IVGMM versions for endogenous regressors. robust cov_types can still be on top of this if the modeled correlation is only a "working correlation" structure and not assumed to be correctly specified (but it should hold approximately to improve efficiency).
Sounds like fun, but something for "GMM round 4" not for a cleanup round 3.
One related issue: Before I was thinking more about adding more parametric assumptions on the calculation of the weight matrix (and associated cov_params). In this case we would deviate from the nonparametric, "unspecified" correlation or heteroscedasticity. This might result in similar outcome in some models as the prewhiten version, maybe in standard linear model. However, generic GMM works with sums and weights moment conditions, while pre-whitening changes the weight that observations get.
(e.g. exactly identified GMM replicates OLS parameters but has robust cov_params)
(In cluster/panel/system models we could treat each cluster as one observation and each observation within the cluster as a moment condition, then correlation across moment conditions would capture correlation within clusters. )
Davidson and MacKinnon make the point of using optimal instruments also to handle correlated observations clearer than any other book that I remember. To emphasis: parametric assumption and improvements to the estimation of the weight matrix uses more information for "efficient GMM" (ie. optimal weight matrix), but that does not say anything about optimal instruments.
(to be continued in private repo, to avoid even more detours here.)
changed the title [-]ENH/REF GMM round 3: cleanup and more enhancements[/-][+]ENH/REF/SUMM GMM round 3: cleanup and more enhancements[/+]on Aug 29, 2021
approx_fprime has centered option (default is False) GMM.gradient_momcond explicitly computes a centered numdiff.
Does delegating to approx_fprime with centered=True compute the same numdiff (except maybe different epsilon magnitude)?
Aside: We are starting to make heavier use for GMM internally, e.g. treatment effect, control function/iv.
Activity
josef-pkt commentedon Oct 7, 2015
related to correlation across observations:
reading Davidson MacKinnon "Econometric Theory and Methods" chapter on GMM again (selective reading and paying attention to different details than before)
pages 376ff have the general correlated observation case explicitly for nonlinear moment conditions with optimal instruments. It reads now a bit similar to GEE (as more general version) but with the two cases: completely unknown or completely known covariance of errors (up to scale factor).
(GEE has working correlation which is not assumed to be correctly specified)
The same correlation across observations structure goes through large parts of the GMM chapter 9.
(I didn't read this carefully before because of their focus on instruments)
Possible extension: something like GEEGMM with working correlation or working heteroscedasticity (extend the idea of GMM to noncluster case, which is already allowed in GEE)
computational definition:
It looks like Davidson MacKinnon use instruments to convert moment conditions to exactly identified structure, similar to the first order condition of GMM optimization. I haven't tried to figure out the details yet. (It might become "3-D" because IVGMM only allows a 1-D residual. across moments and across observations???, eg. combine two IV moment conditions like in treatment effect models or multi-parameter distributions)
This might take us already in a similar route as DynamicPanelGMM, for which I haven't even figured out a prototype yet.
josef-pkt commentedon Oct 7, 2015
Going through a bit of the math we can just prewhiten an array of generic moment conditions to get to working independence of observations. see #1948 for correlation and prewhitening tools.
Calculating auxiliary parameters like autocorrelation coefficients might need more structure than generic moment conditions provide (e.g. 1-D residuals or
score_factor)As examples: We should be able to replicate GLSAR and GLSHet as GMM models, and be able to extend them to IVGMM versions for endogenous regressors. robust cov_types can still be on top of this if the modeled correlation is only a "working correlation" structure and not assumed to be correctly specified (but it should hold approximately to improve efficiency).
josef-pkt commentedon Oct 7, 2015
Sounds like fun, but something for "GMM round 4" not for a cleanup round 3.
One related issue: Before I was thinking more about adding more parametric assumptions on the calculation of the weight matrix (and associated cov_params). In this case we would deviate from the nonparametric, "unspecified" correlation or heteroscedasticity. This might result in similar outcome in some models as the prewhiten version, maybe in standard linear model. However, generic GMM works with sums and weights moment conditions, while pre-whitening changes the weight that observations get.
(e.g. exactly identified GMM replicates OLS parameters but has robust cov_params)
(In cluster/panel/system models we could treat each cluster as one observation and each observation within the cluster as a moment condition, then correlation across moment conditions would capture correlation within clusters. )
Davidson and MacKinnon make the point of using optimal instruments also to handle correlated observations clearer than any other book that I remember. To emphasis: parametric assumption and improvements to the estimation of the weight matrix uses more information for "efficient GMM" (ie. optimal weight matrix), but that does not say anything about optimal instruments.
(to be continued in private repo, to avoid even more detours here.)
josef-pkt commentedon Apr 5, 2018
#4425 API changes
josef-pkt commentedon Aug 29, 2021
summaryneeds improvementse,g, it doesn't specify with weight type, cov_type has been used.
running an example with hac
https://stackoverflow.com/questions/68933669/issue-with-using-statsmodels-sandbox-regression-gmm-gmm-in-python
[-]ENH/REF GMM round 3: cleanup and more enhancements[/-][+]ENH/REF/SUMM GMM round 3: cleanup and more enhancements[/+]josef-pkt commentedon Apr 20, 2023
implementation detail to check:
approx_fprime has centered option (default is False)
GMM.gradient_momcondexplicitly computes acenterednumdiff.Does delegating to approx_fprime with
centered=Truecompute the same numdiff (except maybe different epsilon magnitude)?Aside: We are starting to make heavier use for GMM internally, e.g. treatment effect, control function/iv.