I'm just exploring Generalized Linear Models for the first time, and trying to see if I can correctly fit the simplest model I can think of. So I'm generating random values from some NegativeBinomial distribution and then fitting it with a GLM.
np.random.seed(5555555)
weeks = np.arange(np.datetime64("2020-01-01"),np.datetime64("2022-12-01"),np.timedelta64(1,'W'))
counts = pd.Series(nbinom.rvs(10, .5, size=weeks.shape[0]))
counts.index=weeks
obs, last = counts[0:-1], counts[-1:]
X = np.array(obs.index.values.tolist())
X = np.stack((X, np.ones(X.shape[0])),axis=1)
X.shape
y = obs
mdl = GLM(y, X, family=NegativeBinomialFamily())
results = mdl.fit()
results.summary()
I would think that the slope for my one independent variable of 'date' should just be 0.
But this code always gives me a very small positive value:
Generalized Linear Model Regression Results Dep. Variable: y No. Observations: 152
Model: GLM Df Residuals: 151
Model Family: NegativeBinomial Df Model: 0
Link Function: Log Scale: 1.0000
Method: IRLS Log-Likelihood: -504.15
Date: Thu, 04 May 2023 Deviance: 28.334
Time: 10:51:39 Pearson chi2: 24.8
No. Iterations: 4 Pseudo R-squ. (CS): -0.001740
Covariance Type: nonrobust
coef std err z P>|z| [0.025 0.975]
x1 1.396e-18 5.25e-20 26.594 0.000 1.29e-18 1.5e-18
const 8.594e-37 3.23e-38 26.594 0.000 7.96e-37 9.23e-37
What's going on here? It looks like the model is very confident the model has an itty bitty positive slope.
Am I setting up the model wrong? Am I interpreting the output wrong?
1.405e-18
? $\endgroup$GLM
function decides to stop when trying to optimize parameter estimates. $\endgroup$