spreg.GM_ErrorRE¶
- class spreg.GM_ErrorRE(y, x, w, slx_lags=0, slx_vars='all', time_effects=False, full_weights=False, regimes=None, vm=False, name_y=None, name_x=None, name_w=None, name_ds=None, name_regimes=None, latex=False)[source]¶
GMM method for a spatial random effects panel model based on Kapoor, Kelejian and Prucha (2007) [KKP07].
- Parameters:
- y
arrayorpandasDataFrame n*tx1 or nxt array for dependent variable
- x
arrayorpandasDataFrame Two dimensional array or DF with n*t rows and k columns for independent (exogenous) variable or n rows and k*t columns (note, must not include a constant term)
- w
spatialweightsobject Spatial weights matrix, nxn
- slx_lags
integer Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type.
- slx_vars
either“All” (default)orlistofbooleanstoselectxvariables to be lagged
- time_effectsbool
If True, then include time dummies in the model specification (first omitted). Default: False
- full_weights: boolean
Considers different weights for each of the 6 moment conditions if True or only 2 sets of weights for the first 3 and the last 3 moment conditions if False (default)
- vmbool
If True, include variance-covariance matrix in summary results
- name_y
strorlistofstrings Name of dependent variable for use in output
- name_x
listofstrings Names of independent variables for use in output
- name_w
str Name of weights matrix for use in output
- name_ds
str Name of dataset for use in output
- latexbool
Specifies if summary is to be printed in latex format
- y
- Attributes:
- output
dataframe regression results pandas dataframe
- summary
str Summary of regression results and diagnostics (note: use in conjunction with the print command)
- betas
array kx1 array of estimated coefficients
- u
array nx1 array of residuals
- predy
array nx1 array of predicted y values
- n
integer Number of observations
- t
integer Number of time periods
- k
integer Number of variables for which coefficients are estimated (including the constant)
- y
array nx1 array for dependent variable
- x
array Two dimensional array with n rows and one column for each independent (exogenous) variable, including the constant
- vm
array Variance covariance matrix (kxk)
- name_y
str Name of dependent variable for use in output
- name_x
listofstrings Names of independent variables for use in output
- name_w
str Name of weights matrix for use in output
- name_ds
str Name of dataset for use in output
- output
Examples
>>> import libpysal >>> import geopandas as gpd >>> import numpy as np >>> from spreg import GM_ErrorRE
In this example, we will use data on NCOVR US County Homicides (3085 areas) included in libpysal.
>>> libpysal.examples.load_example('NCOVR') >>> db = gpd.read_file(libpysal.examples.get_path("NAT.shp")) >>> name_ds = "NCOVR.shp"
Extract the HR (homicide rates) data in the 70’s, 80’s and 90’s from the dataframe and make it the dependent variable for the regression. Note that the data can also be passed in the long format instead of wide format (i.e. a vector with n*t rows and a single column for the dependent variable and a matrix of dimension n*txk for the independent variables).
>>> y_name = ['HR70','HR80','HR90'] >>> y = db[y_name]
Extract RD and PS in the same time periods from the dataframe to be used as independent variables in the regression. Data must be organized in a way that all time periods of a given variable are side-by-side and in the correct time order. By default a vector of ones will be added to the independent variables passed in.
>>> x_names = ['RD70','RD80','RD90','PS70','PS80','PS90'] >>> x = db[x_names]
Since we want to run a spatial error panel model, we need to specify the spatial weights matrix that includes the spatial configuration of the observations into the error component of the model. To do that, we can open an already existing gal file or create a new one. In this case, we will create one from
NAT.shp.>>> w = libpysal.weights.Queen.from_dataframe(db, use_index=True) >>> w.transform = 'r' >>> name_w = "NCOVR.gal"
We are all set with the preliminaries, we are good to run the model.
>>> reg = GM_ErrorRE(y, x, w)
Once we have run the model, we can explore a little bit the output with the command print(reg.summary).
- __init__(y, x, w, slx_lags=0, slx_vars='all', time_effects=False, full_weights=False, regimes=None, vm=False, name_y=None, name_x=None, name_w=None, name_ds=None, name_regimes=None, latex=False)[source]¶
Methods
__init__(y, x, w[, slx_lags, slx_vars, ...])Attributes
- property mean_y¶
- property std_y¶