Module Expr Str ImportFrom alias Import alias identifier Import alias identifier Import alias identifier Assign NameStore Call AttributeLoad AttributeLoad AttributeLoad NameLoad attr attr attr Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr attr Assign NameStore SubscriptLoad AttributeLoad NameLoad attr ExtSlice Slice Index Num Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr ExtSlice Slice Slice Num keyword BinOpDiv Num NameLoad attr Assign NameStore BinOpSub AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore BinOpDiv NameLoad AttributeLoad NameLoad attr Assign NameStore BinOpDiv NameLoad BinOpAdd AttributeLoad NameLoad attr Num Assign NameStore BinOpDiv NameLoad AttributeLoad NameLoad attr Assign NameStore BinOpSub Num BinOpMult BinOpDiv AttributeLoad NameLoad attr AttributeLoad NameLoad attr BinOpSub Num NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr ExtSlice Slice Index TupleLoad Num Num Num Num keyword BinOpDiv Num NameLoad attr Expr Call NameLoad Call AttributeLoad NameLoad attr Expr Call NameLoad Str Expr Call NameLoad BinOpDiv BinOpSub AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr ListLoad Num Num Expr Call AttributeLoad NameLoad attr ListLoad Num Num Expr Call NameLoad Str Expr Call NameLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call NameLoad Str Expr Call NameLoad BinOpPow SubscriptLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Index TupleLoad Num Num Num Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr ListLoad Num Num Expr Call AttributeLoad NameLoad attr ListLoad Num Num FunctionDef arguments args NameParam defaults body Expr Str If BoolOpAnd Call NameLoad NameLoad Str Call NameLoad NameLoad Str body Assign NameStore AttributeLoad NameLoad attr Assign NameStore AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore AttributeLoad NameLoad attr orelse Assign NameStore SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad NameLoad Index Num Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index Num Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Assign NameStore BinOpMult Call AttributeLoad NameLoad attr NameLoad NameLoad Return TupleLoad BinOpSub Num BinOpDiv NameLoad NameLoad NameLoad NameLoad BinOpSub NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Slice UnaryOpUSub NameLoad Assign NameStore Call AttributeLoad NameLoad attr SubscriptLoad NameLoad Slice UnaryOpUSub NameLoad Return TupleLoad NameLoad NameLoad decorator_list Assign TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr Num Expr Call NameLoad Str NameLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Index NameLoad SubscriptLoad AttributeLoad NameLoad attr ExtSlice Index NameLoad Slice attr Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Index NameLoad SubscriptLoad AttributeLoad NameLoad attr ExtSlice Index NameLoad Slice attr Assign NameStore ListLoad NameLoad NameLoad NameLoad NameLoad For NameStore ListLoad BinOpDiv Num NameLoad BinOpDiv Num BinOpPow NameLoad Num Call AttributeLoad NameLoad attr NameLoad body Expr Call NameLoad Str Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword NameLoad attr Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr SubscriptLoad AttributeLoad NameLoad attr Index NameLoad SubscriptLoad AttributeLoad NameLoad attr ExtSlice Index NameLoad Slice keyword SubscriptLoad NameLoad Index NameLoad attr Assign TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr Num Expr Call NameLoad Str Expr Call NameLoad NameLoad SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Expr Call NameLoad Str NameLoad NameLoad Expr Call NameLoad Str Expr Call NameLoad Str AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call NameLoad Str AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call NameLoad Str Expr Call NameLoad Str SubscriptLoad Call NameLoad NameLoad Index Num Expr Call NameLoad SubscriptLoad Call NameLoad TupleLoad AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Index Num Expr Call NameLoad Str SubscriptLoad Call NameLoad NameLoad Index Num Expr Call NameLoad SubscriptLoad Call NameLoad TupleLoad AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Index Num Expr Call NameLoad Str SubscriptLoad Call NameLoad NameLoad Index Num Expr Call NameLoad SubscriptLoad Call NameLoad TupleLoad AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Index Num Expr Call AttributeLoad NameLoad attr ListLoad NameLoad NameLoad Expr Call NameLoad Str Expr Call NameLoad Str Expr Call NameLoad Call AttributeLoad NameLoad attr ListComp AttributeLoad NameLoad attr comprehension NameStore NameLoad Expr Call NameLoad Str Expr Call NameLoad Call AttributeLoad NameLoad attr ListComp Call NameLoad NameLoad Str NameLoad comprehension NameStore NameLoad Expr Call NameLoad Str Expr Call NameLoad Call AttributeLoad NameLoad attr ListComp Call NameLoad NameLoad Str NameLoad comprehension NameStore NameLoad Expr Call NameLoad Str Expr Call NameLoad Str Expr Call NameLoad Call AttributeLoad NameLoad attr ListComp Call NameLoad NameLoad NameLoad NameLoad comprehension NameStore ListLoad Str Str Str Str Assign TupleStore NameStore NameStore AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad BinOpMult NameLoad Num For NameStore Call NameLoad NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad keyword NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr ExtSlice Index NameLoad Slice Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr NameLoad NameLoad attr Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice NameLoad AttributeLoad NameLoad attr Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Call NameLoad keyword Num Expr Call NameLoad Str Expr Call NameLoad Str Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call AttributeLoad NameLoad attr For NameStore Call NameLoad Num body Expr Call AttributeLoad NameLoad attr Num Num BinOpAdd NameLoad Num Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index NameLoad Num Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Expr Call AttributeLoad NameLoad attr Num Num Str keyword Str keyword Str keyword Str keyword Str Assign NameStore SubscriptLoad AttributeLoad NameLoad attr Index NameLoad Assign NameStore SubscriptLoad AttributeLoad NameLoad attr ExtSlice Index NameLoad Slice Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign TupleStore NameStore NameStore AttributeLoad NameLoad attr Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr TupleLoad NameLoad BinOpMult NameLoad Num For NameStore Call NameLoad NameLoad body Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad keyword NameLoad Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore SubscriptLoad NameLoad ExtSlice Index NameLoad Slice Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr NameLoad NameLoad keyword BinOpDiv Num SubscriptLoad NameLoad ExtSlice Index NameLoad Slice attr Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice NameLoad AttributeLoad NameLoad attr Assign SubscriptStore NameLoad ExtSlice Index NameLoad Slice NameLoad AttributeLoad NameLoad attr Expr Call NameLoad Str Expr Call NameLoad Str Expr Call NameLoad Str Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call NameLoad Str Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Slice Num Num Expr Call AttributeLoad NameLoad attr For NameStore Call NameLoad Num body Expr Call AttributeLoad NameLoad attr Num Num BinOpAdd NameLoad Num Expr Call AttributeLoad NameLoad attr SubscriptLoad NameLoad ExtSlice Slice Index NameLoad Num Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Expr Call AttributeLoad NameLoad attr Num Num Str keyword Str keyword Str keyword Str keyword Str
N/A N/A 
Weighted Least Squares

example is extended to look at the meaning of rsquared in WLS,
at outliers, compares with RLM and a short bootstrap

 __future__ print_function N/A numpy np N/A statsmodels.api sm N/A matplotlib.pyplot plt N/A data N/A N/A N/A N/A sm datasets ccard load N/A N/A data exog N/A N/A sm add_constant N/A data exog prepend False N/A ols_fit N/A N/A N/A N/A sm OLS N/A data endog N/A data exog fit N/A incomesq N/A N/A data exog N/A N/A N/A 2 N/A N/A N/A plt scatter incomesq N/A ols_fit resid N/A N/A N/A plt grid N/A wls_fit N/A N/A N/A N/A sm WLS N/A data endog N/A N/A data exog N/A N/A N/A -1 weights N/A 1 incomesq fit N/A ess N/A N/A wls_fit uncentered_tss N/A wls_fit ssr N/A rsquared N/A ess N/A wls_fit uncentered_tss N/A mse_model N/A ess N/A N/A wls_fit df_model 1 N/A fvalue N/A mse_model N/A wls_fit mse_resid N/A rsquared_adj N/A 1 N/A N/A N/A wls_fit nobs N/A wls_fit df_resid N/A 1 rsquared N/A wls_fit3 N/A N/A N/A N/A sm WLS N/A data endog N/A N/A data exog N/A N/A N/A N/A 0 1 3 4 weights N/A 1 incomesq fit N/A N/A print N/A N/A wls_fit3 summary N/A N/A print corrected rsquared N/A N/A print N/A N/A N/A wls_fit3 uncentered_tss N/A wls_fit3 ssr N/A wls_fit3 uncentered_tss N/A N/A N/A plt figure N/A N/A N/A plt title WLS dropping heteroscedasticity variable from regressors N/A N/A N/A plt plot N/A data endog N/A wls_fit3 fittedvalues o N/A N/A N/A plt xlim N/A 0 2000 N/A N/A N/A plt ylim N/A 0 2000 N/A N/A print raw correlation of endog and fittedvalues N/A N/A print N/A N/A np corrcoef N/A data endog N/A wls_fit fittedvalues N/A N/A print raw correlation coefficient of endog and fittedvalues squared N/A N/A print N/A N/A N/A N/A np corrcoef N/A data endog N/A wls_fit fittedvalues N/A N/A 0 1 2 N/A rlm_fit N/A N/A N/A N/A sm RLM N/A data endog N/A data exog fit N/A N/A N/A plt figure N/A N/A N/A plt title using robust for comparison N/A N/A N/A plt plot N/A data endog N/A rlm_fit fittedvalues o N/A N/A N/A plt xlim N/A 0 2000 N/A N/A N/A plt ylim N/A 0 2000 getrsq N/A N/A fitresult N/A N/A N/A 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)
     N/A N/A N/A hasattr fitresult resid N/A hasattr fitresult model N/A N/A resid N/A fitresult resid N/A endog N/A N/A fitresult model endog N/A nobs N/A fitresult nobs N/A N/A resid N/A fitresult N/A 0 N/A endog N/A fitresult N/A 1 N/A nobs N/A N/A resid shape N/A 0 N/A rss N/A N/A np dot resid resid N/A tss N/A N/A N/A np var endog nobs N/A N/A N/A 1 N/A rss tss rss tss N/A tss rss N/A index_trim_outlier N/A N/A resid k N/A N/A N/A returns indices to residual array with k outliers removed

    Parameters
    ----------
    resid : array_like, 1d
        data vector, usually residuals of a regression
    k : int
        number of outliers to remove

    Returns
    -------
    trimmed_index : array, 1d
        index array with k outliers removed
    outlier_index : array, 1d
        index array of k outliers

    Notes
    -----

    Outliers are defined as the k observations with the largest
    absolute values.

     N/A sort_index N/A N/A np argsort N/A N/A np abs resid N/A trimmed_index N/A N/A np sort N/A sort_index N/A N/A k N/A outlier_index N/A N/A np sort N/A sort_index N/A N/A k N/A N/A trimmed_index outlier_index N/A N/A N/A olskeep olsoutl N/A index_trim_outlier N/A ols_fit resid 2 N/A N/A print ols outliers olsoutl N/A N/A ols_fit resid N/A olsoutl N/A ols_fit_rm2 N/A N/A N/A N/A sm OLS N/A N/A data endog N/A olskeep N/A N/A data exog N/A N/A olskeep N/A fit N/A rlm_fit_rm2 N/A N/A N/A N/A sm RLM N/A N/A data endog N/A olskeep N/A N/A data exog N/A N/A olskeep N/A fit N/A results N/A ols_fit ols_fit_rm2 rlm_fit rlm_fit_rm2 N/A weights N/A N/A 1 incomesq N/A 1 N/A incomesq 2 N/A N/A np sqrt incomesq N/A N/A N/A print 
Comparison OLS and WLS with and without outliers N/A wls_fit0 N/A N/A N/A N/A sm WLS N/A data endog N/A data exog weights weights fit N/A wls_fit_rm2 N/A N/A N/A N/A sm WLS N/A N/A data endog N/A olskeep N/A N/A data exog N/A N/A olskeep N/A weights N/A weights N/A olskeep fit N/A N/A wlskeep wlsoutl N/A index_trim_outlier N/A ols_fit resid 2 N/A N/A print 2 outliers candidates and residuals N/A N/A print wlsoutl N/A N/A wls_fit resid N/A olsoutl N/A N/A print outliers ols, wls: olsoutl wlsoutl N/A N/A print rsquared N/A N/A print ols vs ols rm2 N/A ols_fit rsquared N/A ols_fit_rm2 rsquared N/A N/A print wls vs wls rm2 N/A wls_fit0 rsquared N/A wls_fit_rm2 rsquared N/A N/A print compare R2_resid  versus  R2_wresid N/A N/A print ols minus 2 N/A N/A getrsq ols_fit_rm2 N/A 0 N/A N/A print N/A N/A getrsq N/A N/A ols_fit_rm2 wresid N/A N/A ols_fit_rm2 model wendog N/A 0 N/A N/A print wls         N/A N/A getrsq wls_fit N/A 0 N/A N/A print N/A N/A getrsq N/A N/A wls_fit wresid N/A N/A wls_fit model wendog N/A 0 N/A N/A print wls minus 2 N/A N/A getrsq wls_fit_rm2 N/A 0 N/A N/A print N/A N/A getrsq N/A N/A wls_fit_rm2 wresid N/A N/A wls_fit_rm2 model wendog N/A 0 N/A N/A N/A results extend N/A wls_fit0 wls_fit_rm2 N/A N/A print      ols             ols_rm2       rlm           rlm_rm2     wls (lin)    wls_rm2 (lin)   wls (squ)   wls_rm2 (squ)  wls (sqrt)   wls_rm2 (sqrt) N/A N/A print Parameter estimates N/A N/A print N/A N/A np column_stack N/A N/A r params N/A r results N/A N/A print R2 original data, next line R2 weighted data N/A N/A print N/A N/A np column_stack N/A N/A getattr r rsquared None N/A r results N/A N/A print Standard errors N/A N/A print N/A N/A np column_stack N/A N/A getattr r bse None N/A r results N/A N/A print Heteroscedasticity robust standard errors (with ols) N/A N/A print with outliers N/A N/A print N/A N/A np column_stack N/A N/A getattr ols_fit se None N/A se N/A HC0_se HC1_se HC2_se HC3_se N/A N/A nobs nvar N/A N/A data exog shape N/A niter 2000 N/A bootres N/A N/A np zeros N/A niter N/A nvar 2 N/A it N/A range niter N/A N/A rind N/A N/A N/A np random randint nobs size nobs N/A endog N/A N/A data endog N/A rind N/A exog N/A N/A data exog N/A N/A rind N/A N/A res N/A N/A N/A N/A sm OLS endog exog fit N/A N/A bootres N/A N/A it N/A nvar N/A res params N/A N/A bootres N/A N/A it N/A nvar N/A res bse N/A N/A N/A np set_print N/A options linewidth 200 N/A N/A print Bootstrap Results of parameters and parameter standard deviation  OLS N/A N/A print Parameter estimates N/A N/A print median N/A N/A np median N/A bootres N/A N/A N/A 5 0 N/A N/A print mean   N/A N/A np mean N/A bootres N/A N/A N/A 5 0 N/A N/A print std    N/A N/A np std N/A bootres N/A N/A N/A 5 0 N/A N/A print Standard deviation of parameter estimates N/A N/A print median N/A N/A np median N/A bootres N/A N/A N/A 5 0 N/A N/A print mean   N/A N/A np mean N/A bootres N/A N/A N/A 5 0 N/A N/A print std    N/A N/A np std N/A bootres N/A N/A N/A 5 0 N/A N/A N/A plt figure N/A i N/A range 4 N/A N/A N/A N/A plt subplot 2 2 N/A i 1 N/A N/A N/A plt hist N/A bootres N/A N/A N/A i 50 N/A N/A N/A plt title N/A var%d i N/A N/A N/A plt figtext 0.5 0.935 OLS Bootstrap ha center color black weight bold size large N/A data_endog N/A N/A data endog N/A olskeep N/A data_exog N/A N/A data exog N/A N/A olskeep N/A N/A incomesq_rm2 N/A incomesq N/A olskeep N/A N/A nobs nvar N/A data_exog shape N/A niter 500 N/A bootreswls N/A N/A np zeros N/A niter N/A nvar 2 N/A it N/A range niter N/A N/A rind N/A N/A N/A np random randint nobs size nobs N/A endog N/A data_endog N/A rind N/A exog N/A data_exog N/A N/A rind N/A N/A res N/A N/A N/A N/A sm WLS endog exog weights N/A 1 N/A incomesq N/A N/A rind N/A fit N/A N/A bootreswls N/A N/A it N/A nvar N/A res params N/A N/A bootreswls N/A N/A it N/A nvar N/A res bse N/A N/A print Bootstrap Results of parameters and parameter standard deviation N/A N/A print WLS removed 2 outliers from sample N/A N/A print Parameter estimates N/A N/A print median N/A N/A np median N/A bootreswls N/A N/A N/A 5 0 N/A N/A print mean   N/A N/A np mean N/A bootreswls N/A N/A N/A 5 0 N/A N/A print std    N/A N/A np std N/A bootreswls N/A N/A N/A 5 0 N/A N/A print Standard deviation of parameter estimates N/A N/A print median N/A N/A np median N/A bootreswls N/A N/A N/A 5 0 N/A N/A print mean   N/A N/A np mean N/A bootreswls N/A N/A N/A 5 0 N/A N/A print std    N/A N/A np std N/A bootreswls N/A N/A N/A 5 0 N/A N/A N/A plt figure N/A i N/A range 4 N/A N/A N/A N/A plt subplot 2 2 N/A i 1 N/A N/A N/A plt hist N/A bootreswls N/A N/A N/A i 50 N/A N/A N/A plt title N/A var%d i N/A N/A N/A plt figtext 0.5 0.935 WLS rm2 Bootstrap ha center color black weight bold size large