Skip to content

GLSHet status ? #647

Open
Open

Description

@josef-pkt

What's the status with GLSHet?
It's not in the docs AFAICS.

there is issue #181

similar are all options for GLSAR included?

no tests, there is one example file

Stata: as far as I have seen, Stata only has arch for this case, which uses MLE as estimator .
R: I haven't figured out what's similar, maybe an option/formula to lm

bias-correction: Greene mentions a less biased or bias corrected version for log link in the var estimation
not implemented

Activity

  1. josef-pkt commented on Mar 21, 2013

    @josef-pkt
    MemberAuthor

    also inherited from_formula would also need to handle 2-equation models
    needs examples and test to be used with pandas and formula

    also now we have an additional missing options, need to drop rows also from variance exog

  2. josef-pkt commented on Mar 21, 2013

    @josef-pkt
    MemberAuthor

    The exog_var will also need the "data" treatment if we want to have the names from a pandas dataframe.

  3. added this to the 0.14 milestone on Oct 17, 2021
  4. josef-pkt commented on Oct 17, 2021

    @josef-pkt
    MemberAuthor

    GLSHet looks good when comparing to MLE for #7793
    Large sample results, nobs = 10000, agreement is high between MLE and iterated GLS, and even 2-step FGLS.

    Simulated example with correctly specified model, except that we have 2 additional explanatory variables in exog_var with coefficient = 0 in dgp. loglink for variance.

    OLS with HC1 or HC3 has bse in the same neighborhood. Nonrobust bse in OLS are less than half of that.
    OLS params estimate are consistent in this case.
    OLS here is actually no step GLSHet, I need to check defaults fit, fit_iterated.

    update
    There is something fishy with GLSHet 0-step, just calling GLSHet(...).fit(). The params correspond to OLS, but the bse are far away from OLS and from iterated GLSHet.
    looks like wrong scale

    resgls1.bse / res_ols.bse
    array([0.06652092, 0.06652092, 0.06652092, 0.06652092])
    
    np.sqrt(resgls1.scale / res_ols.scale)
    0.06652092465866388
    

    update2 wrong state of model instance when evaluating scale and bse.
    see next comment

    So GLSHet.fit() is the same as OLS and WLS without weights, if fit() has been called, but no state changing fit_iterative

    <end update>

    p_arr = np.column_stack([np.array(params_dgp[:4]), ress.params[:4],  resglsi.params, resgls2.params, resgls1.params]).T
    names = ["dgp", "mle", "gls-it", "gls-2", "ols"]
    params_frame = pd.DataFrame(p_arr, index = names)
    
    print(params_frame.T)
       dgp       mle    gls-it     gls-2       ols
    0  1.0  1.011414  1.011778  1.011775  1.014893
    1  0.5  0.483027  0.483797  0.483790  0.500452
    2 -0.5 -0.491924 -0.492013 -0.491987 -0.502950
    3  1.0  0.980652  0.980289  0.980293  0.977544
    
    
    bse_arr = np.column_stack([ress.bse[:4],  resglsi.bse, resgls2.bse, res_olshc3.bse, res_olshc1.bse, resgls1.bse]).T
    names = ["mle", "gls-it", "gls-2", "ols-hc3", "ols-hc1", "ols"]
    bse_frame = pd.DataFrame(bse_arr, index = names)
    
    print(bse_frame.T)
            mle    gls-it     gls-2   ols-hc3   ols-hc1       ols
    0  0.017306  0.017262  0.017282  0.017495  0.017491  0.007015
    1  0.015797  0.015869  0.015883  0.019824  0.019815  0.007062
    2  0.015906  0.015978  0.015992  0.018277  0.018269  0.007133
    3  0.015576  0.015656  0.015670  0.017388  0.017381  0.006997
    
  5. josef-pkt commented on Oct 19, 2021

    @josef-pkt
    MemberAuthor

    I don't know what the problem could be with GLSHe fit()
    GLSHet does not definie fit() and it is just inherited from the superclass, the relevant fit method is in top class RegressionModel

    problem is not in fit()
    The problem is that I called fit_iterative() after calling fit().
    GLSHet is a stateful model, calling fit_iterative updates the model, weights wendog, wexog, ....
    If we keep several results instance, during repeated calls of fit_iterative, then all but the last will be messed up, at least as far as some results still need to be computed at the end.

    That is,
    If we want to keep the results from intermediate stages for later analysis than we need separate model instances.

    mod = GLSHet(y, X, exog_var=X, link=links.Log())
    resgls1 = mod.fit()
    mod = GLSHet(y, X, exog_var=X, link=links.Log())
    resgls2 = mod.iterative_fit(maxiter=2)
    mod = GLSHet(y, X, exog_var=X, link=links.Log())
    resglsi = mod.iterative_fit(maxiter=100)
    

    and not the following

    mod = GLSHet(y, X, exog_var=X, link=links.Log())
    resgls1 = mod.fit()
    resgls2 = mod.iterative_fit(maxiter=2)
    resglsi = mod.iterative_fit(maxiter=100)
    
  6. josef-pkt commented on Oct 19, 2021

    @josef-pkt
    MemberAuthor

    GLSAR has the same stateful pattern, but the only stateful attribute is rho, the autocorrelation coefficients for whitening.
    GLSAR.fit_iterative solves the yule_walker equations to update rho.
    whiten is conditional on initial conditions, nobs is reduced by order of AR polynomial.

    In both models GLSHet and GLSAR it looks like the inherited fit estimates the parameters and results based on the current "state" but doesn't update the state.

  7. josef-pkt commented on Oct 19, 2021

    @josef-pkt
    MemberAuthor

    Actually, the current design with fit and fit_iterative is not so bad.

    Calling fit(...) does not update the model (state, weight remains unchanged). So, we can call it with different options, e.g. different cov_types, if we don't assume that our specified variance function is correct.

    I will add a onetime UserWarning to fit_iterative, that state/model will be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions