import polars as pl
import scipy as sp
import numpy as np
import patsy as pt
import matplotlib.pyplot as plt
import statsmodels.api as smurl = "https://roualdes.sfo3.digitaloceanspaces.com/data/finches.csv"
df = pl.read_csv(url)y, X = pt.dmatrices("winglength ~ C(island) * taillength", data = df.to_pandas())
mod = sm.OLS(y, X)
fit = mod.fit()
fit.summary()| Dep. Variable: | winglength | R-squared: | 0.602 |
| Model: | OLS | Adj. R-squared: | 0.570 |
| Method: | Least Squares | F-statistic: | 18.74 |
| Date: | Wed, 18 Nov 2026 | Prob (F-statistic): | 2.67e-11 |
| Time: | 14:23:24 | Log-Likelihood: | -159.53 |
| No. Observations: | 68 | AIC: | 331.1 |
| Df Residuals: | 62 | BIC: | 344.4 |
| Df Model: | 5 | ||
| Covariance Type: | nonrobust |
| coef | std err | t | P>|t| | [0.025 | 0.975] | |
| Intercept | 20.2341 | 8.555 | 2.365 | 0.021 | 3.132 | 37.336 |
| C(island)[T.sancristobal] | 5.4694 | 12.298 | 0.445 | 0.658 | -19.113 | 30.052 |
| C(island)[T.santacruz] | -16.0580 | 15.124 | -1.062 | 0.292 | -46.290 | 14.174 |
| taillength | 1.1597 | 0.194 | 5.976 | 0.000 | 0.772 | 1.548 |
| C(island)[T.sancristobal]:taillength | -0.1179 | 0.277 | -0.425 | 0.672 | -0.673 | 0.437 |
| C(island)[T.santacruz]:taillength | 0.3917 | 0.347 | 1.128 | 0.264 | -0.303 | 1.086 |
| Omnibus: | 4.060 | Durbin-Watson: | 1.738 |
| Prob(Omnibus): | 0.131 | Jarque-Bera (JB): | 3.324 |
| Skew: | -0.525 | Prob(JB): | 0.190 |
| Kurtosis: | 3.263 | Cond. No. | 2.72e+03 |
Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 2.72e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
- interaction term: joins together two predictors
- OLS: ordinary least squares: minimize squared residuals
- adjusted R^2: correctly penalizes for including predictors that aren’t good at their job. Only use adjusted \(R^2\)
- like R^2 but isn’t guaranteed to go up with extra, useless predictors. This is a good thing. Use adjusted \(R^2\) in place of R^2 at all times.
- AIC/BIC: Akaike/Bayesian information criterion. They attempt to quantify how well your model will predict new (unseen) data.