Nicely formatted regression reporting
Project description
Stargazer
This is a python port of the R stargazer package that can be found on CRAN. I was disappointed that there wasn't equivalent functionality in any python packages I was aware of so I'm re-implementing it here.
There is an experimental function in the statsmodels.regression.linear_model.OLSResults.summary2 that can report single regression model results in HTML/CSV/LaTeX/etc, but it still didn't quite fulfill what I was looking for.
The python package is object oriented now with chained commands to make changes to the rendering parameters, which is hopefully more pythonic and the user doesn't have to put a bunch of arguments in a single function.
I'm just making this in my free time, so please feel free to contribute or log issues when you see them.
Installation
You can install this package with pip install stargazer
or just clone the repo and take the stargazer.py
file since it's the only one in the package.
Dependencies
It depends on statsmodels
, which in turn depends on several other libraries like pandas
, numpy
, etc
TODO
Here's some things I'd like to do but will never get to when I have time.
✔ HTML support
✔ LaTeX support
☐ Markdown support (maybe?)
☐ ASCII support (maybe?)
☐ Fixing those ugly lookin pluses to make strings by using .format like a regular person
Example
Here is an examples of how to quickly get started with the library. More examples can be found in the examples.ipynb
file in the github repo. The examples all use the scikit-learn diabetes dataset, but it is not a dependency for the package.
OLS Models Preparation
import pandas as pd
from sklearn import datasets
import statsmodels.api as sm
from stargazer.stargazer import Stargazer
diabetes = datasets.load_diabetes()
df = pd.DataFrame(diabetes.data)
df.columns = ['Age', 'Sex', 'BMI', 'ABP', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6']
df['target'] = diabetes.target
est = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:4]])).fit()
est2 = sm.OLS(endog=df['target'], exog=sm.add_constant(df[df.columns[0:6]])).fit()
stargazer = Stargazer([est, est2])
HTML Example
stargazer.render_html()
Dependent variable: | ||
(1) | (2) | |
ABP | 416.674*** | 397.583*** |
(69.495) | (70.87) | |
Age | 37.241 | 24.704 |
(64.117) | (65.411) | |
BMI | 787.179*** | 789.742*** |
(65.424) | (66.887) | |
S1 | 197.852 | |
(143.812) | ||
S2 | -169.251 | |
(142.744) | ||
Sex | -106.578* | -82.862 |
(62.125) | (64.851) | |
const | 152.133*** | 152.133*** |
(2.853) | (2.853) | |
Observations | 442.0 | 442.0 |
R2 | 0.4 | 0.403 |
Adjusted R2 | 0.395 | 0.395 |
Residual Std. Error | 59.976(df = 437.0) | 59.982(df = 435.0) |
F Statistic | 72.913***(df = 4.0; 437.0) | 48.915***(df = 6.0; 435.0) |
Note: | p<0.1; p<0.05; p<0.01 |
LaTeX Example
stargazer.render_latex()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for stargazer-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634e9db3e12cb1082373044c73158325f48d33aa8aba60f8ee2db7f8135a7e54 |
|
MD5 | fb14e1c044cbb2a2ff5a8db6b62de2e8 |
|
BLAKE2b-256 | 6b27141d7a5ad69c3f5aa7a12016452f3f928ffd0ffbb87ff4b4b4ad9fa8c110 |
Hashes for stargazer-0.0.3-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ed3d0afb18068875a703343987bd2c8af44a106c2084920cbeca8cda593ea4 |
|
MD5 | 7de63c175db6279fd62e58d78b9e133c |
|
BLAKE2b-256 | 218c5c29ca23219d0f81ed373235518445492bb301e11f61f2537bc23c0cf101 |