Skip to content

ENH: OLS Influence, more statistics without explicit looo loop #9009

Closed

Description

@josef-pkt

question on mailing list

"
I am wondering why the computation times of the dfbeta and dfbetas influence statistics are extremely large. The reason seems to be that the implementation uses results form leave-one-out regression loops, requiring N auxilliary regressions (where N is the number of observations of the data set). In the classical monography by Belsley et al. it is shown that these statistics can be computed extremely fast, even without running OLS regressions.

Why are the algorithms presented in the book not implemented?
"

related: Closed form studentized residuals external #373

Activity

  1. added this to the 0.15 milestone on Sep 22, 2023
  2. josef-pkt commented on Sep 23, 2023

    @josef-pkt
    MemberAuthor

    looo for scale: BKW equ (2.8) p. 14

  3. ludsteckj-home commented on Mar 28, 2024

    @ludsteckj-home

    I tried to ad versions of OLS outlier statistics that get without the observation-wise LOOO loops. I am anxious, howerver, that my amenendements would destroy the architecture of the current implementation. Why? To the best of my knowledge, the current implementation, includes both internal and external versions of several (auxiliary) statistics. According to Belsley et al.'s book, all statistics dfbeta, dffit, covratio, cooksd can be computed without observation-wise LOOO computations.
    Therefore I add sketches of the implementations here, hoping that they are helpful for you.

    @cache_readonly
    def dfbeta(self):
    """ dfbeta statistic """
    hii = self.hat_matrix_diag
    invXtX = np.linalg.inv(self.exog.T @ self.exog)
    dfbeta = ((invXtX @ exog.T * self.resid) / (1-hii)).T
    return dfbeta

    @cache_readonly
    def dfbetas(self):
        
        res = self.resid
        hii = self.hat_matrix_diag
        looo_sdres = self.sigma2_not_obsi**0.5
        
        invXtX = np.linalg.inv(self.exog.T @ self.exog)
    
        looo_bse = np.outer(looo_sdres, np.diag(invXtX)**0.5)
        
        dfbetas = self.dfbeta / looo_bse
        return dfbetas
    
    @cache_readonly
    def sigma2_not_obsi(self):
        """ LOOO error variance """
        
        def looom(x): # LOOO mean 
            n = len(x)
            return(x if n <= 2 else (n*x.mean() - x)/(n-1))
    
        return (looom(self.resid**2) - looom(self.resid)**2)
    
    
    
    @cache_readonly
    def cov_ratio(self):
        """covariance ratio between LOOO and original
    
        This uses determinant of the estimate of the parameter covariance
        from leave-one-out estimates.
        requires leave one out loop for observations
        """
        hii = self.hat_matrix_diag 
        res_stud = self.resid_studentized
        nobs, k_vars = self.nobs, self.k_vars
    
        cov_ratio = ((1-hii) * ((nobs-k_vars-1) + res_stud**2)/(nobs-k_vars))
        cov_ratio = 1 / cov_ratio
        return cov_ratio
    

    don't hesitate to contact me if

    Best regards,
    Johannes

  4. ludsteckj-home commented on Mar 28, 2024

    @ludsteckj-home

    References for the formulas (All refer to Belsley, Kuh and Welsch: Regression Diagnostics ISBN 978-0-471-69117-4)
    dfbeta: Page 13, formulas 2.1 and 2.7
    dfits: Page 15, formula 2.11
    covratio: Page 22, formula 2.38

  5. ludsteckj-home commented on Mar 28, 2024

    @ludsteckj-home

    A computationally efficient alterntive to using observation-wise LOOO loops for nonlinear models (MLE and GLM) would be to linearize these models using first order Taylor approximations. Then the closed form solutions for the OLS case could be used. Did you consider this choice?

  6. josef-pkt commented on Mar 29, 2024

    @josef-pkt
    MemberAuthor

    Thanks, I will go over the details of your code soon(ish).

    To the best of my knowledge, the current implementation, includes both internal and external versions of several (auxiliary) statistics.

    This was mainly based on the documentation of other packages, e.g. SAS.

    for GLM, I have two versions, GLM influence tries to take some shortcuts using the irls WLS version. (I don't remember right now about looo scale, There might be only "internal" versions for families that don't have scale fixed at 1.).
    Generic MLEInfluence can also be used for it.

    MLEInfluence is generic and uses only derivative information (AFAIR), e.g. df_params are from a one-step Newton iteration as approximation. This was mainly based on references for specific distributions or models.

    we don't have WLSInfluence yet, I did not see a reference for which statistic should be based on resid, exog or wresid, wexog.
    i.e. parts that should differ from applying OLSInfluence on only the weighted data, wendog, wexog.
    #9067

  7. added a commit that references this issue on Oct 6, 2026
    fc755c7
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