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
I'm writing tests between WLS and OLS with user-weighting. in PR #1189
The fvalues differ. Should they?
second part: When I use robust covariances (HC1), the fvalue also differ, even though the cov_params is the same. The only difference in the code can come from the constant detection.
There must be something strange or not robust there.
I'm using one of the exog as weights (inverse: weights=exog[...])
I didn't check whether I could turn of the constant detection in my example.
I thought maybe because exog[] * weight = 1, but the OLS rescaling is with the sqrt(weights), so maybe that's not it, or it goes the other way.
I just tried: adding hasconst=True to the weighted OLS doesn't help, but it breaks the fvalue calculation in non-robust because const_idx is None
Thanks, it will take me some time to understand that, when I have or take the time.
I have a problem in my code (fvalue) and plans where I wanted to replace comparing sum of squares with wald test, if we don't have an identified constant, i.e. const_idx is None.
IIRC, Kevin uses projection (on a constant?) in one of his PR to get the difference to constant or restriction matrix, or something like that.
That is the only method I know to test for an implicit constant, although in my example I first do a simple boolean test (could also test dummies, but not sure how to always get it correct). Basically test whether the R^2 is 1 of regressing a column of 1s on the same X - should be relatively low cost since pinv has been computed.
Yes, I thought it's a nice way of checking this when I saw it and kept it in mind for other things.
Related: for 1st stage of 2SLS, I thought of using residuals==0 (relative tolerance 1e-13 or so) to check for which exog are really exogenous (i.e. both included in explanatory variables and included in instruments.)
Can we recover the restriction matrix for testing beta=0 except for the implied constant?
I think there is related code in contrasts that we inherited that I never figured out in detail.
Coming back to the fvalue, we can use the f_test if we have the restriction matrix relative to just a model with a constant, or use f_test for all params=0 if there is no constant.
In discrete we also use the Lagrange multiplier test in the summary() comparing to a model with only a constant.
This will also need to be replaced with a Wald test if we use robust covariances, in QML, AFAICS.
I would probably do an all comparrison since it is reasonable to assume that if a variable is in both the regressors and exogenous variables, then it will appear without any modification. This should be faster, especially if there are a lot of variables.
The only advantage of using a residual-based test would be to protect against end-users doing silly things, like rotating their exogenous variables.
As for recovering in the case of an explicit restriction, you can coefficients on a vector of 1, and the regression coefficients tell you the null (up to a scale that doesn't matter). For example, if you estiamted b=(0,.3,.7), then .3 * x2 + .7_x1 = 1, so the null is 0_b1=.3_b2 = .7_b3, or the restriction matrix is R=[0 .3 -.7], r=1. The number of restrictions for the intercept is equal the the number of non-zero coefficients minus 1.
f_test is technically fine if there is no constant, although it is important to use a SSE-based version and not an R2 versions since R2 definition changes (SSE doesn't). Easy to verify by simulation.
Check whether this works for the case when also WLS doesn't have a constant.
AFAICS now, OLS with reweighted endog and exog doesn't have enough information to do a proper f_test.
At least in the case of Wald test there is no implicit constant in the model. The constant would be
1 * weights.
However, I'm opening a new issue for f_test or wald_test against an implicit constant. That case (hasconstant=True, but no explicit constant) fails currently in the robust covariances which use the f_test.
Activity
TST: test compare OLS WLS for HCx, fvalues don't match see statsmodel…
jseabold commentedon Nov 28, 2013
Yes. Recall the weighted centered vs. uncentered sum of squares bug.
josef-pkt commentedon Nov 28, 2013
Is there an issue or an explanation somewhere?
I didn't check whether I could turn of the constant detection in my example.
I thought maybe because
exog[] * weight = 1, but the OLS rescaling is with the sqrt(weights), so maybe that's not it, or it goes the other way.I just tried: adding
hasconst=Trueto the weighted OLS doesn't help, but it breaks the fvalue calculation in non-robust because const_idx is Nonejseabold commentedon Nov 28, 2013
#501
josef-pkt commentedon Nov 28, 2013
Thanks, it will take me some time to understand that, when I have or take the time.
I have a problem in my code (fvalue) and plans where I wanted to replace comparing sum of squares with wald test, if we don't have an identified constant, i.e. const_idx is None.
IIRC, Kevin uses projection (on a constant?) in one of his PR to get the difference to constant or restriction matrix, or something like that.
bashtage commentedon Nov 28, 2013
That is the only method I know to test for an implicit constant, although in my example I first do a simple boolean test (could also test dummies, but not sure how to always get it correct). Basically test whether the R^2 is 1 of regressing a column of 1s on the same X - should be relatively low cost since pinv has been computed.
josef-pkt commentedon Nov 29, 2013
Yes, I thought it's a nice way of checking this when I saw it and kept it in mind for other things.
Related: for 1st stage of 2SLS, I thought of using residuals==0 (relative tolerance 1e-13 or so) to check for which
exogare really exogenous (i.e. both included in explanatory variables and included in instruments.)Can we recover the restriction matrix for testing beta=0 except for the implied constant?
I think there is related code in contrasts that we inherited that I never figured out in detail.
Coming back to the fvalue, we can use the f_test if we have the restriction matrix relative to just a model with a constant, or use f_test for all params=0 if there is no constant.
In discrete we also use the Lagrange multiplier test in the summary() comparing to a model with only a constant.
This will also need to be replaced with a Wald test if we use robust covariances, in QML, AFAICS.
TST: test compare OLS WLS for HCx, fvalues don't match see #1212
bashtage commentedon Dec 1, 2013
I would probably do an all comparrison since it is reasonable to assume that if a variable is in both the regressors and exogenous variables, then it will appear without any modification. This should be faster, especially if there are a lot of variables.
The only advantage of using a residual-based test would be to protect against end-users doing silly things, like rotating their exogenous variables.
As for recovering in the case of an explicit restriction, you can coefficients on a vector of 1, and the regression coefficients tell you the null (up to a scale that doesn't matter). For example, if you estiamted b=(0,.3,.7), then .3 * x2 + .7_x1 = 1, so the null is 0_b1=.3_b2 = .7_b3, or the restriction matrix is R=[0 .3 -.7], r=1. The number of restrictions for the intercept is equal the the number of non-zero coefficients minus 1.
f_test is technically fine if there is no constant, although it is important to use a SSE-based version and not an R2 versions since R2 definition changes (SSE doesn't). Easy to verify by simulation.
TST: test compare OLS WLS for HCx, fvalues don't match see statsmodel…
jseabold commentedon Sep 21, 2014
I don't think this is an issue. Re-open if necessary.
josef-pkt commentedon Sep 23, 2014
Check whether this works for the case when also WLS doesn't have a constant.
AFAICS now, OLS with reweighted endog and exog doesn't have enough information to do a proper f_test.
At least in the case of Wald test there is no implicit constant in the model. The constant would be
1 * weights.
However, I'm opening a new issue for f_test or wald_test against an implicit constant. That case (hasconstant=True, but no explicit constant) fails currently in the robust covariances which use the f_test.