Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Last active December 21, 2022 05:05
Show Gist options
  • Save galenseilis/70fe9d29f612578adf3fc4c9c44d28ae to your computer and use it in GitHub Desktop.
Save galenseilis/70fe9d29f612578adf3fc4c9c44d28ae to your computer and use it in GitHub Desktop.
Statistical rethinking with Python
import matplotlib.pyplot as plt
import statsmodels.api as sm
import statsmodels.formula.api as smf
cars = sm.datasets.get_rdataset('cars')
cars = cars.raw_data
model = smf.ols('dist ~ speed', data=cars)
results = model.fit()
print(results.params)
plt.scatter(cars.speed, results.resid)
plt.xlabel('Speed')
plt.ylabel('Residuals')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment