stargazer
Python implementation of the R stargazer multiple regression model creation tool
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.7%) to scientific vocabulary
Keywords
Repository
Python implementation of the R stargazer multiple regression model creation tool
Basic Info
- Host: GitHub
- Owner: StatsReporting
- License: other
- Language: Jupyter Notebook
- Default Branch: master
- Size: 439 KB
Statistics
- Stars: 203
- Watchers: 5
- Forks: 54
- Open Issues: 33
- Releases: 0
Topics
Metadata Files
README.md
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.
Installation
You can install this package through PyPi 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
Editing Features
This library implements many of the customization features found in the original package. Examples of most can be found in the examples jupyter notebook and a full list of the methods/features is here below:
title: custom titleshow_header: display or hide model header datashow_model_numbers: display or hide model numberscustom_columns: custom model names and model groupingssignificance_levels: change statistical significance thresholdssignificant_digits: change number of significant digitsshow_confidence_intervals: display confidence intervals instead of variancedependent_variable_name: rename dependent variablerename_covariates: rename covariatescovariate_order: reorder covariatesreset_covariate_order: reset covariate order to original orderingshow_degrees_of_freedom: display or hide degrees of freedomcustom_note_label: label notes section at bottom of tableadd_custom_notes: add custom notes to section at bottom of the tableadd_line: add a custom line to the tableappend_notes: display or hide statistical significance thresholds
These features are agnostic of the rendering type and will be applied whether the user outputs in HTML, LaTeX, etc
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
```python 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.addconstant(df[df.columns[0:4]])).fit() est2 = sm.OLS(endog=df['target'], exog=sm.addconstant(df[df.columns[0:6]])).fit()
stargazer = Stargazer([est, est2]) ```
HTML Example
python
stargazer.render_html()
| Dependent variable: target | ||
| (1) | (2) | |
| ABP | 416.674*** | 397.583*** |
| (69.495) | (70.870) | |
| 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 | 442 |
| R2 | 0.400 | 0.403 |
| Adjusted R2 | 0.395 | 0.395 |
| Residual Std. Error | 59.976 (df=437) | 59.982 (df=435) |
| F Statistic | 72.913*** (df=4; 437) | 48.915*** (df=6; 435) |
| Note: | *p<0.1; **p<0.05; ***p<0.01 | |
LaTeX Example
python
stargazer.render_latex()

Owner
- Name: StatsReporting
- Login: StatsReporting
- Kind: organization
- Repositories: 1
- Profile: https://github.com/StatsReporting
GitHub Events
Total
- Issues event: 1
- Watch event: 13
- Issue comment event: 4
- Pull request event: 2
- Fork event: 5
Last Year
- Issues event: 1
- Watch event: 13
- Issue comment event: 4
- Pull request event: 2
- Fork event: 5
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 8
- Total pull requests: 16
- Average time to close issues: about 1 month
- Average time to close pull requests: 5 months
- Total issue authors: 7
- Total pull request authors: 7
- Average comments per issue: 2.38
- Average comments per pull request: 2.44
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 3.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- SwannChelly (2)
- randomgambit (1)
- elemn (1)
- SimaFT (1)
- javier-garcia-tilburg (1)
- msh855 (1)
- toobaz (1)
Pull Request Authors
- vlshields (4)
- jsr-p (3)
- dsliwka (3)
- s3alfisc (2)
- javier-garcia-tilburg (2)
- jpweytjens (1)
- maruoss (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 4,837 last-month
- Total dependent packages: 1
- Total dependent repositories: 33
- Total versions: 7
- Total maintainers: 2
pypi.org: stargazer
Nicely formatted regression reporting
- Homepage: https://github.com/StatsReporting/stargazer
- Documentation: https://stargazer.readthedocs.io/
- License: GPLv2
-
Latest release: 0.0.7
published almost 2 years ago