spglm.glm.GLMResults¶
- class spglm.glm.GLMResults(model, params, mu, w)[source]¶
Results of estimated GLM and diagnostics.
- Parameters:
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:
- model
GLMObject Points to GLM object for which parameters have been estimated.
- y
array n*1, dependent variable.
- x
array n*k, independent variable, including constant.
- family
str 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)
- fit_params
dict parameters passed into fit method to define estimation routine.
- scale
float sigma squared used for subsequent computations.
- params
array n*k, estimared beta coefficients
- w
array n*1, final weight values of x
- mu
array n*1, predicted value of y (i.e., fittedvalues)
cov_paramsarrayReturns the variance/covariance matrix.
- bse
array k*1, standard errors of betas
- pvalues
array k*1, two-tailed pvalues of parameters
tvaluesarrayReturn the t-statistic for a given parameter estimate.
- null
array n*1, predicted values of y for null model
- deviance
float value of the deviance function evalued at params; see family.py for distribution-specific deviance
- null_deviance
float value of the deviance function for the model fit with a constant as the only regressor
- llf
float value of the loglikelihood function evalued at params; see family.py for distribution-specific loglikelihoods
- llnull
float value of log-likelihood function evaluated at null
- aic
float AIC
- bic
float BIC
- D2
float percent deviance explained
- adj_D2
float adjusted percent deviance explained
- pseudo_R2
float McFadden’s pseudo R2 (coefficient of determination)
- adj_pseudoR2
float adjusted McFadden’s pseudo R2
- tr_S
traceofthehatmatrixS - resid_response
array response residuals; defined as y-mu
- resid_pearson
array 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_working
array Working residuals; the working residuals are defined as resid_response/link’(mu); see links.py for the derivatives of the link functions.
- resid_anscombe
array Anscombe residuals; see family.py for distribution-specific Anscombe residuals.
- resid_deviance
array deviance residuals; see family.py for distribution-specific deviance residuals.
- pearson_chi2
float chi-Squared statistic is defined as the sum of the squares of the Pearson residuals
- normalized_cov_params
array k*k, approximates [X.T*X]-1
- model
Methods
D2()__init__(model, params, mu, w)adj_D2()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.TIf contrast and other are specified returns(scale) * r_matrix (X.T X)^(-1) other.TIf 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()null()pseudoR2()pvalues()scale()tr_S()tvalues()Return the t-statistic for a given parameter estimate.
Attributes
use_t