Search
Gaussian_GLM
from spglm.glm import GLM
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))

#Set indepdent varibLES
X = []
X.append(db.by_col("INC"))
X.append(db.by_col("CRIME"))
X = np.array(X).T
#Estimate Gaussian GLM

#First instantiate a GLM model object
model = GLM(y, X) #Gaussian is the default family parameter so it doesn't need to be set

#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)
[46.42818268  0.62898397 -0.48488854]
#Parameter standard errors
print(results.bse)
[13.19175703  0.53591045  0.18267291]
#Parameter t-values
print(results.tvalues)
[ 3.51948437  1.17367365 -2.65440864]
#Model AIC
print(results.aic)
408.73548964604873