def getrsq(fitresult):
    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
calculates rsquared residual, total and explained sums of squares
dataset/ETHPy150Open statsmodels/statsmodels/examples/incomplete/wls_extended.py/getrsq