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
cluster robust standard errors for Logit, Probit and GMM #863
I'm trying to connect this to what is already in statsmodels:
in _cluster_A A = numpy.matrix(grad(model.score,B)).transpose()
should be the same as the Hessian/normalized_cov_params, which we already have in all MLE models.
_cluster_D: score_cpts = grad(model.loglikeobs,B).transpose()
The MLE models in discrete have jac which, if I read it correctly, is your
However, this is not available for all models that have an MLE interpretation
_cluster_D is the inner sandwich part, which should essentially be the same as S_crosssection (different normalization), and connected in the robust cov in cov_cluster (x should be score for each observation, i.e. jac, I guess)
So based on Damien's script, if I read this correctly, we can use Hinv S Hinv, (Hinv is inverse Hessian or information) where S = J'J outerproduct of jacobian in the heteroscedasticity, or
S is calculated with any of the robust_covariance functions, cluster, HAC, ...
The sandwich_covariance currently assume that the score is exog * resid, but the inner calculation only uses the product and not the two components.
From the source of NegativeBinomial I cannot see right now if resid has the right form, the exog part is multiplicative.
However, the traceback looks like NegativeBinomial will be more difficult to combine because we have the extra parameter which I assume causes the matrices are not aligned error.
So maybe we need also the general score version for NegativeBinomial. (I doubt that the covariance for NegativeBinomial is block-diagonal, but I don't know).
more from the thread (with fixed typo), see comments in gist script
the function in sandwich_covariance might not work with pandas datastructures.
I'm not sure yet why I get some exceptions.
missing handling is now built into patsy (0.2.x) and also an option
for the models (missing='drop'), but there is no automatic handling of
the extra arrays required by the sandwiches, groups, time, ...
NegativeBinomial doesn't have jac, but it has scoreobs
Poisson already seems to work for cov_cluster, because it's score has
the exog * resid structure.
Logit also has the same structure.
My last message has the function
from statsmodels.stats.sandwich_covariance import S_crosssection
def cov_cluster_mle(jac, hessian_inv, groups, use_correction=True):
S = S_crosssection(jac, groups)
# The next part is _HCCM, which shouldn't require results
xxi = hessian_inv
cov = np.dot(np.dot(xxi, S), xxi.T)
if use_correction:
#add correction
nobs, k_params = jac.shape
n_groups = len(np.unique(groups))
corr_fact = n_groups / (n_groups - 1.) * ((nobs-1.) / float(nobs - k_params))
cov *= corr_fact
return cov
Activity
josef-pkt commentedon Oct 9, 2013
an implementation for this
https://github.com/spillz/sci-comp/tree/master/statsmodels-fun
mailing list
https://groups.google.com/d/msg/pystatsmodels/Qp3V37AVusY/y6qtiID629EJ
comment
I'm trying to connect this to what is already in statsmodels:
in
_cluster_AA = numpy.matrix(grad(model.score,B)).transpose()should be the same as the Hessian/normalized_cov_params, which we already have in all MLE models.
_cluster_D:score_cpts = grad(model.loglikeobs,B).transpose()The MLE models in discrete have
jacwhich, if I read it correctly, is yourHowever, this is not available for all models that have an MLE interpretation
_cluster_Dis the inner sandwich part, which should essentially be the same asS_crosssection(different normalization), and connected in the robust cov incov_cluster(xshould be score for each observation, i.e.jac, I guess)So based on Damien's script, if I read this correctly, we can use
Hinv S Hinv, (Hinvis inverse Hessian orinformation) whereS = J'Jouterproduct of jacobian in the heteroscedasticity, orS is calculated with any of the
robust_covariancefunctions, cluster, HAC, ...josef-pkt commentedon Dec 9, 2013
mailing list question about NegativeBinomail
https://groups.google.com/d/msg/pystatsmodels/yB8z4zjJPJs/edjnA9jzg34J
The sandwich_covariance currently assume that the score is exog * resid, but the inner calculation only uses the product and not the two components.
From the source of NegativeBinomial I cannot see right now if resid has the right form, the exog part is multiplicative.
However, the traceback looks like NegativeBinomial will be more difficult to combine because we have the extra parameter which I assume causes the
matrices are not alignederror.So maybe we need also the general score version for NegativeBinomial. (I doubt that the covariance for NegativeBinomial is block-diagonal, but I don't know).
josef-pkt commentedon Dec 9, 2013
more from the thread (with fixed typo), see comments in gist script
the function in sandwich_covariance might not work with pandas datastructures.
I'm not sure yet why I get some exceptions.
missing handling is now built into patsy (0.2.x) and also an option
for the models (missing='drop'), but there is no automatic handling of
the extra arrays required by the sandwiches, groups, time, ...
NegativeBinomial doesn't have
jac, but it hasscoreobsPoisson already seems to work for cov_cluster, because it's score has
the exog * resid structure.
Logit also has the same structure.
My last message has the function