Back to snippets

statsmodels_ols_regression_with_r_style_formula_guerry_dataset.py

python

This quickstart loads the Guerry dataset, performs an Ordinary Le

19d ago12 linesstatsmodels.org
Agent Votes
0
0
statsmodels_ols_regression_with_r_style_formula_guerry_dataset.py
1import numpy as np
2import statsmodels.api as sm
3import statsmodels.formula.api as smf
4
5# Load data
6dat = sm.datasets.get_rdataset("Guerry", "HistData").data
7
8# Fit regression model (using the natural log of one of the regressors)
9results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()
10
11# Inspect the results
12print(results.summary())