Skip to content

FAQ-D df_resid df_model in results and in model #1723

Open

Description

@josef-pkt

(developer FAQ) (answer not settled yet)

Why are the df_xxx different in the results from those in the model?

Where do I set df_xxx?

Activity

  1. josef-pkt commented on Jun 2, 2014

    @josef-pkt
    MemberAuthor

    I'm trying to figure out what should be attributes of the model instance and what of the results instance.

    I started with some cases where I adjust the df_resid, df_model in the results instance, but don't adjust the ones in the model instance, which are just a property of shape and rank of exog.

    issues with df_resid or df_model #921 #1624 #1203
    related naming conventions #487

  2. josef-pkt commented on Jun 4, 2017

    @josef-pkt
    MemberAuthor

    new discussions in #3735, #1664, #3734, ...

  3. josef-pkt commented on Jul 17, 2021

    @josef-pkt
    MemberAuthor

    trying again
    I ran again into several problems using GenericLikelihood model and results for betareg which has two exog and two constants in null model #7543, #7584 (comment)

    what we need

    counting parameters:

    • len(params) number of parameters in results instance
    • number of estimated parameters, this can differ from len(params) if there are constraints, fixed params that are included in params array (with bse=0) or reduced rank cov_params, this might be the same as rank cov_params
    • number of auxiliary params, estimated outside main estimation, e.g. scale when (asymptotically, in expectation) orthogonal to means (GLM, OLS/WLS), could be more than 1 in GEE and GLSHet/GLSAR,
      currently ignored for inference, aic, ... (aic, ... should get ddof keyword option)

    for inference:

    • df_model defined as number of estimated parameters minus number of parameters in the null model
      current definition is number of estimated parameters minus has_const, which is not the right thing if the null model has two constants as in beta regression, or extra shape parameters as in NegBin, GPP, TModel with estimated df
      correction DiscreteModel defines df_model as exog_rank -1, extra_params are not counted. So, this is the number of slope parameters assuming constant is present and we only have one exog.
    • df_null number of estimated parameters in null model, we don't have it yet, R betareg uses it.
    • df_resid: nobs minus number of params.
      more general this should be: effective weighted obs minus number of effective params, e.g. when we have importance or freq_weights or penalization.
      • used both for inference and for df correction for scale estimate (e.g. when using variance of pearson residuals)
    • df_resid_inference: currently used for "effective nobs" in cluster robust (or panel?) cov_type for Wald inference, e.g. to account for variation in only one dimension of a panel dataset,
    • corrected df_resid like Satterthwaite, maybe in mixed models, could apply to more general models like `df_resid_inference.
      only or mainly available in standalone functions for simple hypothesis tests (e.g. t-test, oneway anova)

    The main current mess is with df_model which is not consistently defined, and hardcodes that in some parts that we have one constant. (I think the only substantive result that depends on it and handles cases correctly is regression model rsquared in simple case with or without constant.

    The basic model has one constant, and I think this case is handled properly.

    Then we have modifications

    • model without a constant: what's the null model in that case?
      • In OLS/WLS the null prediction is E(y | x) = 0
      • In Logit it would be E(y | x) = 0.5, or more general E(y | x) = link_inverse(0) or E(y | x) = link_inverse(offset). Those are not commonly used and we ignore that null so far
      • If we use constants-only as definition of the null model for (nonlinear, link) models independently of has_constant (which we currently do outside of linear regression rsquared), then the null model might not be nested in the full model (if the full model does not have a explicit or implicit constant)
    • constraints
    • penalization
    • multi-parameter distributions, multiple links, multiple exog, multiple constant or extra_params
    • improved inference, bias corrections, ...
  4. josef-pkt commented on Jul 17, 2021

    @josef-pkt
    MemberAuthor

    Check definitions in NB and GPP to see where extra_params are included.

    e.g. according to aic, it looks like df_model does not include k_extra

            k_extra = getattr(self.model, 'k_extra', 0)
            return -2*(self.llf - (self.df_model + self.k_constant + k_extra))
    

    in that case llr_pvalue is correct because k_params_full - k_params_null = df_model, where k_params_null = k_constant + k_extra
    unit tests for Negbin and similar have llr_pvalue = 0 in the test case, so correct df_constraints or off-by-one does not affect results.

  5. josef-pkt commented on Jul 18, 2021

    @josef-pkt
    MemberAuthor

    checking discrete.coutnmodel ZeroInflated

    • module does not define df_model, so most likely this only counts exog of main model
    • unit tests for aic and llf against Stata (?)
    • null model is tested to have 2 constant parameters, ie. constant prob of inflation
    • no unit test for llr_pvalue, and no direct tests for df_xxx

    possibly a BUG for llr_pvalue and df_model
    AFAICS:
    ZeroInflatedResults use aic from DiscreteResults aic = -2*(self.llf - (self.df_model+1))
    which would make llr_pvalue inconsistent with this definition of df_model.

  6. josef-pkt commented on Aug 21, 2021

    @josef-pkt
    MemberAuthor

    again
    weibull model using GenericLikelihood, with one extra parameter
    I'm explicitly setting df_resid, but not df_model
    df_model looks correct as k_params - df_null

    I get warning
    warnings.warn("df_model + k_constant differs from nparams")

    We should replace k_constant in these cases by df_null.

    I think we should support df_null = k_constant = 0 only in linear models (OLS/WLS/...)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions