Poisson_GLM
from spglm.glm import GLM
from spglm.family import Poisson
import libpysal.api as ps
import numpy as np
#Load sample dataset - columbus dataset
db = ps.open(ps.get_path('columbus.dbf'),'r')
#Set dependent variable
y = np.array(db.by_col("HOVAL"))
y = np.reshape(y, (49,1))
#Round dependent variable and convert to integer for the example since Poisson is for discrete data
y = np.round(y).astype(int)
#Set indepdent varibLES
X = []
X.append(db.by_col("INC"))
X.append(db.by_col("CRIME"))
X = np.array(X).T
#Estimate Poisson GLM
#First instantiate a GLM model object
model = GLM(y, X, family=Poisson()) #Set family to Poisson family object for Poisson GLM
#Then use the fit method to estimate coefficients and compute diagnostics
results = model.fit()
#Estimated prameters, intercept is always the first column on the left
print(results.params)
#Parameter standard errors
print(results.bse)
#Parameter t-values
print(results.tvalues)
#Model AIC
print(results.aic)