spglm.glm.GLMResults

class spglm.glm.GLMResults(model, params, mu, w)[source]

Results of estimated GLM and diagnostics.

Parameters:
modelGLM object

Pointer to GLM object with estimation parameters.

paramsarray

k*1, estimared coefficients

muarray

n*1, predicted y values.

warray

n*1, final weight used for iwls

Examples

>>> import libpysal
>>> from spglm.glm import GLM, GLMResults
>>> 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())
>>> results1 = model.fit()
>>> results1.aic
408.73548964604873
>>> model = results1.model
>>> params = results1.params.flatten()
>>> predy = results1.mu
>>> w = results1.w
>>> results2 = GLMResults(model, params, predy, w)
>>> results2.aic
408.73548964604873
Attributes:
modelGLM Object

Points to GLM object for which parameters have been estimated.

yarray

n*1, dependent variable.

xarray

n*k, independent variable, including constant.

familystr

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

ninteger

Number of observations

kinteger

Number of independent variables

df_modelfloat

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

df_residualfloat

observations minus variables (n-k)

fit_paramsdict

parameters passed into fit method to define estimation routine.

scalefloat

sigma squared used for subsequent computations.

paramsarray

n*k, estimared beta coefficients

warray

n*1, final weight values of x

muarray

n*1, predicted value of y (i.e., fittedvalues)

cov_paramsarray

Returns the variance/covariance matrix.

bsearray

k*1, standard errors of betas

pvaluesarray

k*1, two-tailed pvalues of parameters

tvaluesarray

Return the t-statistic for a given parameter estimate.

nullarray

n*1, predicted values of y for null model

deviancefloat

value of the deviance function evalued at params; see family.py for distribution-specific deviance

null_deviancefloat

value of the deviance function for the model fit with a constant as the only regressor

llffloat

value of the loglikelihood function evalued at params; see family.py for distribution-specific loglikelihoods

llnullfloat

value of log-likelihood function evaluated at null

aicfloat

AIC

bicfloat

BIC

D2float

percent deviance explained

adj_D2float

adjusted percent deviance explained

pseudo_R2float

McFadden’s pseudo R2 (coefficient of determination)

adj_pseudoR2float

adjusted McFadden’s pseudo R2

tr_Strace of the hat matrix S
resid_responsearray

response residuals; defined as y-mu

resid_pearsonarray

Pearson residuals; defined as (y-mu)/sqrt(VAR(mu)) where VAR is the distribution specific variance function; see family.py and varfuncs.py for more information.

resid_workingarray

Working residuals; the working residuals are defined as resid_response/link’(mu); see links.py for the derivatives of the link functions.

resid_anscombearray

Anscombe residuals; see family.py for distribution-specific Anscombe residuals.

resid_deviancearray

deviance residuals; see family.py for distribution-specific deviance residuals.

pearson_chi2float

chi-Squared statistic is defined as the sum of the squares of the Pearson residuals

normalized_cov_paramsarray

k*k, approximates [X.T*X]-1

__init__(model, params, mu, w)[source]

Methods

D2()

__init__(model, params, mu, w)

adj_D2()

adj_pseudoR2()

aic()

bic()

bse()

conf_int([alpha, cols, method])

Returns the confidence interval of the fitted parameters.

cov_params([r_matrix, column, scale, cov_p, ...])

Returns the variance/covariance matrix. The variance/covariance matrix can be of a linear contrast of the estimates of params or all params multiplied by scale which will usually be an estimate of sigma^2. Scale is assumed to be a scalar. Parameters ---------- r_matrix : array-like Can be 1d, or 2d. Can be used alone or with other. column : array-like, optional Must be used on its own. Can be 0d or 1d see below. scale : float, optional Can be specified or not. Default is None, which means that the scale argument is taken from the model. other : array-like, optional Can be used when r_matrix is specified. Returns ------- cov : ndarray covariance matrix of the parameter estimates or of linear combination of parameter estimates. See Notes. Notes ----- (The below are assumed to be in matrix notation.) If no argument is specified returns the covariance matrix of a model (scale)*(X.T X)^(-1) If contrast is specified it pre and post-multiplies as follows (scale) * r_matrix (X.T X)^(-1) r_matrix.T If contrast and other are specified returns (scale) * r_matrix (X.T X)^(-1) other.T If column is specified returns (scale) * (X.T X)^(-1)[column,column] if column is 0d OR (scale) * (X.T X)^(-1)[column][:,column] if column is 1d.

deviance()

df_model()

df_resid()

initialize(model, params, **kwd)

llf()

llnull()

normalized_cov_params()

null()

null_deviance()

pearson_chi2()

pseudoR2()

pvalues()

resid_anscombe()

resid_deviance()

resid_pearson()

resid_response()

resid_working()

scale()

tr_S()

tvalues()

Return the t-statistic for a given parameter estimate.

Attributes

use_t

D2()[source]
adj_D2()[source]
adj_pseudoR2()[source]
aic()[source]
bic()[source]
deviance()[source]
df_model()[source]
df_resid()[source]
llf()[source]
llnull()[source]
normalized_cov_params()[source]
null()[source]
null_deviance()[source]
pearson_chi2()[source]
pseudoR2()[source]
resid_anscombe()[source]
resid_deviance()[source]
resid_pearson()[source]
resid_response()[source]
resid_working()[source]
scale()[source]
tr_S()[source]