Skip to content

ENH: Add "(uncentered)" after rsquared label in .summary, .summary2 when appropriate - #5083

Merged
josef-pkt merged 2 commits into
statsmodels:masterfrom
bertrandhaut:feature/uncentered_label
Sep 7, 2018
Merged

josef-pkt merged 2 commits into
statsmodels:masterfrom
bertrandhaut:feature/uncentered_label

Conversation

@bertrandhaut

Copy link
Copy Markdown
Contributor

Add "(uncentered)" after rsquared label in .summary, .summary2 when appropriate

Related to #5078

I didn't find any Unit Test related to the formatting/labeling of the .summary{2} functions.

The following script

import statsmodels.formula.api as smf
import statsmodels.api as sm

dat = sm.datasets.get_rdataset("Guerry", "HistData").data

results = smf.ols('Lottery ~ Literacy + Pop1831', data=dat).fit()
print('#################################################')
print('#########   CENTERED      #######################')
print('#################################################')
print('')
print(results.summary())
print(results.summary2())



print('#################################################')
print('#########   UNCENTERED      #####################')
print('#################################################')
print('')
results = smf.ols('Lottery ~ Literacy + Pop1831 -1', data=dat).fit()
print(results.summary())
print(results.summary2())

leads to the following outputs:

#################################################
#########   CENTERED      #######################
#################################################

                            OLS Regression Results                            
==============================================================================
Dep. Variable:                Lottery   R-squared:                       0.325
Model:                            OLS   Adj. R-squared:                  0.308
Method:                 Least Squares   F-statistic:                     19.95
Date:                Sat, 01 Sep 2018   Prob (F-statistic):           8.40e-08
Time:                        21:25:42   Log-Likelihood:                -381.36
No. Observations:                  86   AIC:                             768.7
Df Residuals:                      83   BIC:                             776.1
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept     89.8137      7.683     11.690      0.000      74.532     105.095
Literacy      -0.4683      0.130     -3.596      0.001      -0.727      -0.209
Pop1831       -0.0738      0.015     -4.854      0.000      -0.104      -0.044
==============================================================================
Omnibus:                        3.172   Durbin-Watson:                   1.981
Prob(Omnibus):                  0.205   Jarque-Bera (JB):                2.810
Skew:                          -0.350   Prob(JB):                        0.245
Kurtosis:                       2.456   Cond. No.                     1.40e+03
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 1.4e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
                 Results: Ordinary least squares
=================================================================
Model:              OLS              Adj. R-squared:     0.308   
Dependent Variable: Lottery          AIC:                768.7289
Date:               2018-09-01 21:25 BIC:                776.0919
No. Observations:   86               Log-Likelihood:     -381.36 
Df Model:           2                F-statistic:        19.95   
Df Residuals:       83               Prob (F-statistic): 8.40e-08
R-squared:          0.325            Scale:              431.20  
------------------------------------------------------------------
              Coef.   Std.Err.     t     P>|t|    [0.025   0.975] 
------------------------------------------------------------------
Intercept    89.8137    7.6833  11.6895  0.0000  74.5320  105.0954
Literacy     -0.4683    0.1302  -3.5958  0.0005  -0.7273   -0.2093
Pop1831      -0.0738    0.0152  -4.8535  0.0000  -0.1040   -0.0435
-----------------------------------------------------------------
Omnibus:               3.172        Durbin-Watson:          1.981
Prob(Omnibus):         0.205        Jarque-Bera (JB):       2.810
Skew:                  -0.350       Prob(JB):               0.245
Kurtosis:              2.456        Condition No.:          1401 
=================================================================
* The condition number is large (1e+03). This might indicate
strong multicollinearity or other numerical problems.
#################################################
#########   UNCENTERED      #####################
#################################################

                                 OLS Regression Results                                
=======================================================================================
Dep. Variable:                Lottery   R-squared (uncentered):                   0.561
Model:                            OLS   Adj. R-squared (uncentered):              0.551
Method:                 Least Squares   F-statistic:                              53.67
Date:                Sat, 01 Sep 2018   Prob (F-statistic):                    9.65e-16
Time:                        21:25:42   Log-Likelihood:                         -423.21
No. Observations:                  86   AIC:                                      850.4
Df Residuals:                      84   BIC:                                      855.3
Df Model:                           2                                                  
Covariance Type:            nonrobust                                                  
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Literacy       0.4432      0.169      2.628      0.010       0.108       0.779
Pop1831        0.0488      0.018      2.742      0.007       0.013       0.084
==============================================================================
Omnibus:                        4.076   Durbin-Watson:                   1.845
Prob(Omnibus):                  0.130   Jarque-Bera (JB):                2.348
Skew:                          -0.161   Prob(JB):                        0.309
Kurtosis:                       2.258   Cond. No.                         19.1
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                       Results: Ordinary least squares
==============================================================================
Model:                  OLS              Adj. R-squared (uncentered): 0.551   
Dependent Variable:     Lottery          AIC:                         850.4216
Date:                   2018-09-01 21:25 BIC:                         855.3303
No. Observations:       86               Log-Likelihood:              -423.21 
Df Model:               2                F-statistic:                 53.67   
Df Residuals:           84               Prob (F-statistic):          9.65e-16
R-squared (uncentered): 0.561            Scale:                       1127.5  
-----------------------------------------------------------------------------------
               Coef.       Std.Err.        t         P>|t|       [0.025      0.975]
-----------------------------------------------------------------------------------
Literacy       0.4432        0.1687      2.6276      0.0102      0.1078      0.7786
Pop1831        0.0488        0.0178      2.7421      0.0075      0.0134      0.0842
------------------------------------------------------------------------------
Omnibus:                  4.076             Durbin-Watson:               1.845
Prob(Omnibus):            0.130             Jarque-Bera (JB):            2.348
Skew:                     -0.161            Prob(JB):                    0.309
Kurtosis:                 2.258             Condition No.:               19   
==============================================================================

@josef-pkt

Copy link
Copy Markdown
Member

The summary functions have almost only smoke test.
What you could do is to look in the unit tests for regression OLS for a test case where rsquared is uncentered, and then just add an assert that the strings "R-squared (uncentered):" "Adj. R-squared (uncentered):" are in the summary string

@josef-pkt

Copy link
Copy Markdown
Member

change looks fine to me
The top table in summary is a bit wide now, but uncentered is an unusual case and trying to fix the spacing is most likely difficult because there is a lot of hardcoded formatting in summary to make the tables align in the common cases. So, I don't think we need to worry about that.

@coveralls

coveralls commented Sep 1, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.03%) to 83.899% when pulling 063cfa8 on bertrandhaut:feature/uncentered_label into 8e6f521 on statsmodels:master.

@codecov

codecov Bot commented Sep 2, 2018

Copy link
Copy Markdown

Codecov Report

Merging #5083 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5083      +/-   ##
==========================================
+ Coverage    81.4%   81.41%   +0.01%     
==========================================
  Files         582      582              
  Lines       90309    90311       +2     
  Branches    10109    10109              
==========================================
+ Hits        73517    73528      +11     
+ Misses      14490    14484       -6     
+ Partials     2302     2299       -3
Impacted Files Coverage Δ
statsmodels/regression/linear_model.py 91.33% <ø> (+0.01%) ⬆️
statsmodels/iolib/summary2.py 90.84% <100%> (+0.03%) ⬆️
statsmodels/regression/mixed_linear_model.py 89.77% <0%> (+0.79%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e6f521...063cfa8. Read the comment docs.

@bertrandhaut

Copy link
Copy Markdown
Contributor Author

Proposal of UT in test_summary2 committed

@josef-pkt

Copy link
Copy Markdown
Member

tests also look good (unrelated CI failures)
merging

@bertrandhaut Thank you

@josef-pkt
josef-pkt merged commit f7076be into statsmodels:master Sep 7, 2018
@josef-pkt josef-pkt added this to the 0.10 milestone Sep 7, 2018
@josef-pkt josef-pkt changed the title Add "(uncentered)" after rsquared label in .summary, .summary2 when appropriate ENH: Add "(uncentered)" after rsquared label in .summary, .summary2 when appropriate Sep 7, 2018
@bertrandhaut
bertrandhaut deleted the feature/uncentered_label branch September 7, 2018 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants