code: def getrsq(fitresult):
      """calculates rsquared residual, total and explained sums of squares
  
      Parameters
      ----------
      fitresult : instance of Regression Result class, or tuple of (resid, endog)
          arrays regression residuals and endogenous variable
  
      Returns
      -------
      rsquared
      residual sum of squares
      (centered) total sum of squares
      explained sum of squares (for centered)
      """
      if hasattr(fitresult, "resid") and hasattr(fitresult, "model"):
          resid = fitresult.resid
          endog = fitresult.model.endog
          nobs = fitresult.nobs
      else:
          resid = fitresult[0]
          endog = fitresult[1]
          nobs = resid.shape[0]
  
      rss = np.dot(resid, resid)
      tss = np.var(endog) * nobs
      return 1 - rss / tss, rss, tss, tss - rss
  
imports: import numpy
  import statsmodels.api
  import matplotlib.pyplot
label_desc: Use image node_id 1 for calling a global function with example usage: getrsq(fitresult) and returns: unknown,  rss,  tss,  unknown