Examples
This wiki page assembles a collection "official" and user-contributed examples, tutorials and recipes for statsmodels
.
A set of notebook examples are provided as part of the official Statsmodels documentation.
If you have an interesting example, or if you can write a quick tutorial describing one of statsmodels
' features, please consider posting it here. We would be delighted!
Feel free to post your example file in any of the common formats (e.g. .py, .rst, .html) and to use any hosting service you like. One very slick, free, and convenient alternative is to:
- Write-up your example in an IPython notebook
- Save the content of the
.ipynb
file in a Gist - Use nbviewer to display the notebook in html format on the web. This step simply involves swapping the domain name in the Gist URL (e.g. https://gist.github.com/3484337 -> http://nbviewer.ipython.org/3484337)
Please post your contributions below!
- Getting started: HTML View, IPython Notebook
www.dropbox.com/scl/fo/mylhfjbpl2zlc5z5m4prq/h?dl=0&rlkey=li52chs6rcl6lejspde6n0oqf
-
Differential expression analysis of gene expression data [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/7kh8amlez7bx3qlqa6aa.ipynb?create=1)
-
Simulation study of FDR methods [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/wtmzw5hmpe1pbb2cug6x.ipynb)
- Cross validation and ROC curves for predicting diabetes status [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/aouhn2mci77opm3v89vc.ipynb)
-
GDP by country [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/oxsz9tlg19clhzi422i4.ipynb), [data] (https://umich.box.com/shared/static/uxpesc1pix3gedyecggp.csv)
-
Gas prices HTML View
- PCA of fertility rates by country [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/6m7f4lw9bdog241kqcmb.ipynb)
-
L1 regularized logistic regression example with simulated data [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/ck0n67gt1sxaiwj9bp2c.ipynb)
-
L1 regularized logistic regression with data from medical utilization studies [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/az63gav7ly7y7jbxe9zd.ipynb)
-
L1 linear regression for a diabetes data set HTML View
-
Ordinary least squares and regression analysis [Youtube Tutorial] (https://www.youtube.com/watch?v=V86gTgL1FRw)
-
Logistic regression power analysis using simulation [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/ttstmmi3ushthhkl0g33.ipynb)
-
Relative risk logistic regression [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/60n20u2i871xzd7q21gl.ipynb)
-
Regression graphics [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/lw8pzvzgi9bq5baaca0i4e2dfhsqmm80.ipynb)
-
Gamma GLM [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/n0nsh9d765t3snl907vc.ipynb)
- Cross sectional smoothing of NHANES data HTML View
- Mediation analysis in a political framing study.
-
Basic proportional hazards regression in Statsmodels, R, and Stata [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/epie6pcdk1rgb10zcd5v.ipynb)
-
Survival analysis of NHANES III data [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/elrb0pu8djecxgf17ozahd7gsqzoy1zg.ipynb)
-
Diagnostics for proportional hazards regression models [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/hyw87uy0cgc1bi9epg0t.ipynb)
-
Simulated data example for dependent events [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/1187gaws4aip9o5d2o3k.ipynb)
-
Prediction in proportional hazards models [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/r7sz17s96cwvemwfix7b.ipynb)
- Simulation study using "corr_nearest" HTML View
-
Two examples using both R (LME4) and Statsmodels [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/6tfc1e0q6jincsv5pgfa.ipynb)
-
Regression analysis of healthcare spending in Vietnam, using mixed models and GEE. Stata results provided for comparison. [HTML View] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/lc6uf6dmabmitjbup3yt.ipynb)
-
GEE analysis of longitudinal CD4 counts HTML view
-
GEE Poisson model for repeated measures of epileptic seizure counts HTML view
-
GEE Gaussian and Poisson models for repeated measures of disease incidence in herds of cattle HTML view, data set
-
GEE for discrete ordinal test score data with cluster sampling [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/y1fw0iameuixrq9zt02d.ipynb?create=1)
-
GEE score test simulation study [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/mlc77aixvwl43xe9vvjf.ipynb?create=1)
-
GEE for repeated measures of outcomes that are proportions [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/y0azjuau3t21b7p11m56.ipynb)
-
GEE analyses of student test score data with nested dependence [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/wt4jlup9nwbt2d69xvm6.ipynb?create=1)
-
GEE simulation study for data with nested dependence [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/7dmmgmaekk2gh9h6ztcw.ipynb?create=1)
-
GEE simulation study for Poisson regression with overdispersion [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/y20u25cxot26kg0mbfys.ipynb)
-
GEE simulation study for regression with nominal data [HTML view] (http://nbviewer.ipython.org/urls/umich.box.com/shared/static/wwwlg3z8as0layod22lx.ipynb)
-
Time Series Analysis Using ARIMA From Statsmodels [HTML view] (https://www.nbshare.io/notebook/136553745/Time-Series-Analysis-Using-ARIMA-From-StatsModels/)