Tuesday, January 31, 2012

The nice thing about seeing zeros

Now, why am I happy to see a result like this?
>>> np.round(table_sm - table_sas, 3)
array([[ 0.,  0.,  0., -0.,  0., -0., -0.,  0., -0.,  0., -0.,  0.],
       [ 0.,  0., -0., -0.,  0., -0., -0.,  0.,  0.,  0., -0.,  0.],
       [ 0.,  0., -0., -0., -0.,  0., -0., -0.,  0., -0.,  0., -0.],
       [ 0.,  0., -0.,  0., -0.,  0., -0.,  0.,  0.,  0., -0.,  0.],
       [ 0.,  0., -0., -0.,  0., -0., -0.,  0.,  0., -0.,  0.,  0.],
       [ 0.,  0., -0.,  0.,  0.,  0., -0., -0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0., -0.,  0., -0., -0., -0., -0.,  0.],
       [ 0.,  0., -0., -0., -0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0., -0., -0.,  0., -0., -0.],
       [ 0.,  0.,  0.,  0.,  0.,  0., -0., -0., -0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0., -0.,  0., -0.,  0., -0.,  0.],
       [ 0.,  0.,  0., -0., -0.,  0., -0., -0., -0.,  0., -0., -0.],
       [ 0.,  0., -0.,  0.,  0.,  0.,  0., -0.,  0., -0., -0., -0.],
       [ 0.,  0.,  0.,  0., -0., -0.,  0., -0., -0.,  0.,  0.,  0.],
       [ 0.,  0.,  0., -0., -0.,  0.,  0., -0., -0., -0.,  0.,  0.],
       [ 0.,  0., -0.,  0.,  0., -0.,  0., -0.,  0.,  0., -0.,  0.],
       [ 0.,  0.,  0., -0.,  0., -0.,  0., -0., -0., -0., -0., -0.],
       [ 0.,  0.,  0., -0.,  0.,  0.,  0.,  0., -0.,  0.,  0., -0.],
       [ 0.,  0., -0., -0.,  0., -0.,  0.,  0.,  0.,  0.,  0.,  0.]])
It means I get the same results, up to print precision, as SAS in this table http://www.sfu.ca/sasdoc/sashtml/stat/chap55/sect4.htm#regg2f
table_sm = np.column_stack([
                              np.arange(res.nobs) + 1,
                              res.model.endog,
                              res.fittedvalues,
                              predict_mean_se,
                              predict_mean_ci[:,0],
                              predict_mean_ci[:,1],
                              predict_ci[:,0],
                              predict_ci[:,1],
                              res.resid,
                              resid_se,
                              infl.resid_studentized_internal,
                              infl.cooks_distance()[0]
                              ])
from numpy.testing import assert_almost_equal
assert_almost_equal(table_sm, table_sas, decimal=4)
>>> print st
=====================================================================================================================================
       Obs    Dep Var  Predicted    Std Error    Mean ci    Mean ci Predict ci Predict ci   Residual  Std Error    Student     Cook's
           Population      Value Mean Predict    95% low    95% upp    95% low    95% upp              Residual   Residual          D
-------------------------------------------------------------------------------------------------------------------------------------
         1      3.929      5.038        1.729      1.373      8.704     -1.903     11.980     -1.109      2.178     -0.509      0.055
         2      5.308      5.039        1.391      2.090      7.987     -1.553     11.631      0.269      2.408      0.112      0.001
         3      7.239      6.309        1.130      3.912      8.705     -0.055     12.672      0.930      2.541      0.366      0.009
         4      9.638      8.847        0.957      6.818     10.876      2.612     15.082      0.791      2.611      0.303      0.004
         5     12.866     12.655        0.872     10.806     14.504      6.476     18.834      0.211      2.641      0.080      0.000
         6     17.069     17.732        0.858     15.913     19.550     11.562     23.901     -0.663      2.645     -0.251      0.002
         7     23.191     24.078        0.883     22.205     25.951     17.892     30.264     -0.887      2.637     -0.336      0.004
         8     31.443     31.693        0.920     29.742     33.644     25.483     37.903     -0.250      2.624     -0.095      0.000
         9     39.818     40.577        0.949     38.566     42.589     34.348     46.807     -0.759      2.614     -0.290      0.004
        10     50.155     50.731        0.959     48.697     52.764     44.494     56.967     -0.576      2.610     -0.221      0.002
        11     62.947     62.153        0.949     60.142     64.164     55.924     68.382      0.794      2.614      0.304      0.004
        12     75.994     74.845        0.920     72.894     76.796     68.635     81.055      1.149      2.624      0.438      0.008
        13     91.972     88.806        0.883     86.933     90.679     82.620     94.992      3.166      2.637      1.201      0.054
        14    105.710    104.035        0.858    102.217    105.854     97.866    110.205      1.675      2.645      0.633      0.014
        15    122.775    120.534        0.872    118.686    122.383    114.356    126.713      2.241      2.641      0.849      0.026
        16    131.669    138.303        0.957    136.274    140.332    132.068    144.537     -6.633      2.611     -2.541      0.289
        17    151.325    157.340        1.130    154.943    159.736    150.976    163.704     -6.015      2.541     -2.367      0.370
        18    179.323    177.646        1.391    174.697    180.595    171.054    184.238      1.677      2.408      0.696      0.054
        19    203.211    199.221        1.729    195.556    202.887    192.280    206.163      3.990      2.178      1.831      0.704
===================================================================================================================================== 
 
This is again just produced with SimpleTable, and I didn't spend any time on formatting yet.

(aside: I'm still trying to figure out how to create an article without a large administrative overhead. This time I used sphinx but it doesn't quite work yet.)

No comments:

Post a Comment