spreg.PooledOLS

class spreg.PooledOLS(y, x, w, slx_lags=0, slx_vars='all', time_effects=False, robust=None, vm=False, nonspat_diag=False, spat_diag=True, BSK_list=['LMJ', 'LM1', 'LM2'], name_y=None, name_x=None, name_w=None, name_ds=None, latex=False)[source]

Pooled OLS for Panel Data.

This is the baseline model for panel data analysis. It stacks the cross-sectional data over time and runs a standard OLS regression, ignoring specific individual or time effects (unless dummies are manually provided).

Parameters:
ynumpy.ndarray or pandas object

nxt or (nxt)x1 array for dependent variable

xnumpy.ndarray or pandas object

nx(txk) or (nxt)xk array for independent (exogenous) variables, no constant

wpysal W object, optional

Spatial weights object. Not required for estimation, but required for spatial diagnostic tests (LM tests).

slx_lagsinteger

Number of spatial lags of X to include in the model specification. If slx_lags>0, the specification becomes of the SLX type.

slx_varseither “All” (default) or list of booleans to select x variables

to be lagged

time_effectsbool

If True, then include time dummies in the model specification (first omitted). Default: False.

robuststr, optional

If ‘white’, then a White consistent estimator of the variance-covariance matrix is given. If ‘hac’, then a HAC consistent estimator is given.

vmbool

if True, include variance-covariance matrix in summary results

nonspat_diagbool

if True, include non-spatial diagnostic tests in summary (default: False)

spat_diagbool

If True, then compute the BSK tests.

BSK_listlist of strings

List of BSK tests to compute if spat_diag is True. Options are “all”, “LMJ”, “LM1”, “LM2”, “LMC_spatial”, “LMC_RE” (default: [“LMJ”, “LM1”, “LM2”])

name_ystr

Name of dependent variable for use in output

name_xlist of strings

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

Attributes:
outputdataframe

regression results pandas dataframe

summarystr

Summary of regression results and diagnostics (note: use in conjunction with the print command)

betasarray

kx1 array of estimated coefficients

uarray

(nxt)x1 array of residuals

predyarray

(nxt)x1 array of predicted y values

ninteger

Total number of observations (N * T)

tinteger

Number of time periods

kinteger

Number of variables

mean_yfloat

Mean of dependent variable

std_yfloat

Standard deviation of dependent variable

vmarray

Variance covariance matrix (kxk)

sig2float

Sigma squared used in computations

logllfloat

Log-likelihood of the estimation

aicfloat

Akaike information criterion

schwarzfloat

Schwarz criterion

Examples

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

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. IMPORTANT: The 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. That is: x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc. 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]

Even if we are not running a spatial model, we need to specify the spatial weights matrix that includes the spatial configuration of the observations into the error component of the model for the diagnostics. 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 = PooledOLS(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, robust=None, vm=False, nonspat_diag=False, spat_diag=True, BSK_list=['LMJ', 'LM1', 'LM2'], name_y=None, name_x=None, name_w=None, name_ds=None, latex=False)[source]

Methods

__init__(y, x, w[, slx_lags, slx_vars, ...])

Attributes

mean_y

sig2n

sig2n_k

std_y

utu

vm

property mean_y
property sig2n
property sig2n_k
property std_y
property utu
property vm