Python 2.7 - statsmodels - formatting and writing summary output

后端 未结 5 1719
独厮守ぢ
独厮守ぢ 2021-02-05 20:55

I\'m doing logistic regression using pandas 0.11.0(data handling) and statsmodels 0.4.3 to do the actual regression, on Mac OSX Lion.

I\'m goin

5条回答
  •  余生分开走
    2021-02-05 21:45

    There is no premade table of parameters and their result statistics currently available.

    Essentially you need to stack all the results yourself, whether in a list, numpy array or pandas DataFrame depends on what's more convenient for you.

    for example, if I want one numpy array that has the results for a model, llf and results in the summary parameter table, then I could use

    res_all = []
    for res in results:
        low, upp = res.confint().T   # unpack columns 
        res_all.append(numpy.concatenate(([res.llf], res.params, res.tvalues, res.pvalues, 
                       low, upp)))
    

    But it might be better to align with pandas, depending on what structure you have across models.

    You could write a helper function that takes all the results from the results instance and concatenates them in a row.

    (I'm not sure what's the most convenient for writing to csv by rows)

    edit:

    Here is an example storing the regression results in a dataframe

    https://github.com/statsmodels/statsmodels/blob/master/statsmodels/sandbox/multilinear.py#L21

    the loop is on line 159.

    summary() and similar code outside of statsmodels, for example http://johnbeieler.org/py_apsrtable/ for combining several results, is oriented towards printing and not to store variables.

提交回复
热议问题