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:
- modelGLMObject
- 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_params- array
- Returns the variance/covariance matrix. 
- bsearray
- k*1, standard errors of betas 
- pvaluesarray
- k*1, two-tailed pvalues of parameters 
- tvalues- array
- 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_StraceofthehatmatrixS
- 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 
 
- 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