This page was generated from notebooks/Gaussian_GLM.ipynb. Interactive online version:
Gaussian GLMΒΆ
[1]:
from spglm.glm import GLM
import libpysal
import numpy
[2]:
# Load sample dataset - columbus dataset
db = libpysal.io.open(libpysal.examples.get_path("columbus.dbf"))
# Set dependent variable
y = numpy.array(db.by_col("HOVAL"))
y = numpy.reshape(y, (49, 1))
# Set indepdent varibLES
X = []
X.append(db.by_col("INC"))
X.append(db.by_col("CRIME"))
X = numpy.array(X).T
[3]:
# Estimate Gaussian GLM
# First instantiate a GLM model object
# -- Gaussian is the default family parameter so it doesn't need to be set
model = GLM(y, X)
# Then use the fit method to estimate coefficients and compute diagnostics
results = model.fit()
[4]:
# Estimated prameters, intercept is always the first column on the left
print(results.params)
[46.42818268 0.62898397 -0.48488854]
[5]:
# Parameter standard errors
print(results.bse)
[13.19175703 0.53591045 0.18267291]
[6]:
# Parameter t-values
print(results.tvalues)
[ 3.51948437 1.17367365 -2.65440864]
[7]:
# Model AIC
print(results.aic)
408.73548964604873