title: Python 2.7 - statsmodels - formatting and writing summary output
body: <p>I'm doing logistic regression using <code>pandas 0.11.0</code>(data handling) and <code>statsmodels 0.4.3</code> to do the actual regression, on Mac OSX Lion.</p>
  
  <p>I'm going to be running ~2,900 different logistic regression models and need the results output to csv file and formatted in a particular way.</p>
  
  <p>Currently, I'm only aware of doing <code>print result.summary()</code> which prints the results (as follows) to the shell:</p>
  
  <pre><code> Logit Regression Results                           
    ==============================================================================
   Dep. Variable:            death_death   No. Observations:                 9752
   Model:                          Logit   Df Residuals:                     9747
   Method:                           MLE   Df Model:                            4
   Date:                Wed, 22 May 2013   Pseudo R-squ.:                -0.02672
   Time:                        22:15:05   Log-Likelihood:                -5806.9
   converged:                       True   LL-Null:                       -5655.8
                                           LLR p-value:                     1.000
   ===============================================================================
                     coef    std err          z      P&gt;|z|      [95.0% Conf. Int.]
   -------------------------------------------------------------------------------
   age_age5064    -0.1999      0.055     -3.619      0.000        -0.308    -0.092
   age_age6574    -0.2553      0.053     -4.847      0.000        -0.359    -0.152
   sex_female     -0.2515      0.044     -5.765      0.000        -0.337    -0.166
   stage_early    -0.1838      0.041     -4.528      0.000        -0.263    -0.104
   access         -0.0102      0.001    -16.381      0.000        -0.011    -0.009
   ===============================================================================
  </code></pre>
  
  <p>I will also need the odds ratio, which is computed by <code>print np.exp(result.params)</code>, and is printed in the shell as such:</p>
  
  <pre><code>age_age5064    0.818842
  age_age6574    0.774648
  sex_female     0.777667
  stage_early    0.832098
  access         0.989859
  dtype: float64
  </code></pre>
  
  <p>What I need is for these each to be written to a csv file in form of a very lon row like (am not sure, at this point, whether I will need things like <code>Log-Likelihood</code>, but have included it for the sake of thoroughness):</p>
  
  <pre><code>`Log-Likelihood, age_age5064_coef, age_age5064_std_err, age_age5064_z, age_age5064_p&gt;|z|,...age_age6574_coef, age_age6574_std_err, ......access_coef, access_std_err, ....age_age5064_odds_ratio, age_age6574_odds_ratio, ...sex_female_odds_ratio,.....access_odds_ratio`
  </code></pre>
  
  <p>I think you get the picture - a very long row, with all of these actual values, and a header with all the column designations in a similar format.</p>
  
  <p>I am familiar with the <code>csv module</code> in Python, and am becoming more familiar with <code>pandas</code>.  Not sure whether this info could be formatted and stored in a <code>pandas dataframe</code> and then written, using <code>to_csv</code> to a file once all ~2,900 logistic regression models have completed; that would certainly be fine.  Also, writing them as each model is completed is also fine (using <code>csv module</code>).</p>
  
  <p>UPDATE:</p>
  
  <p>So, I was looking more at statsmodels site, specifically trying to figure out how the results of a model are stored within classes.  It looks like there is a class called 'Results', which will need to be used.  I think using inheritance from this class to create another class, where some of the methods/operators get changed might be the way to go, in order to get the formatting I require.  I have very little experience in the ways of doing this, and will need to spend quite a bit of time figuring this out (which is fine).  If anybody can help/has more experience that would be awesome!</p>
  
  <p>Here is the site where the classes are laid out: <a href="http://statsmodels.sourceforge.net/stable/dev/internal.html#model">statsmodels results class</a></p>