I'm trying to figure out how to return chi2 as measure of fit for linear regression models (OLS, WLS, etc). Ulitmately I'll use chi2 to calculate reduced chi-squared, which is the accepted goodness of fit measure in my field. Here's some example code with actual data I'm using.
import numpy as np
import statsmodels.api as sm
from matplotlib import pyplot as plt
# measured data
x = np.array([0.514282, 1.963679, 2.174223, 2.110413, 0.152505, 0.023114])
y = np.array([0.284664, 0.289194, 0.289830, 0.289639, 0.283551, 0.283176])
# stdev in y measurment
s = np.array([0.000029, 0.000029, 0.000030, 0.000029, 0.000029, 0.000029])
# convert stdev to variance
w = 1/(s*s)
# add constant value to calculate intercept
X = sm.add_constant(x)
# weighted least squares regression
res_wls = sm.WLS(y, X, weights=w).fit()
print(res_wls.summary())
# plot the data and model fit
fig, ax = plt.subplots(figsize=(10, 7))
plt.plot(x, y, 'o')
plt.plot(x, res_wls.fittedvalues)