spreg.ML_Lag¶
- class spreg.ML_Lag(y, x, w, slx_lags=0, slx_vars='All', regimes=None, method='full', epsilon=1e-07, spat_impacts='simple', vm=False, spat_diag=True, name_y=None, name_x=None, name_w=None, name_ds=None, latex=False, **kwargs)[source]¶
- ML estimation of the spatial lag model with all results and diagnostics; [Ans88] - Parameters:
- ynumpy.ndarrayorpandas.Series
- nx1 array for dependent variable 
- xnumpy.ndarrayorpandasobject
- Two dimensional array with n rows and one column for each independent (exogenous) variable, excluding the constant 
- wpysalWobject
- Spatial weights object 
- slx_lagsinteger
- Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the Spatial Durbin type. 
- slx_varseither“All” (default)orlistofbooleanstoselectxvariables
- to be lagged 
- regimeslistorpandas.Series
- List of n values with the mapping of each observation to a regime. Assumed to be aligned with ‘x’. For other regimes-specific arguments, see ML_Lag_Regimes 
- methodstr
- if ‘full’, brute force calculation (full matrix expressions) if ‘ord’, Ord eigenvalue method 
- epsilonfloat
- tolerance criterion in mimimize_scalar function and inverse_product 
- spat_diagbool
- If True, then compute Common Factor Hypothesis test when applicable 
- spat_impactsstrorlist
- Include average direct impact (ADI), average indirect impact (AII),
- and average total impact (ATI) in summary results. Options are ‘simple’, ‘full’, ‘power’, ‘all’ or None. See sputils.spmultiplier for more information. 
 
- vmbool
- if True, include variance-covariance matrix in summary results 
- name_ystr
- Name of dependent variable for use in output 
- name_xlistofstrings
- Names of independent variables for use in output 
- name_wstr
- Name of weights matrix for use in output 
- name_dsstr
- Name of dataset for use in output 
- latexbool
- Specifies if summary is to be printed in latex format 
 
- y
- Attributes:
- outputdataframe
- regression results pandas dataframe 
- betasarray
- (k+1)x1 array of estimated coefficients (rho first) 
- rhofloat
- estimate of spatial autoregressive coefficient 
- uarray
- nx1 array of residuals 
- predyarray
- nx1 array of predicted y values 
- ninteger
- Number of observations 
- kinteger
- Number of variables for which coefficients are estimated (including the constant, excluding the rho) 
- yarray
- nx1 array for dependent variable 
- xarray
- Two dimensional array with n rows and one column for each independent (exogenous) variable, including the constant 
- methodstr
- log Jacobian method if ‘full’: brute force (full matrix computations) 
- epsilonfloat
- tolerance criterion used in minimize_scalar function and inverse_product 
- mean_yfloat
- Mean of dependent variable 
- std_yfloat
- Standard deviation of dependent variable 
- vmarray
- Variance covariance matrix (k+1 x k+1), all coefficients 
- vm1array
- Variance covariance matrix (k+2 x k+2), includes sig2 
- sig2float
- Sigma squared used in computations 
- logllfloat
- maximized log-likelihood (including constant terms) 
- aicfloat
- Akaike information criterion 
- schwarzfloat
- Schwarz criterion 
- cfh_testtuple
- Common Factor Hypothesis test; tuple contains the pair (statistic, p-value). Only when it applies (see specific documentation). 
- predy_earray
- predicted values from reduced form 
- e_predarray
- prediction errors using reduced form predicted values 
- pr2float
- Pseudo R squared (squared correlation between y and ypred) 
- pr2_efloat
- Pseudo R squared (squared correlation between y and ypred_e (using reduced form)) 
- utufloat
- Sum of squared residuals 
- std_errarray
- 1xk array of standard errors of the betas 
- z_statlistoftuples
- z statistic; each tuple contains the pair (statistic, p-value), where each is a float 
- sp_multipliers: dict
- Dictionary of spatial multipliers (if spat_impacts is not None) 
- name_ystr
- Name of dependent variable for use in output 
- name_xlistofstrings
- Names of independent variables for use in output 
- name_wstr
- Name of weights matrix for use in output 
- name_dsstr
- Name of dataset for use in output 
- titlestr
- Name of the regression method used 
 
- output
 - Examples - >>> import numpy as np >>> import libpysal >>> from libpysal.examples import load_example >>> from libpysal.weights import Queen >>> from spreg import ML_Error_Regimes >>> import geopandas as gpd >>> from spreg import ML_Lag >>> np.set_printoptions(suppress=True) #prevent scientific format >>> baltimore = load_example('Baltimore') >>> db = libpysal.io.open(baltimore.get_path("baltim.dbf"),'r') >>> df = gpd.read_file(baltimore.get_path("baltim.shp")) >>> ds_name = "baltim.dbf" >>> y_name = "PRICE" >>> y = np.array(db.by_col(y_name)).T >>> y.shape = (len(y),1) >>> x_names = ["NROOM","NBATH","PATIO","FIREPL","AC","GAR","AGE","LOTSZ","SQFT"] >>> x = np.array([db.by_col(var) for var in x_names]).T >>> w = Queen.from_dataframe(df) >>> w_name = "baltim_q.gal" >>> w.transform = 'r' >>> mllag = ML_Lag(y,x,w,name_y=y_name,name_x=x_names, name_w=w_name,name_ds=ds_name) >>> np.around(mllag.betas, decimals=4) array([[ 4.3675], [ 0.7502], [ 5.6116], [ 7.0497], [ 7.7246], [ 6.1231], [ 4.6375], [-0.1107], [ 0.0679], [ 0.0794], [ 0.4259]]) >>> "{0:.6f}".format(mllag.rho) '0.425885' >>> "{0:.6f}".format(mllag.mean_y) '44.307180' >>> "{0:.6f}".format(mllag.std_y) '23.606077' >>> np.around(np.diag(mllag.vm1), decimals=4) array([ 23.8716, 1.1222, 3.0593, 7.3416, 5.6695, 5.4698, 2.8684, 0.0026, 0.0002, 0.0266, 0.0032, 220.1292]) >>> np.around(np.diag(mllag.vm), decimals=4) array([ 23.8716, 1.1222, 3.0593, 7.3416, 5.6695, 5.4698, 2.8684, 0.0026, 0.0002, 0.0266, 0.0032]) >>> "{0:.6f}".format(mllag.sig2) '151.458698' >>> "{0:.6f}".format(mllag.logll) '-832.937174' >>> "{0:.6f}".format(mllag.aic) '1687.874348' >>> "{0:.6f}".format(mllag.schwarz) '1724.744787' >>> "{0:.6f}".format(mllag.pr2) '0.727081' >>> "{0:.4f}".format(mllag.pr2_e) '0.7062' >>> "{0:.4f}".format(mllag.utu) '31957.7853' >>> np.around(mllag.std_err, decimals=4) array([ 4.8859, 1.0593, 1.7491, 2.7095, 2.3811, 2.3388, 1.6936, 0.0508, 0.0146, 0.1631, 0.057 ]) >>> np.around(mllag.z_stat, decimals=4) array([[ 0.8939, 0.3714], [ 0.7082, 0.4788], [ 3.2083, 0.0013], [ 2.6018, 0.0093], [ 3.2442, 0.0012], [ 2.6181, 0.0088], [ 2.7382, 0.0062], [-2.178 , 0.0294], [ 4.6487, 0. ], [ 0.4866, 0.6266], [ 7.4775, 0. ]]) >>> mllag.name_y 'PRICE' >>> mllag.name_x ['CONSTANT', 'NROOM', 'NBATH', 'PATIO', 'FIREPL', 'AC', 'GAR', 'AGE', 'LOTSZ', 'SQFT', 'W_PRICE'] >>> mllag.name_w 'baltim_q.gal' >>> mllag.name_ds 'baltim.dbf' >>> mllag.title 'MAXIMUM LIKELIHOOD SPATIAL LAG (METHOD = FULL)' >>> mllag = ML_Lag(y,x,w,method='ord',name_y=y_name,name_x=x_names, name_w=w_name,name_ds=ds_name) >>> np.around(mllag.betas, decimals=4) array([[ 4.3675], [ 0.7502], [ 5.6116], [ 7.0497], [ 7.7246], [ 6.1231], [ 4.6375], [-0.1107], [ 0.0679], [ 0.0794], [ 0.4259]]) >>> "{0:.6f}".format(mllag.rho) '0.425885' >>> "{0:.6f}".format(mllag.mean_y) '44.307180' >>> "{0:.6f}".format(mllag.std_y) '23.606077' >>> np.around(np.diag(mllag.vm1), decimals=4) array([ 23.8716, 1.1222, 3.0593, 7.3416, 5.6695, 5.4698, 2.8684, 0.0026, 0.0002, 0.0266, 0.0032, 220.1292]) >>> np.around(np.diag(mllag.vm), decimals=4) array([ 23.8716, 1.1222, 3.0593, 7.3416, 5.6695, 5.4698, 2.8684, 0.0026, 0.0002, 0.0266, 0.0032]) >>> "{0:.6f}".format(mllag.sig2) '151.458698' >>> "{0:.6f}".format(mllag.logll) '-832.937174' >>> "{0:.6f}".format(mllag.aic) '1687.874348' >>> "{0:.6f}".format(mllag.schwarz) '1724.744787' >>> "{0:.6f}".format(mllag.pr2) '0.727081' >>> "{0:.6f}".format(mllag.pr2_e) '0.706198' >>> "{0:.4f}".format(mllag.utu) '31957.7853' >>> np.around(mllag.std_err, decimals=4) array([ 4.8859, 1.0593, 1.7491, 2.7095, 2.3811, 2.3388, 1.6936, 0.0508, 0.0146, 0.1631, 0.057 ]) >>> np.around(mllag.z_stat, decimals=4) array([[ 0.8939, 0.3714], [ 0.7082, 0.4788], [ 3.2083, 0.0013], [ 2.6018, 0.0093], [ 3.2442, 0.0012], [ 2.6181, 0.0088], [ 2.7382, 0.0062], [-2.178 , 0.0294], [ 4.6487, 0. ], [ 0.4866, 0.6266], [ 7.4775, 0. ]]) >>> mllag.name_y 'PRICE' >>> mllag.name_x ['CONSTANT', 'NROOM', 'NBATH', 'PATIO', 'FIREPL', 'AC', 'GAR', 'AGE', 'LOTSZ', 'SQFT', 'W_PRICE'] >>> mllag.name_w 'baltim_q.gal' >>> mllag.name_ds 'baltim.dbf' >>> mllag.title 'MAXIMUM LIKELIHOOD SPATIAL LAG (METHOD = ORD)' - __init__(y, x, w, slx_lags=0, slx_vars='All', regimes=None, method='full', epsilon=1e-07, spat_impacts='simple', vm=False, spat_diag=True, name_y=None, name_x=None, name_w=None, name_ds=None, latex=False, **kwargs)[source]¶
 - Methods - __init__(y, x, w[, slx_lags, slx_vars, ...])- Attributes - property mean_y¶
 - property sig2n¶
 - property sig2n_k¶
 - property std_y¶
 - property utu¶
 - property vm¶