# pysal.model.spreg.SURerrorGM¶

class pysal.model.spreg.SURerrorGM(bigy, bigX, w, regimes=None, nonspat_diag=True, spat_diag=False, vm=False, name_bigy=None, name_bigX=None, name_ds=None, name_w=None, name_regimes=None)[source]

User class for SUR Error estimation by Maximum Likelihood

Parameters: bigy : dictionary with vectors of dependent variable, one for each equation bigX : dictionary with matrices of explanatory variables, one for each equation w : spatial weights object regimes : list List of n values with the mapping of each observation to a regime. Assumed to be aligned with ‘x’. nonspat_diag : boolean; flag for non-spatial diagnostics, default = False spat_diag : boolean; flag for spatial diagnostics, default = False (to be implemented) vm : boolean; flag for asymptotic variance for lambda and Sigma, default = False (to be implemented) name_bigy : dictionary with name of dependent variable for each equation default = None, but should be specified is done when sur_stackxy is used name_bigX : dictionary with names of explanatory variables for each equation default = None, but should be specified is done when sur_stackxy is used name_ds : string; name for the data set name_w : string; name for the weights file name_regimes : string; name of regime variable for use in the output

Examples

First import pysal to load the spatial analysis tools.

>>> import pysal


Open data on NCOVR US County Homicides (3085 areas) using pysal.open(). This is the DBF associated with the NAT shapefile. Note that pysal.open() also reads data in CSV format.

>>> db = pysal.open(pysal.examples.get_path("NAT.dbf"),'r')


The specification of the model to be estimated can be provided as lists. Each equation should be listed separately. Equation 1 has HR80 as dependent variable, and PS80 and UE80 as exogenous regressors. For equation 2, HR90 is the dependent variable, and PS90 and UE90 the exogenous regressors.

>>> y_var = ['HR80','HR90']
>>> x_var = [['PS80','UE80'],['PS90','UE90']]
>>> yend_var = [['RD80'],['RD90']]
>>> q_var = [['FP79'],['FP89']]


The SUR method requires data to be provided as dictionaries. PySAL provides the tool sur_dictxy to create these dictionaries from the list of variables. The line below will create four dictionaries containing respectively the dependent variables (bigy), the regressors (bigX), the dependent variables’ names (bigyvars) and regressors’ names (bigXvars). All these will be created from th database (db) and lists of variables (y_var and x_var) created above.

>>> bigy,bigX,bigyvars,bigXvars = pysal.model.spreg.sur_utils.sur_dictxy(db,y_var,x_var)


To run a spatial error model, we need to specify the spatial weights matrix. To do that, we can open an already existing gal file or create a new one. In this example, we will create a new one from NAT.shp and transform it to row-standardized.

>>> w = pysal.queen_from_shapefile(pysal.examples.get_path("NAT.shp"))
>>> w.transform='r'


We can now run the regression and then have a summary of the output by typing: print(reg.summary)

Alternatively, we can just check the betas and standard errors, asymptotic t and p-value of the parameters:

>>> reg = SURerrorGM(bigy,bigX,w=w,name_bigy=bigyvars,name_bigX=bigXvars,name_ds="NAT",name_w="nat_queen")
>>> reg.bSUR
{0: array([[ 3.9774686 ],
[ 0.8902122 ],
[ 0.43050364]]), 1: array([[ 2.93679118],
[ 1.11002827],
[ 0.48761542]])}
>>> reg.sur_inf
{0: array([[  0.37251477,  10.67734473,   0.        ],
[  0.14224297,   6.25839157,   0.        ],
[  0.04322388,   9.95985619,   0.        ]]), 1: array([[  0.33694902,   8.71583239,   0.        ],
[  0.13413626,   8.27537784,   0.        ],
[  0.04033105,  12.09032295,   0.        ]])}

Attributes: n : number of observations in each cross-section n_eq : number of equations bigy : dictionary with vectors of dependent variable, one for each equation bigX : dictionary with matrices of explanatory variables, one for each equation bigK : n_eq x 1 array with number of explanatory variables by equation bigylag : spatially lagged dependent variable bigXlag : spatially lagged explanatory variable lamsur : spatial autoregressive coefficient in ML SUR Error bSUR : beta coefficients in ML SUR Error varb : variance of beta coefficients in ML SUR Error sig : error variance-covariance matrix in ML SUR Error bigE : n by n_eq matrix of vectors of residuals for each equation sur_inf : inference for regression coefficients, stand. error, t, p surchow : list with tuples for Chow test on regression coefficients each tuple contains test value, degrees of freedom, p-value name_bigy : dictionary with name of dependent variable for each equation name_bigX : dictionary with names of explanatory variables for each equation name_ds : string; name for the data set name_w : string; name for the weights file name_regimes : string; name of regime variable for use in the output
__init__(bigy, bigX, w, regimes=None, nonspat_diag=True, spat_diag=False, vm=False, name_bigy=None, name_bigX=None, name_ds=None, name_w=None, name_regimes=None)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

 __init__(bigy, bigX, w[, regimes, …]) Initialize self.