spglm.glm.GLM

class spglm.glm.GLM(y, X, family=<spglm.family.Gaussian object>, offset=None, y_fix=None, constant=True)[source]

Generalised linear models. Can currently estimate Guassian, Poisson and Logisitc regression coefficients. GLM object prepares model input and fit method performs estimation which then returns a GLMResults object.

Parameters:
y : array

n*1, dependent variable.

X : array

n*k, independent variable, exlcuding the constant.

family : string

Model type: ‘Gaussian’, ‘Poisson’, ‘Binomial’

offset : array

n*1, the offset variable at the ith location. For Poisson model this term is often the size of the population at risk or the expected size of the outcome in spatial epidemiology. Default is None where Ni becomes 1.0 for all locations.

y_fix : array

n*1, the fix intercept value of y

Examples

>>> import libpysal
>>> from spglm.glm import GLM
>>> from spglm.family import Gaussian
>>> db = libpysal.io.open(libpysal.examples.get_path('columbus.dbf'),'r')
>>> y = np.array(db.by_col("HOVAL"))
>>> y = np.reshape(y, (49,1))
>>> X = []
>>> X.append(db.by_col("INC"))
>>> X.append(db.by_col("CRIME"))
>>> X = np.array(X).T
>>> model = GLM(y, X, family=Gaussian())
>>> results = model.fit()
>>> results.params
array([46.42818268,  0.62898397, -0.48488854])
Attributes:
y : array

n*1, dependent variable.

X : array

n*k, independent variable, including constant.

family : string

Model type: ‘Gaussian’, ‘Poisson’, ‘logistic’

n : integer

Number of observations

k : integer

Number of independent variables

df_model : float

k-1, where k is the number of variables (including intercept)

df_residual : float

observations minus variables (n-k)

mean_y : float

Mean of y

std_y : float

Standard deviation of y

fit_params : dict

Parameters passed into fit method to define estimation routine.

Methods

fit([ini_betas, tol, max_iter, solve]) Method that fits a model with a particular estimation routine.
df_model  
df_resid  
__init__(y, X, family=<spglm.family.Gaussian object>, offset=None, y_fix=None, constant=True)[source]

Initialize class

Methods

__init__(y, X[, family, offset, y_fix, constant]) Initialize class
df_model()
df_resid()
fit([ini_betas, tol, max_iter, solve]) Method that fits a model with a particular estimation routine.

Attributes

mean_y
std_y