spreg.Panel_RE_Error¶
- class spreg.Panel_RE_Error(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 error model with all results and diagnostics [Elh03].
- Parameters:
- y
numpy.ndarray
orpandas
object
nxt or (nxt)x1 array for dependent variable
- x
numpy.ndarray
orpandas
object
nx(txk) or (nxt)xk array for independent (exogenous) variables, no constant
- w
pysal
W
object
Spatial weights object
- epsilon
float
tolerance criterion in mimimize_scalar function and inverse_product
- vmbool
if True, include variance-covariance matrix in summary results
- name_y
str
Name of dependent variable for use in output
- name_x
list
of
strings
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
- y
- Attributes:
- betas
array
kx1 array of estimated coefficients
- lam
float
estimate of spatial autoregressive coefficient
- sig2_u
float
Sigma squared for random effects
- u
array
(nxt)x1 array of residuals
- e_filtered
array
(nxt)x1 array of spatially filtered residuals
- predy
array
(nxt)x1 array of predicted y values
- n
integer
Total number of observations
- t
integer
Number of time periods
- k
integer
Number of variables for which coefficients are estimated (no constant, excluding the lambda)
- y
array
(nxt)x1 array for dependent variable
- x
array
Two dimensional array with nxt rows and one column for each independent (exogenous) variable, including the constant
- mean_y
float
Mean of dependent variable
- std_y
float
Standard deviation of dependent variable
- vm
array
Variance covariance matrix (k+2 x k+2), all coefficients
- vm1
array
Variance covariance matrix (k+3 x k+3), includes sig2
- sig2
float
Sigma squared used in computations
- logll
float
maximized log-likelihood (including constant terms)
- aic
float
Akaike information criterion
- schwarz
float
Schwarz criterion
- pr2
float
Pseudo R squared (squared correlation between y and ypred)
- utu
float
Sum of squared residuals
- std_err
array
1x(k+1) array of standard errors of the betas
- z_stat
list
of
tuples
z statistic; each tuple contains the pair (statistic, p-value), where each is a float
- name_y
str
Name of dependent variable for use in output
- name_x
list
of
strings
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
- title
str
Name of the regression method used
- betas
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_error = spreg.Panel_RE_Error(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_error.betas, decimals=4) array([[5.87893756], [3.23269025], [2.62996804], [0.34042682], [4.9782446]])
- __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
- property mean_y¶
- property sig2n¶
- property sig2n_k¶
- property std_y¶
- property utu¶
- property vm¶