spreg.Panel_RE_Lag

class spreg.Panel_RE_Lag(y, x, w, epsilon=1e-07, vm=False, name_y=None, name_x=None, name_w=None, name_ds=None)[source]

ML estimation of the random effects spatial lag model with all results and diagnostics [Elh03].

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, excluding the constant

wpysal W object

Spatial weights object

epsilonfloat

tolerance criterion in mimimize_scalar function and inverse_product

vmbool

if True, include variance-covariance matrix in summary results

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

Attributes:
betasarray

(k+2)x1 array of estimated coefficients (rho and phi last)

rhofloat

estimate of spatial autoregressive coefficient

phifloat

estimate of weight attached to the cross-sectional component phi^2 = sig2 / (t*sig2_u + sig2)

uarray

(nxt)x1 array of residuals

predyarray

(nxt)x1 array of predicted y values

ninteger

Total number of observations

tinteger

Number of time periods

kinteger

Number of variables for which coefficients are estimated (excluding the phi)

yarray

(nxt)x1 array for dependent variable

xarray

Two dimensional array with nxt rows and one column for each independent (exogenous) variable

mean_yfloat

Mean of dependent variable

std_yfloat

Standard deviation of dependent variable

vmarray

Variance covariance matrix (k+2 x k+2)

vm1array

Variance covariance matrix (k+3 x k+3) includes sigma2

sig2float

Sigma squared used in computations

logllfloat

maximized log-likelihood (including constant terms)

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

1x(k+1) array of standard errors of the betas

z_statlist of tuples

z statistic; each tuple contains the pair (statistic, p-value), where each is a float

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

titlestr

Name of the regression method used

Examples

>>> import numpy as np
>>> import pandas as pd
>>> import libpysal
>>> import spreg
>>> nat = libpysal.examples.load_example("NCOVR")
>>> db = libpysal.io.open(nat.get_path("NAT.dbf"), "r")
>>> nat_shp = libpysal.examples.get_path("NAT.shp")
>>> w_full = libpysal.weights.Queen.from_shapefile(nat_shp)
>>> name_y = ["HR70", "HR80", "HR90"]
>>> y_full = np.array([db.by_col(name) for name in name_y]).T
>>> name_x = ["RD70", "RD80", "RD90", "PS70", "PS80", "PS90"]
>>> x_full = np.array([db.by_col(name) for name in name_x]).T
>>> name_c = ["STATE_NAME", "FIPSNO"]
>>> df_counties = pd.DataFrame([db.by_col(name) for name in name_c], index=name_c).T
>>> filter_states = ["Kansas", "Missouri", "Oklahoma", "Arkansas"]
>>> filter_counties = df_counties[df_counties["STATE_NAME"].isin(filter_states)]["FIPSNO"].values
>>> counties = np.array(db.by_col("FIPSNO"))
>>> subid = np.where(np.isin(counties, filter_counties))[0]
>>> w = w_subset(w_full, subid)
>>> w.transform = 'r'
>>> y = y_full[subid, ]
>>> x = x_full[subid, ]
>>> re_lag = spreg.Panel_RE_Lag(y, x, w, name_y=name_y, name_x=name_x, name_ds="NAT")
Warning: Assuming panel is in wide format, i.e. y[:, 0] refers to T0, y[:, 1] refers to T1, etc.
Similarly, assuming x[:, 0:T] refers to T periods of k1, x[:, T+1:2T] refers to k2, etc.
np.around(re_lag.betas, decimals=4)
array([[4.44421994],
       [2.52821717],
       [2.24768846],
       [0.25846846],
       [0.68426639]])
__init__(y, x, w, epsilon=1e-07, vm=False, name_y=None, name_x=None, name_w=None, name_ds=None)[source]

Methods

__init__(y, x, w[, epsilon, vm, name_y, ...])

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