

def getrsq(fitresult):
    'calculates rsquared residual, total and explained sums of squares\n\n    Parameters\n    ----------\n    fitresult : instance of Regression Result class, or tuple of (resid, endog) arrays\n        regression residuals and endogenous variable\n\n    Returns\n    -------\n    rsquared\n    residual sum of squares\n    (centered) total sum of squares\n    explained sum of squares (for centered)\n    '
    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))

dataset/ETHPy150Open statsmodels/statsmodels/examples/incomplete/wls_extended.py getrsq/original