spreg.SURerrorML

class spreg.SURerrorML(bigy, bigX, w, df=None, regimes=None, nonspat_diag=True, spat_diag=False, vm=False, epsilon=1e-07, 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:
bigylist or dictionary

list with the name of the dependent variable for each equation or dictionary with vectors for dependent variable by equation

bigXlist or dictionary

list of lists the name of the explanatory variables for each equation or dictionary with matrix of explanatory variables by equation (note, already includes constant term)

wspatial weights object
dbPandas DataFrame

Optional. Required in case bigy and bigX are lists with names of variables

regimeslist

default = None. List of n values with the mapping of each observation to a regime. Assumed to be aligned with ‘x’.

epsilonfloat

convergence criterion for ML iterations. default 0.0000001

nonspat_diagbool

flag for non-spatial diagnostics, default = True

spat_diagbool

flag for spatial diagnostics, default = False

vmbool

flag for asymptotic variance for lambda and Sigma, default = False

name_bigydictionary

with name of dependent variable for each equation. default = None, but should be specified is done when sur_stackxy is used

name_bigXdictionary

with names of explanatory variables for each equation. default = None, but should be specified is done when sur_stackxy is used

name_dsstr

name for the data set

name_wstr

name for the weights file

name_regimesstr

name of regime variable for use in the output

Attributes:
nint

number of observations in each cross-section

n2int

n/2

n_eqint

number of equations

bigydictionary

with vectors of dependent variable, one for each equation

bigXdictionary

with matrices of explanatory variables, one for each equation

bigKarray

n_eq x 1 array with number of explanatory variables by equation

bigylagdictionary

spatially lagged dependent variable

bigXlagdictionary

spatially lagged explanatory variable

lamolsarray

spatial autoregressive coefficients from equation by equation ML-Error estimation

clikerrfloat

concentrated log-likelihood from equation by equation ML-Error estimation (no constant)

bSUR0array

SUR estimation for betas without spatial autocorrelation

llikfloat

log-likelihood for classic SUR estimation (includes constant)

lamsurfloat

spatial autoregressive coefficient in ML SUR Error

bSURarray

beta coefficients in ML SUR Error

varbarray

variance of beta coefficients in ML SUR Error

sigarray

error variance-covariance matrix in ML SUR Error

bigEarray

n by n_eq matrix of vectors of residuals for each equation

cliksurerrfloat

concentrated log-likelihood from ML SUR Error (no constant)

sur_infarray

inference for regression coefficients, stand. error, t, p

errllikfloat

log-likelihood for error model without SUR (with constant)

surerrllikfloat

log-likelihood for SUR error model (with constant)

lrtesttuple

likelihood ratio test for off-diagonal Sigma elements

likrlambdatuple

likelihood ratio test on spatial autoregressive coefficients

vmarray

asymptotic variance matrix for lambda and Sigma (only for vm=True)

lamsetparray

inference for lambda, stand. error, t, p (only for vm=True)

lamtesttuple

with test for constancy of lambda across equations (test value, degrees of freedom, p-value)

joinlamtuple

with test for joint significance of lambda across equations (test value, degrees of freedom, p-value)

surchowlist

with tuples for Chow test on regression coefficients. each tuple contains test value, degrees of freedom, p-value

name_bigydictionary

with name of dependent variable for each equation

name_bigXdictionary

with names of explanatory variables for each equation

name_dsstr

name for the data set

name_wstr

name for the weights file

name_regimesstr

name of regime variable for use in the output

Examples

>>> import libpysal
>>> import geopandas as gpd
>>> from spreg import SURerrorML

Open data on NCOVR US County Homicides (3085 areas) from libpysal examples using geopandas.

>>> nat = libpysal.examples.load_example('Natregimes')
>>> df = gpd.read_file(nat.get_path("natregimes.shp"))

The specification of the model to be estimated can be provided as lists. Each equation should be listed separately. In this example, 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']]

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 = libpysal.weights.Queen.from_dataframe(df)
>>> 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 = spreg.SURerrorML(y_var,x_var,w=w,df=df,name_ds="NAT",name_w="nat_queen")
>>> reg.bSUR
{0: array([[4.02228606],
       [0.88489637],
       [0.42402845]]), 1: array([[3.04923031],
       [1.10972632],
       [0.47075678]])}
>>> reg.sur_inf
{0: array([[ 0.36692175, 10.96224484,  0.        ],
       [ 0.14129077,  6.26294545,  0.        ],
       [ 0.04267954,  9.93516909,  0.        ]]), 1: array([[ 0.33139967,  9.20106629,  0.        ],
       [ 0.13352591,  8.31094381,  0.        ],
       [ 0.04004097, 11.75687747,  0.        ]])}
__init__(bigy, bigX, w, df=None, regimes=None, nonspat_diag=True, spat_diag=False, vm=False, epsilon=1e-07, name_bigy=None, name_bigX=None, name_ds=None, name_w=None, name_regimes=None)[source]

Methods

__init__(bigy, bigX, w[, df, regimes, ...])