Title: | Estimation of Spatial Autoregressive Models with and without Heteroskedastic Innovations |
---|---|
Description: | Functions for fitting Cliff-Ord-type spatial autoregressive models with and without heteroskedastic innovations using Generalized Method of Moments estimation are provided. Some support is available for fitting spatial HAC models, and for fitting with non-spatial endogeneous variables using instrumental variables. |
Authors: | Gianfranco Piras [aut, cre] , Roger Bivand [ctb] |
Maintainer: | Gianfranco Piras <[email protected]> |
License: | GPL-2 |
Version: | 2.1-1 |
Built: | 2024-12-06 18:42:53 UTC |
Source: | CRAN |
A set of functions to estimate spatial models with heteroskedastic innovations
Package: | sphet |
Type: | Package |
Version: | 1.12 |
Date: | 2021-06-17 |
License: | GPL |
LazyLoad: | yes |
Gianfranco Piras [email protected]
Piras, Gianfranco (2010) sphet: Spatial Models with Heteroskedastic Innovations in R, Journal of Statistical Software June 2010, Volume 35, Issue 1.
Bivand, R; Millo, G; Piras, G. (2021) A Review of Software for Spatial Econometrics in R Mathematics 9 (11):1276.
Bivand, R; Piras, G. (2015) Comparing Implementations of Estimation Methods for Spatial Econometrics, Journal of Statistical Software, Volume 63, Issue 18, 1–36.
The function generates k-ahead and k-behind weighting matrices as in Kelejian and Prucha (1999)
circular(nrow, ncol, ab)
circular(nrow, ncol, ab)
nrow |
Number of rows |
ncol |
Number of columns |
ab |
Ahead - behind |
Generate circular weigthing matrices
An object of class nb
Gianfranco Piras [email protected]
ab.3 <- circular(10, 10, 3) ab.5 <- circular(15, 15, 5)
ab.3 <- circular(10, 10, 3) ab.5 <- circular(15, 15, 5)
Object of class distance for Columbus dataset 10-nearest neighbors matrix for columbus dataset
A list of neighbors and distances for the columbus neighborhoods
Gianfranco Piras [email protected]
Reads points coordinates and generates objects of class distance.matrix
distance(coord, region.id = NULL, output = TRUE, type = c("NN", "distance", "inverse"), measure = c("euclidean", "gcircle", "chebyshev", "braycur", "canberra"), nn = 6, cutoff = FALSE, miles = TRUE, R = NULL, shape.name = NULL, region.id.name = NULL, firstline = FALSE, file.name = NULL)
distance(coord, region.id = NULL, output = TRUE, type = c("NN", "distance", "inverse"), measure = c("euclidean", "gcircle", "chebyshev", "braycur", "canberra"), nn = 6, cutoff = FALSE, miles = TRUE, R = NULL, shape.name = NULL, region.id.name = NULL, firstline = FALSE, file.name = NULL)
coord |
a matrix with the (X,Y)-coordinates of the points. The first column can be the region.id variable giving the ordering of the observations |
region.id |
variable that defines the ordering of the observations |
output |
when TRUE (default) writes the object to a file |
type |
one of |
measure |
one of |
nn |
the number of nearest neighbors |
cutoff |
If type is |
miles |
If TRUE (default), distances are in miles, otherwise in Km. (See |
R |
deprecated, |
shape.name |
The name of the shape file. See Details |
region.id.name |
The name of the |
firstline |
If |
file.name |
If |
Writes distance matrices
The object created is similar to the content of a 'GWT'
file. The output file can be of any format.
In particular, it could be a 'GWT'
file. When firstline
is TRUE
, an header line is added to the 'GWT'
file.
The first element is simply a place holder, the second is the number of observations. The name of the shape file
and of the id variable can be specified by the options shape.name
and region.id.name
respectively.
The function performs a series of test on the region.id
variable. If a region.id
variable is not specified and
coord
only has two columns, a sequence from 1 to the number of observations is generated and
used as identification variable. If region.id
is specified
and the first column of coord
contains an id variable they should be the same.
The distance measures implemented in sphet
are:
'euclidean'
:
'chebyshev'
:
'braycur'
:
'canberra'
:
'gcircle'
: see spDists
, which uses an approximation to the WGS84 spheroid.
A matrix
of three columns: from
, to
, and distance
Gianfranco Piras [email protected]
set.seed("1234") X <- runif(100, 0, 70) Y <- runif(100, -30, 20) coord1 <- cbind(seq(1,100), X, Y) thm2 <- distance(coord1, region.id = NULL, output = FALSE, type = "NN", nn = 6) thm2 <- distance(coord1, region.id = NULL, output = FALSE, type = "distance", cutoff = 1)
set.seed("1234") X <- runif(100, 0, 70) Y <- runif(100, -30, 20) coord1 <- cbind(seq(1,100), X, Y) thm2 <- distance(coord1, region.id = NULL, output = FALSE, type = "NN", nn = 6) thm2 <- distance(coord1, region.id = NULL, output = FALSE, type = "distance", cutoff = 1)
Multi step GM/IV estimation of a linear Cliff and Ord -type of model of the form:
with
The model allows for spatial lag in the dependent variable and disturbances. The innovations in the disturbance process are assumed heteroskedastic of an unknown form.
gstslshet(formula, data = list(), listw, na.action = na.fail, zero.policy = NULL, initial.value = 0.2, abs.tol = 1e-20, rel.tol = 1e-10, eps = 1e-5, inverse = T, sarar = T)
gstslshet(formula, data = list(), listw, na.action = na.fail, zero.policy = NULL, initial.value = 0.2, abs.tol = 1e-20, rel.tol = 1e-10, eps = 1e-5, inverse = T, sarar = T)
formula |
a description of the model to be fit |
data |
an object of class data.frame. An optional data frame containing the variables in the model. |
listw |
an object of class |
na.action |
a function which indicates what should happen when the data contains missing values. See lm for details. |
zero.policy |
See |
initial.value |
The initial value for |
abs.tol |
Absolute tolerance. See nlminb for details. |
rel.tol |
Relative tolerance. See nlminb for details. |
eps |
Tolerance level for the approximation. See Details. |
inverse |
|
sarar |
|
The procedure consists of two steps alternating GM and IV estimators. Each step consists of sub-steps.
In step one is estimated by 2SLS. The 2SLS residuals are first employed
to obtain an initial (consistent but not efficient) GM estimator of
and then a consistent and efficient
estimator (involving the variance-covariance matrix of the limiting distribution of the normalized sample moments).
In step two, the spatial Cochrane-Orcutt transformed model is estimated by 2SLS. This corresponds to a GS2SLS procedure.
The GS2SLS residuals are used to obtain a consistent and efficient GM estimator for
.
The initial value for the optimization in step 1b is taken to be initial.value
. The initial value in step 1c is the
optimal parameter of step 1b. Finally, the initial value for the optimization of step 2b is the optimal parameter of step 1c.
Internally, the object of class listw
is transformed into a Matrix
using the function listw2dgCMatrix
.
The expression of the estimated variance covariance matrix of the limiting
distribution of the normalized sample moments based on 2SLS residuals
involves the inversion of .
When
inverse
is FALSE
, the inverse is calculated using the approximation
.
The powers considered depend on a condition.
The function will keep adding terms until the absolute value of the
sum
of all elements
of the matrix is greater than a fixed
(
eps
). By default eps
is set to 1e-5.
A list object of class sphet
coefficients |
Generalized Spatial two stage least squares coefficient estimates of |
var |
variance-covariance matrix of the estimated coefficients |
s2 |
GS2SLS residuals variance |
residuals |
GS2SLS residuals |
yhat |
difference between GS2SLS residuals and response variable |
call |
the call used to create this object |
model |
the model matrix of data |
method |
|
W |
Wald test for both |
Gianfranco Piras [email protected]
Arraiz, I. and Drukker, M.D. and Kelejian, H.H. and Prucha, I.R. (2007) A spatial Cliff-Ord-type Model with Heteroskedastic Innovations: Small and Large Sample Results, Department of Economics, University of Maryland'
Kelejian, H.H. and Prucha, I.R. (2007) Specification and Estimation of Spatial Autoregressive Models with Autoregressive and Heteroskedastic Disturbances, Journal of Econometrics, forthcoming.
Kelejian, H.H. and Prucha, I.R. (1999) A Generalized Moments Estimator for the Autoregressive Parameter in a Spatial Model, International Economic Review, 40, pages 509–533.
Kelejian, H.H. and Prucha, I.R. (1998) A Generalized Spatial Two Stage Least Square Procedure for Estimating a Spatial Autoregressive Model with Autoregressive Disturbances, Journal of Real Estate Finance and Economics, 17, pages 99–121.
data(columbus, package = "spdep") listw <- spdep::nb2listw(col.gal.nb) res <- gstslshet(CRIME ~ HOVAL + INC, data = columbus, listw = listw) summary(res)
data(columbus, package = "spdep") listw <- spdep::nb2listw(col.gal.nb) res <- gstslshet(CRIME ~ HOVAL + INC, data = columbus, listw = listw) summary(res)
Generate impacts for objects of class error_sphet created in sphet
## S3 method for class 'error_sphet' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL )
## S3 method for class 'error_sphet' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL )
obj |
A spreg spatial regression object created by |
... |
Arguments passed through to methods in the coda package |
tr |
A vector of traces of powers of the spatial weights matrix created using |
R |
If given, simulations are used to compute distributions for the impact measures, returned as |
listw |
a listw object |
evalues |
vector of eigenvalues of spatial weights matrix for impacts calculations |
tol |
Argument passed to |
empirical |
Argument passed to |
Q |
default NULL, else an integer number of cumulative power series impacts to calculate if |
Estimate of the Average Total, Average Direct, and Average Indirect Effects
library(sphet) require("sf", quietly=TRUE) columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) listw <- spdep::nb2listw(col.gal.nb) error1 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "error") summary(error1) impacts(error1) summary(impacts(error1)) error2 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "error") impacts(error2) error3 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "error") summary(impacts(error3))
library(sphet) require("sf", quietly=TRUE) columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) listw <- spdep::nb2listw(col.gal.nb) error1 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "error") summary(error1) impacts(error1) summary(impacts(error1)) error2 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "error") impacts(error2) error3 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "error") summary(impacts(error3))
Generate impacts for spreg lag and sarar models
Generate impacts for objects of class sarar_gmm created in sphet
## S3 method for class 'gstsls' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL, KPformula = FALSE, prt = TRUE )
## S3 method for class 'gstsls' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL, KPformula = FALSE, prt = TRUE )
obj |
A spreg spatial regression object created by |
... |
Arguments passed through to methods in the coda package |
tr |
A vector of traces of powers of the spatial weights matrix created using |
R |
If given, simulations are used to compute distributions for the impact measures, returned as |
listw |
a listw object |
evalues |
vector of eigenvalues of spatial weights matrix for impacts calculations |
tol |
Argument passed to |
empirical |
Argument passed to |
Q |
default NULL, else an integer number of cumulative power series impacts to calculate if |
KPformula |
default FALSE, else inference of the impacts based on Kelejian and Piras (2020) |
prt |
prints the KP summary of the VC matrix |
Estimate of the Average Total, Average Direct, and Average Indirect Effects
Estimate of the Average Total, Average Direct, and Average Indirect Effects
Roger Bivand, Gianfranco Piras (2015). Comparing Implementations of Estimation Methods for Spatial Econometrics. Journal of Statistical Software, 63(18), 1-36. https://www.jstatsoft.org/v63/i18/. Harry Kelejian, Gianfranco Piras (2020). Spillover effects in spatial models: Generalization and extensions. Journal of Regional Science, 60(3), 425-442. Gianfranco Piras, Paolo Postiglione (2022). A deeper look at impacts in spatial Durbin model with sphet. Geographical Analysis, 54(3), 664-684.
data(columbus, package="spdep") listw <- spdep::nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus , listw= listw, het = TRUE, verbose = FALSE, model = "sarar") summary(res) effects <- impacts(res, listw = listw, R = 399) summary(effects) data(boston, package="spData") Wb <- as(spdep::nb2listw(boston.soi), "CsparseMatrix") ev <- eigen(Wb)$values trMatb <- spatialreg::trW(Wb, type="mult") sarar1 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = Wb, model = "sarar") summary(sarar1) impacts(sarar1, KPformula = TRUE) summary(impacts(sarar1, tr = trMatb, R=1000), zstats=TRUE, short=TRUE) summary(impacts(sarar1, evalues = ev, R=1000), zstats=TRUE, short=TRUE) sarar2 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = Wb, model = "sarar", Durbin = TRUE) summary(sarar2) impacts(sarar2, evalues = ev, KPformula = TRUE) impacts(sarar2, evalues = ev) impacts(sarar2, listw = spdep::nb2listw(boston.soi)) impacts(sarar2, tr = trMatb) summary(impacts(sarar2, evalues = ev, R=1000), zstats=TRUE, short=TRUE) sarar3 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = Wb, model = "sarar", Durbin = ~CRIM + TAX) summary(sarar3) impacts(sarar3, evalues = ev) impacts(sarar3, evalues = ev, KPformula = TRUE) impacts(sarar3, evalues = ev, KPformula = TRUE, tr = trMatb) impacts(sarar3, listw = spdep::nb2listw(boston.soi)) impacts(sarar3, tr = trMatb) summary(impacts(sarar3, listw = spdep::nb2listw(boston.soi), R=1000), zstats=TRUE, short=TRUE) sarar4 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B , data = boston.c, listw = Wb, model = "sarar", Durbin = ~CRIM + TAX + log(LSTAT)) summary(sarar4) impacts(sarar4, evalues = ev) summary(impacts(sarar4, evalues = ev, R=1000), zstats=TRUE, short=TRUE) sarar5 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS), data = boston.c, listw = Wb, model = "sarar", Durbin = ~ TAX + log(LSTAT)) summary(sarar5) impacts(sarar5, evalues = ev) summary(impacts(sarar4, tr = trMatb, R=1000), zstats=TRUE, short=TRUE)
data(columbus, package="spdep") listw <- spdep::nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus , listw= listw, het = TRUE, verbose = FALSE, model = "sarar") summary(res) effects <- impacts(res, listw = listw, R = 399) summary(effects) data(boston, package="spData") Wb <- as(spdep::nb2listw(boston.soi), "CsparseMatrix") ev <- eigen(Wb)$values trMatb <- spatialreg::trW(Wb, type="mult") sarar1 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = Wb, model = "sarar") summary(sarar1) impacts(sarar1, KPformula = TRUE) summary(impacts(sarar1, tr = trMatb, R=1000), zstats=TRUE, short=TRUE) summary(impacts(sarar1, evalues = ev, R=1000), zstats=TRUE, short=TRUE) sarar2 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = Wb, model = "sarar", Durbin = TRUE) summary(sarar2) impacts(sarar2, evalues = ev, KPformula = TRUE) impacts(sarar2, evalues = ev) impacts(sarar2, listw = spdep::nb2listw(boston.soi)) impacts(sarar2, tr = trMatb) summary(impacts(sarar2, evalues = ev, R=1000), zstats=TRUE, short=TRUE) sarar3 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT), data = boston.c, listw = Wb, model = "sarar", Durbin = ~CRIM + TAX) summary(sarar3) impacts(sarar3, evalues = ev) impacts(sarar3, evalues = ev, KPformula = TRUE) impacts(sarar3, evalues = ev, KPformula = TRUE, tr = trMatb) impacts(sarar3, listw = spdep::nb2listw(boston.soi)) impacts(sarar3, tr = trMatb) summary(impacts(sarar3, listw = spdep::nb2listw(boston.soi), R=1000), zstats=TRUE, short=TRUE) sarar4 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B , data = boston.c, listw = Wb, model = "sarar", Durbin = ~CRIM + TAX + log(LSTAT)) summary(sarar4) impacts(sarar4, evalues = ev) summary(impacts(sarar4, evalues = ev, R=1000), zstats=TRUE, short=TRUE) sarar5 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS), data = boston.c, listw = Wb, model = "sarar", Durbin = ~ TAX + log(LSTAT)) summary(sarar5) impacts(sarar5, evalues = ev) summary(impacts(sarar4, tr = trMatb, R=1000), zstats=TRUE, short=TRUE)
Generate impacts for objects of class ols_sphet created in sphet
## S3 method for class 'ols_sphet' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL )
## S3 method for class 'ols_sphet' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL )
obj |
A spreg spatial regression object created by |
... |
Arguments passed through to methods in the coda package |
tr |
A vector of traces of powers of the spatial weights matrix created using |
R |
If given, simulations are used to compute distributions for the impact measures, returned as |
listw |
a listw object |
evalues |
vector of eigenvalues of spatial weights matrix for impacts calculations |
tol |
Argument passed to |
empirical |
Argument passed to |
Q |
default NULL, else an integer number of cumulative power series impacts to calculate if |
Estimate of the Average Total, Average Direct, and Average Indirect Effects
data(boston, package="spData") Wb <- as(spdep::nb2listw(boston.soi), "CsparseMatrix") ev <- eigen(Wb)$values trMatb <- spatialreg::trW(Wb, type="mult") lm.D <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS), data = boston.c, listw = Wb, model = "ols", Durbin = TRUE) summary(lm.D) impacts(lm.D) summary(impacts(lm.D)) lm.D2 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS), data = boston.c, listw = Wb, model = "ols", Durbin = ~AGE) summary(lm.D2) impacts(lm.D2) summary(impacts(lm.D2)) lm.D3 <- spreg(log(CMEDV) ~ CRIM + ZN + CHAS + I(NOX^2) + I(RM^2) + AGE, data = boston.c, listw = Wb, model = "ols", Durbin = ~AGE + INDUS ) summary(lm.D3) impacts(lm.D3) summary(impacts(lm.D3)) require("sf", quietly=TRUE) columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) listw <- spdep::nb2listw(col.gal.nb) knear <- spdep::knearneigh(cbind(columbus$X, columbus$Y), 5) knb <- spdep::knn2nb(knear) dist <- spdep::nbdists(knb, cbind(columbus$X, columbus$Y)) k5d <- spdep::nb2listw(knb, glist = dist, style = "B") class(k5d) <- c("listw", "nb", "distance") lm.D4 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "ols") summary(lm.D4) impacts(lm.D4) lm.D5 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "ols") summary(lm.D5) impacts(lm.D5) summary(impacts(lm.D5)) lm.D6 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "ols") summary(lm.D6) summary(impacts(lm.D6)) ## Not run: lm.D7 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, model = "ols", HAC = TRUE, distance = k5d, type = "Triangular") summary(lm.D7) impacts(lm.D7) summary(impacts(lm.D7)) ## End(Not run) lm.D8 <- spreg(CRIME ~ INC + HOVAL, data = columbus, listw = listw, Durbin=TRUE, model = "ols", distance = k5d, type = "Triangular") summary(lm.D8) impacts(lm.D8) summary(impacts(lm.D8)) lmD.9 <- spreg(CRIME ~ INC + HOVAL, data = columbus, listw = listw, Durbin= ~ INC, model = "ols", distance = k5d, type = "Parzen") impacts(lmD.9) lmD.10 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "ols", distance = k5d, type = "Bisquare") summary(lmD.10) summary(impacts(lmD.10))
data(boston, package="spData") Wb <- as(spdep::nb2listw(boston.soi), "CsparseMatrix") ev <- eigen(Wb)$values trMatb <- spatialreg::trW(Wb, type="mult") lm.D <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS), data = boston.c, listw = Wb, model = "ols", Durbin = TRUE) summary(lm.D) impacts(lm.D) summary(impacts(lm.D)) lm.D2 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) + AGE + log(DIS), data = boston.c, listw = Wb, model = "ols", Durbin = ~AGE) summary(lm.D2) impacts(lm.D2) summary(impacts(lm.D2)) lm.D3 <- spreg(log(CMEDV) ~ CRIM + ZN + CHAS + I(NOX^2) + I(RM^2) + AGE, data = boston.c, listw = Wb, model = "ols", Durbin = ~AGE + INDUS ) summary(lm.D3) impacts(lm.D3) summary(impacts(lm.D3)) require("sf", quietly=TRUE) columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) listw <- spdep::nb2listw(col.gal.nb) knear <- spdep::knearneigh(cbind(columbus$X, columbus$Y), 5) knb <- spdep::knn2nb(knear) dist <- spdep::nbdists(knb, cbind(columbus$X, columbus$Y)) k5d <- spdep::nb2listw(knb, glist = dist, style = "B") class(k5d) <- c("listw", "nb", "distance") lm.D4 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "ols") summary(lm.D4) impacts(lm.D4) lm.D5 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "ols") summary(lm.D5) impacts(lm.D5) summary(impacts(lm.D5)) lm.D6 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "ols") summary(lm.D6) summary(impacts(lm.D6)) ## Not run: lm.D7 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, model = "ols", HAC = TRUE, distance = k5d, type = "Triangular") summary(lm.D7) impacts(lm.D7) summary(impacts(lm.D7)) ## End(Not run) lm.D8 <- spreg(CRIME ~ INC + HOVAL, data = columbus, listw = listw, Durbin=TRUE, model = "ols", distance = k5d, type = "Triangular") summary(lm.D8) impacts(lm.D8) summary(impacts(lm.D8)) lmD.9 <- spreg(CRIME ~ INC + HOVAL, data = columbus, listw = listw, Durbin= ~ INC, model = "ols", distance = k5d, type = "Parzen") impacts(lmD.9) lmD.10 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "ols", distance = k5d, type = "Bisquare") summary(lmD.10) summary(impacts(lmD.10))
Generate impacts for objects of class lag_gmm created in sphet
## S3 method for class 'stsls_sphet' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL, KPformula = FALSE, prt = TRUE )
## S3 method for class 'stsls_sphet' impacts( obj, ..., tr = NULL, R = NULL, listw = NULL, evalues = NULL, tol = 1e-06, empirical = FALSE, Q = NULL, KPformula = FALSE, prt = TRUE )
obj |
A spreg spatial regression object created by |
... |
Arguments passed through to methods in the coda package |
tr |
A vector of traces of powers of the spatial weights matrix created using |
R |
If given, simulations are used to compute distributions for the impact measures, returned as |
listw |
a listw object |
evalues |
vector of eigenvalues of spatial weights matrix for impacts calculations |
tol |
Argument passed to |
empirical |
Argument passed to |
Q |
default NULL, else an integer number of cumulative power series impacts to calculate if |
KPformula |
default FALSE, else inference of the impacts based on Kelejian and Piras (2020) |
prt |
prints the KP summary of the VC matrix |
Estimate of the Average Total, Average Direct, and Average Indirect Effects
Roger Bivand, Gianfranco Piras (2015). Comparing Implementations of Estimation Methods for Spatial Econometrics. Journal of Statistical Software, 63(18), 1-36. https://www.jstatsoft.org/v63/i18/. Harry Kelejian, Gianfranco Piras (2020). Spillover effects in spatial models: Generalization and extensions. Journal of Regional Science, 60(3), 425-442. Gianfranco Piras, Paolo Postiglione (2022). A deeper look at impacts in spatial Durbin model with sphet. Geographical Analysis, 54(3), 664-684.
require("sf", quietly=TRUE) library(coda) columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) listw <- spdep::nb2listw(col.gal.nb) ev <- spatialreg::eigenw(listw) W <- as(listw, "CsparseMatrix") trMatc <- spatialreg::trW(W, type="mult") trMC <- spatialreg::trW(W, type="MC") #LAG lobj_gm <- spreg(CRIME ~ INC + HOVAL, columbus, listw, model = "lag") summary(lobj_gm) lobj_gmh <- spreg(CRIME ~ INC + HOVAL, columbus, listw, model = "lag", het = TRUE) summary(lobj_gmh) set.seed(1) impacts(lobj_gm, listw=listw) impacts(lobj_gm, tr=trMatc) impacts(lobj_gm, tr=trMC) impacts(lobj_gm, evalues=ev) impacts(lobj_gmh, listw=listw) impacts(lobj_gmh, tr=trMatc) impacts(lobj_gmh, tr=trMC) impacts(lobj_gmh, evalues=ev) #same impacts but different SD summary(impacts(lobj_gm, evalues = ev, R = 1000)) summary(impacts(lobj_gmh, evalues = ev, R = 1000)) lobjIQ5_gm <- impacts(lobj_gm, tr=trMatc, R=1000, Q=5) summary(lobjIQ5_gm, zstats=TRUE, short=TRUE) summary(lobjIQ5_gm, zstats=TRUE, short=TRUE, reportQ=TRUE) # LAG durbin TRUE mobj_gm <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "lag") summary(mobj_gm) mobj_gmh <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "lag", het = TRUE) mobj_gm2 <- spreg(CRIME ~ INC, columbus, listw, Durbin=TRUE, model = "lag") summary(mobj_gmh) impacts(mobj_gm, KPformula = TRUE) impacts(mobj_gm2, KPformula = TRUE) summary(impacts(mobj_gm2, evalues=ev, R=1000), short=TRUE, zstats=TRUE) impacts(mobj_gm, listw=listw) impacts(mobj_gm, tr=trMatc) impacts(mobj_gm, tr=trMC) impacts(mobj_gm, evalues=ev) summary(impacts(mobj_gm, evalues=ev, R=1000), short=TRUE, zstats=TRUE) impacts(mobj_gmh, listw=listw) impacts(mobj_gmh, tr=trMatc) impacts(mobj_gmh, tr=trMC) impacts(mobj_gmh, evalues=ev) summary(impacts(mobj_gmh, tr=trMatc, R=1000), short=TRUE, zstats=TRUE) #lag durbin = ~formula mobj1_gm <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "lag") mobj1_gmh <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "lag", het = TRUE) impacts(mobj1_gm, tr=trMatc) impacts(mobj1_gm, listw=listw) impacts(mobj1_gm, KPformula = TRUE) summary(impacts(mobj_gm, evalues=ev, R=200), short=TRUE, zstats=TRUE) summary(impacts(mobj1_gm, tr=trMatc, R=200), short=TRUE, zstats=TRUE) mobj1_gm <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "lag") summary(impacts(mobj1_gm, evalues=ev, R=200), short=TRUE, zstats=TRUE)
require("sf", quietly=TRUE) library(coda) columbus <- st_read(system.file("shapes/columbus.gpkg", package="spData")[1], quiet=TRUE) col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1]) listw <- spdep::nb2listw(col.gal.nb) ev <- spatialreg::eigenw(listw) W <- as(listw, "CsparseMatrix") trMatc <- spatialreg::trW(W, type="mult") trMC <- spatialreg::trW(W, type="MC") #LAG lobj_gm <- spreg(CRIME ~ INC + HOVAL, columbus, listw, model = "lag") summary(lobj_gm) lobj_gmh <- spreg(CRIME ~ INC + HOVAL, columbus, listw, model = "lag", het = TRUE) summary(lobj_gmh) set.seed(1) impacts(lobj_gm, listw=listw) impacts(lobj_gm, tr=trMatc) impacts(lobj_gm, tr=trMC) impacts(lobj_gm, evalues=ev) impacts(lobj_gmh, listw=listw) impacts(lobj_gmh, tr=trMatc) impacts(lobj_gmh, tr=trMC) impacts(lobj_gmh, evalues=ev) #same impacts but different SD summary(impacts(lobj_gm, evalues = ev, R = 1000)) summary(impacts(lobj_gmh, evalues = ev, R = 1000)) lobjIQ5_gm <- impacts(lobj_gm, tr=trMatc, R=1000, Q=5) summary(lobjIQ5_gm, zstats=TRUE, short=TRUE) summary(lobjIQ5_gm, zstats=TRUE, short=TRUE, reportQ=TRUE) # LAG durbin TRUE mobj_gm <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "lag") summary(mobj_gm) mobj_gmh <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE, model = "lag", het = TRUE) mobj_gm2 <- spreg(CRIME ~ INC, columbus, listw, Durbin=TRUE, model = "lag") summary(mobj_gmh) impacts(mobj_gm, KPformula = TRUE) impacts(mobj_gm2, KPformula = TRUE) summary(impacts(mobj_gm2, evalues=ev, R=1000), short=TRUE, zstats=TRUE) impacts(mobj_gm, listw=listw) impacts(mobj_gm, tr=trMatc) impacts(mobj_gm, tr=trMC) impacts(mobj_gm, evalues=ev) summary(impacts(mobj_gm, evalues=ev, R=1000), short=TRUE, zstats=TRUE) impacts(mobj_gmh, listw=listw) impacts(mobj_gmh, tr=trMatc) impacts(mobj_gmh, tr=trMC) impacts(mobj_gmh, evalues=ev) summary(impacts(mobj_gmh, tr=trMatc, R=1000), short=TRUE, zstats=TRUE) #lag durbin = ~formula mobj1_gm <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "lag") mobj1_gmh <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC, model = "lag", het = TRUE) impacts(mobj1_gm, tr=trMatc) impacts(mobj1_gm, listw=listw) impacts(mobj1_gm, KPformula = TRUE) summary(impacts(mobj_gm, evalues=ev, R=200), short=TRUE, zstats=TRUE) summary(impacts(mobj1_gm, tr=trMatc, R=200), short=TRUE, zstats=TRUE) mobj1_gm <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC, model = "lag") summary(impacts(mobj1_gm, evalues=ev, R=200), short=TRUE, zstats=TRUE)
The function calculate the Kelejian and Piras J-test for spatial models. Both models (under the null and under the alternative) can be specified with additional endogenous variables, and additional instruments. The model under the null allows for heteroskedasticity as well as spatial autocorrelation:
with
Note that when R reduces to an identity matrix, the error term, while still heteroskedastic, is not spatially autocorrelated.
On the other hand, when the are all the same (and R is an identity matrix) than the error term is neither heteroskedastic nor autocorrelated.
kpjtest(H0model, H1model, data = list(), listw0 = NULL, listw1 = NULL, endogH0 = NULL, endogH1 = NULL, instrumentsH0 = NULL, instrumentsH1 = NULL, lag.instr = FALSE, model = "lag", het = FALSE, HAC = F, distance = NULL, type = "Epanechnikov", bandwidth = "variable", na.action = na.fail)
kpjtest(H0model, H1model, data = list(), listw0 = NULL, listw1 = NULL, endogH0 = NULL, endogH1 = NULL, instrumentsH0 = NULL, instrumentsH1 = NULL, lag.instr = FALSE, model = "lag", het = FALSE, HAC = F, distance = NULL, type = "Epanechnikov", bandwidth = "variable", na.action = na.fail)
H0model |
Formula object for the specification of the model under the null |
H1model |
Formula object for the specification of the model under the alternative |
data |
an object of class data.frame. An optional data frame containing the variables in the model |
listw0 |
an object of class |
listw1 |
an object of class |
endogH0 |
additional endogenous variables under the null model. Default |
endogH1 |
additional endogenous variables under the alternative model. Default |
instrumentsH0 |
external instruments for the null model. Default |
instrumentsH1 |
external instruments for the alternative model. Default |
lag.instr |
should the external instruments be spatially lagged? |
model |
one of |
het |
default FALSE: if TRUE uses the methods developed for heteroskedasticity |
HAC |
perform the HAC estimator of Kelejian and Prucha, 2007 on the null (and augmented) model. |
distance |
an object of class |
type |
One of |
bandwidth |
"variable" (default) - or numeric when a fixed bandwidth is specified by the user. |
na.action |
a function which indicates what should happen when the data contains missing values. See lm for details |
In order to calculate the J-test, the function follows a few steps:
The alternative model is estimated by S2SLS.
Based on the estimated parameters in the previous step, obtain a prediction based on the alternative models of the dependent vector in the null model. The predictor is based on the right hand side of the model.
Use these predicted values of the dependent variable based on the alternative models into the null model to obtain the augmented model.
Estimate the augmented model by 2SLS using all of the instruments relating to the null model as well as all of the instruments relating to the alternative models.
Test for the statistical significance of the predicted value. If it is not significant, accept the null model. If it is significant, reject the null and conclude that the true model is the alternative models.
The output is an object of class sphet
where the last row of the table of coefficients is the prediction.
When the model is heteroskedastic as well as spatially autocorrelated, an HAC procedure is employed. The default sets the bandwith for each observation to the maximum distance for that observation (i.e. the max of each element of the list of distances).
Six different kernel functions are implemented:
'Epanechnikov'
:
'Triangular'
:
'Bisquare'
:
'Parzen'
: if
and
if
'TH'
(Tukey - Hanning):
'Rectangular'
:
'QS'
(Quadratic Spectral): ).
If the kernel type is not one of the six implemented, the function will terminate with an error message.
The spatial two stage least square estimator is based on the matrix of instruments .
A list object of class sphet
coefficients |
Generalized Spatial two stage least squares coefficient estimates of |
var |
variance-covariance matrix of the estimated coefficients |
s2 |
GS2SLS residuals variance |
residuals |
GS2SLS residuals |
yhat |
difference between GS2SLS residuals and response variable |
call |
the call used to create this object |
model |
the model matrix of data |
method |
|
Gianfranco Piras [email protected]
Kelejian and Piras (2017). Spatial Econometrics. Academic Press. ISBN: 978-0-12-813387-3
Gianfranco Piras (2010). sphet: Spatial Models with Heteroskedastic Innovations in R. Journal of Statistical Software, 35(1), 1-21. https://www.jstatsoft.org/v35/i01/.
Roger Bivand, Gianfranco Piras (2015). Comparing Implementations of Estimation Methods for Spatial Econometrics. Journal of Statistical Software, 63(18), 1-36. https://www.jstatsoft.org/v63/i18/.
library(spdep) library(sphet) data(boston) boslw <- nb2listw(boston.soi) Bos.Knn <- knearneigh(boston.utm, k = 5) bos.nb <- knn2nb(Bos.Knn) boslw2 <- nb2listw(bos.nb) fm <- log(MEDV) ~ CRIM + ZN + INDUS + CHAS fm2 <- log(MEDV) ~ CRIM + ZN + INDUS + RM + AGE test <- kpjtest(fm, fm2, data = boston.c, listw0 = boslw, listw1 = boslw2, model = "lag")
library(spdep) library(sphet) data(boston) boslw <- nb2listw(boston.soi) Bos.Knn <- knearneigh(boston.utm, k = 5) bos.nb <- knn2nb(Bos.Knn) boslw2 <- nb2listw(bos.nb) fm <- log(MEDV) ~ CRIM + ZN + INDUS + CHAS fm2 <- log(MEDV) ~ CRIM + ZN + INDUS + RM + AGE test <- kpjtest(fm, fm2, data = boston.c, listw0 = boslw, listw1 = boslw2, model = "lag")
Interface between Matrix class objects and weights list
listw2dgCMatrix(listw, zero.policy = NULL)
listw2dgCMatrix(listw, zero.policy = NULL)
listw |
a |
zero.policy |
See |
Matrix class object: a sparse Matrix
Gianfranco Piras [email protected]
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) spW <- listw2dgCMatrix(listw)
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) spW <- listw2dgCMatrix(listw)
Method used to print objects of class 'summary.sphet'
and 'sphet'
## S3 method for class 'sphet' print(x, digits = max(3, getOption("digits") - 3),...)
## S3 method for class 'sphet' print(x, digits = max(3, getOption("digits") - 3),...)
x |
an object of class 'sphet' |
digits |
minimal number of significant digits, see |
... |
additional arguments to be passed |
The summary function summary.sphet returns an objects of class 'sphet' organized in a coefficient matrix.
Gianfranco Piras[email protected]
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar") summary(res)
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar") summary(res)
Method used to print objects of class 'summary.sphet'
and 'sphet'
## S3 method for class 'summary.sphet' print(x,digits= max(3, getOption("digits") - 2), width=getOption("width"), obsinfo=FALSE,...)
## S3 method for class 'summary.sphet' print(x,digits= max(3, getOption("digits") - 2), width=getOption("width"), obsinfo=FALSE,...)
x |
an object of class 'sphet' |
digits |
minimal number of significant digits, see |
width |
controls the maximum number of columns on a line used in printing |
obsinfo |
for objects of class |
... |
additional arguments to be passed |
The summary function summary.sphet returns an objects of class 'sphet' organized in a coefficient matrix.
Gianfranco Piras[email protected]
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar") summary(res)
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar") summary(res)
The function reads "GWT" files (i.e. generated using distance. It will read also other more general formats (as for example .txt files).
read.gwt2dist(file, region.id = NULL, skip = 1)
read.gwt2dist(file, region.id = NULL, skip = 1)
file |
name of file to be read |
region.id |
variable that defines the ordering of the observations |
skip |
number of lines to skip |
The first line of a 'GWT'
file generally contains some information
(e.g. the name of the shape file, the number of observations),
in which case, skip
should be equal to 1.
When the file
has a 'GWT'
extension,
the number of observations is generally retrived from the first line.
Alternatively, it is fixed to the length
of the unique region.id
variable.
An object of class distance
Gianfranco Piras [email protected]
## Not run: library(spdep) data(columbus) dist <- read.gwt2dist(file = system.file('extdata/knn10columbus.GWT', package = "sphet"), region.id = columbus$POLYID) ## End(Not run)
## Not run: library(spdep) data(columbus) dist <- read.gwt2dist(file = system.file('extdata/knn10columbus.GWT', package = "sphet"), region.id = columbus$POLYID) ## End(Not run)
Multi step GM/IV estimation of a linear Cliff and Ord -type of model of the form:
with
The model allows for spatial lag in the dependent variable and disturbances. The innovations in the disturbance process are assumed heteroskedastic of an unknown form.
spreg(formula, data = list(), listw, listw2 = NULL, endog = NULL, instruments = NULL, lag.instr = FALSE, initial.value = 0.2, q = 2, model = c("sarar", "lag", "error", "ivhac", "ols"), het = FALSE, verbose = FALSE, na.action = na.fail, HAC = FALSE, distance = NULL, type = c("Epanechnikov","Triangular", "Bisquare", "Parzen", "QS", "TH","Rectangular"), bandwidth = "variable" , step1.c = FALSE, control = list(), Durbin = FALSE)
spreg(formula, data = list(), listw, listw2 = NULL, endog = NULL, instruments = NULL, lag.instr = FALSE, initial.value = 0.2, q = 2, model = c("sarar", "lag", "error", "ivhac", "ols"), het = FALSE, verbose = FALSE, na.action = na.fail, HAC = FALSE, distance = NULL, type = c("Epanechnikov","Triangular", "Bisquare", "Parzen", "QS", "TH","Rectangular"), bandwidth = "variable" , step1.c = FALSE, control = list(), Durbin = FALSE)
formula |
a description of the model to be fit |
data |
an object of class data.frame. An optional data frame containing the variables in the model |
listw |
an object of class |
listw2 |
an object of class |
endog |
additional endogenous variables. Default |
instruments |
external instruments. Default |
lag.instr |
should the external instruments be spatially lagged? |
initial.value |
The initial value for |
q |
default equal 2, if 1 the only WX is considered in matrix of instruments |
model |
one of |
het |
default FALSE: if TRUE uses the methods developed for heteroskedasticity |
verbose |
print optimization details |
na.action |
a function which indicates what should happen when the data contains missing values. See lm for details. |
HAC |
perform the HAC estimator of Kelejian and Prucha, 2007. |
distance |
an object of class |
type |
One of |
bandwidth |
"variable" (default) - or numeric when a fixed bandwidth is specified by the user. |
step1.c |
Should step 1.c from Arraiz et al. 2012 be performed? |
control |
A list of control arguments. See nlminb |
Durbin |
Should (some of) the regressors be lagged? Default FALSE. If not |
The procedure consists of two steps alternating GM and IV estimators. Each step consists of sub-steps.
In step one is estimated by 2SLS. The 2SLS residuals are first employed
to obtain an consistent GM estimator of
.
In step two, the spatial Cochrane-Orcutt transformed model is estimated by 2SLS. This corresponds to a GS2SLS procedure.
The GS2SLS residuals are used to obtain a consistent and efficient GM estimator for .
The initial value for the optimization in step 1b is taken to be initial.value
.
The initial value for the optimization of step 2b is the optimal parameter of step 1b.
Internally, the object of class listw
is transformed into a Matrix
using the function listw2dgCMatrix.
For the HAC estimator (Kelejian and Prucha, 2007), there are four possibilities:
A model with only Wy
A model with Wy and additional endogenous
Additional endogenous variables but no Wy
No additional endogenous variables (A linear model with HAC estimation)
In the first two cases, the model
should be "ivhac"
,
in the last two cases, the model
should be "ols"
.
Furthermore, the default sets the bandwidth for each observation to the maximum distance for that observation (i.e. the max of each element of the list of distances).
Six different kernel functions are implemented:
'Epanechnikov'
:
'Triangular'
:
'Bisquare'
:
'Parzen'
: if
and
if
'TH'
(Tukey - Hanning):
'Rectangular'
:
'QS'
(Quadratic Spectral): ).
If the kernel type is not one of the six implemented, the function will terminate with an error message.
A list object of class sphet
coefficients |
Generalized Spatial two stage least squares coefficient estimates of |
var |
variance-covariance matrix of the estimated coefficients |
s2 |
GS2SLS residuals variance |
residuals |
GS2SLS residuals |
yhat |
difference between GS2SLS residuals and response variable |
call |
the call used to create this object |
model |
the model matrix of data |
method |
|
Gianfranco Piras [email protected]
Arraiz, I. and Drukker, M.D. and Kelejian, H.H. and Prucha, I.R. (2010) A spatial Cliff-Ord-type Model with Heteroskedastic Innovations: Small and Large Sample Results, Journal of Regional Sciences, 50, pages 592–614.
Drukker, D.M. and Egger, P. and Prucha, I.R. (2013) On Two-step Estimation of a Spatial Auto regressive Model with Autoregressive Disturbances and Endogenous Regressors, Econometric Review, 32, pages 686–733.
Kelejian, H.H. and Prucha, I.R. (2010) Specification and Estimation of Spatial Autoregressive Models with Autoregressive and Heteroskedastic Disturbances, Journal of Econometrics, 157, pages 53–67.
Kelejian, H.H. and Prucha, I.R. (1999) A Generalized Moments Estimator for the Autoregressive Parameter in a Spatial Model, International Economic Review, 40, pages 509–533.
Kelejian, H.H. and Prucha, I.R. (1998) A Generalized Spatial Two Stage Least Square Procedure for Estimating a Spatial Autoregressive Model with Autoregressive Disturbances, Journal of Real Estate Finance and Economics, 17, pages 99–121.
Gianfranco Piras (2010). sphet: Spatial Models with Heteroskedastic Innovations in R. Journal of Statistical Software, 35(1), 1-21. doi:10.18637/jss.v035.i01.
Roger Bivand, Gianfranco Piras (2015). Comparing Implementations of Estimation Methods for Spatial Econometrics. Journal of Statistical Software, 63(18), 1-36. doi:10.18637/jss.v063.i18.
Gianfranco Piras, Paolo Postiglione (2022). A deeper look at impacts in spatial Durbin model with sphet. Geographical Analysis, 54(3), 664-684.
data(columbus, package="spdep") listw <- spdep::nb2listw(col.gal.nb) res <- spreg(CRIME ~ HOVAL + INC, data = columbus , listw = listw, het = TRUE, verbose = FALSE, model = "sarar") summary(res) Effects <- impacts(res, listw = listw, R = 1000) library(spdep) data("baltimore", package = "spData") mat <- nb2listw(knn2nb(knearneigh(cbind(baltimore$X,baltimore$Y), 3))) knb10 <- knn2nb(knearneigh(cbind(baltimore$X,baltimore$Y), k=5)) dists <- nbdists(knb10, cbind(baltimore$X,baltimore$Y)) k10lw <- nb2listw(knb10, glist=dists, style="B") class(k10lw) <- "distance" # OLS MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, verbose = FALSE, model = "ols", Durbin = TRUE, HAC = TRUE, distance = k10lw, type = "Triangular") summary(res) # note model = "ols" but with endogenous variables res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, verbose = FALSE, model = "ols", Durbin = TRUE, HAC = TRUE, distance = k10lw, type = "Triangular", endog = ~SQFT, instruments = ~GAR + PATIO) summary(res) # ERROR MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = FALSE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = TRUE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE -1, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) # LAG MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = FALSE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = TRUE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE -1, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) # IVHAC MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "ivhac", Durbin = FALSE, HAC = TRUE, distance = k10lw, type = "Triangular", endog = ~SQFT, instruments = ~GAR + PATIO) # SARAR MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = FALSE, q = 1) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = TRUE, q = 1) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH, q =2) summary(res) res <- spreg(PRICE ~ NROOM + AGE + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE -1, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH) summary(res) summary(res)
data(columbus, package="spdep") listw <- spdep::nb2listw(col.gal.nb) res <- spreg(CRIME ~ HOVAL + INC, data = columbus , listw = listw, het = TRUE, verbose = FALSE, model = "sarar") summary(res) Effects <- impacts(res, listw = listw, R = 1000) library(spdep) data("baltimore", package = "spData") mat <- nb2listw(knn2nb(knearneigh(cbind(baltimore$X,baltimore$Y), 3))) knb10 <- knn2nb(knearneigh(cbind(baltimore$X,baltimore$Y), k=5)) dists <- nbdists(knb10, cbind(baltimore$X,baltimore$Y)) k10lw <- nb2listw(knb10, glist=dists, style="B") class(k10lw) <- "distance" # OLS MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, verbose = FALSE, model = "ols", Durbin = TRUE, HAC = TRUE, distance = k10lw, type = "Triangular") summary(res) # note model = "ols" but with endogenous variables res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, verbose = FALSE, model = "ols", Durbin = TRUE, HAC = TRUE, distance = k10lw, type = "Triangular", endog = ~SQFT, instruments = ~GAR + PATIO) summary(res) # ERROR MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = FALSE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = TRUE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE -1, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "error", Durbin = ~SQFT + NBATH) summary(res) # LAG MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = FALSE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = TRUE) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE -1, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "lag", Durbin = ~SQFT + NBATH) summary(res) # IVHAC MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "ivhac", Durbin = FALSE, HAC = TRUE, distance = k10lw, type = "Triangular", endog = ~SQFT, instruments = ~GAR + PATIO) # SARAR MODEL res <- spreg(PRICE ~ NROOM +AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = FALSE, q = 1) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = TRUE, q = 1) summary(res) res <- spreg(PRICE ~ NROOM + AGE + SQFT + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH, q =2) summary(res) res <- spreg(PRICE ~ NROOM + AGE + NBATH, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH) summary(res) res <- spreg(PRICE ~ NROOM + AGE -1, data = baltimore, listw = mat, het = TRUE, verbose = FALSE, model = "sarar", Durbin = ~SQFT + NBATH) summary(res) summary(res)
Non-parametric heteroskedasticity and autocorrelation consistent (HAC) estimator of the variance-covariance (VC) for a vector of sample moments within a spatial context. The disturbance vector is generated as follows:
where is a non-stochastic matrix.
stslshac(formula, data = list(), listw, na.action = na.fail, zero.policy = NULL, HAC = TRUE, distance = NULL, type = "Epanechnikov", bandwidth = "variable", W2X = TRUE)
stslshac(formula, data = list(), listw, na.action = na.fail, zero.policy = NULL, HAC = TRUE, distance = NULL, type = "Epanechnikov", bandwidth = "variable", W2X = TRUE)
formula |
a description of the model to be fit |
data |
an object of class data.frame. An optional data frame containing the variables in the model. |
listw |
an object of class |
na.action |
a function which indicates what should happen when the data contains missing values. See lm for details. |
zero.policy |
See |
HAC |
if FALSE traditional standard errors are provided. |
distance |
an object of class |
type |
One of |
bandwidth |
"variable" (default) - or numeric when a fixed bandwidth is specified by the user. |
W2X |
default TRUE. if FALSE only WX are used as instruments in the spatial two stage least squares. |
The default sets the bandwidth for each observation to the maximum distance for that observation (i.e. the max of each element of the list of distances).
Six different kernel functions are implemented:
'Epanechnikov'
:
'Rectangular'
:
'Triangular'
:
'Bisquare'
:
'Parzen'
: if
and
if
'TH'
(Tukey - Hanning):
'QS'
(Quadratic Spectral): ).
If the kernel type is not one of the six implemented, the function will terminate with an error message.
The spatial two stage least square estimator is based on the matrix of instruments .
A list object of class sphet
coefficients |
Spatial two stage least squares coefficient estimates |
vcmat |
variance-covariance matrix of the estimated coefficients |
s2 |
S2sls residulas variance |
residuals |
S2sls residuals |
yhat |
difference between residuals and response variable |
call |
the call used to create this object |
model |
the model matrix of data |
type |
the kernel employed in the estimation |
bandwidth |
the type of bandwidth |
method |
|
Gianfranco Piras [email protected]
Kelejian, H.H. and Prucha, I.R. (2007) HAC estimation in a spatial framework, Journal of Econometrics, 140, pages 131–154.
Kelejian, H.H. and Prucha, I.R. (1999) A Generalized Moments Estimator for the Autoregressive Parameter in a Spatial Model, International Economic Review, 40, pages 509–533.
Kelejian, H.H. and Prucha, I.R. (1998) A Generalized Spatial Two Stage Least Square Procedure for Estimating a Spatial Autoregressive Model with Autoregressive Disturbances, Journal of Real Estate Finance and Economics, 17, pages 99–121.
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) data(coldis) res <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw, distance = coldis, type = 'Triangular') summary(res)
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) data(coldis) res <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw, distance = coldis, type = 'Triangular') summary(res)
Method used to print objects of class 'summary.sphet'
and 'sphet'
## S3 method for class 'sphet' summary(object, width=getOption("width"), digits=getOption("digits"),obsinfo=FALSE,...)
## S3 method for class 'sphet' summary(object, width=getOption("width"), digits=getOption("digits"),obsinfo=FALSE,...)
object |
an object of class 'sphet' |
width |
controls the maximum number of columns on a line used in printing |
digits |
minimal number of significant digits, see |
obsinfo |
for objects of class |
... |
additional arguments to be passed |
The summary function summary.sphet returns an objects of class 'sphet' organized in a coefficient matrix.
Gianfranco Piras[email protected]
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar") summary(res)
library(spdep) data(columbus) listw <- nb2listw(col.gal.nb) res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar") summary(res)
arg
and arg1
are the objective functions of the non-linear
estimators in the GMM procedure.
Omega
and Omegabis
generates the variance-covariance matrices
of the Original and Transformed models (See Arraiz et al., 2007 for details.)
Ggfastfast
calculates G and g.
All other functions perform calculations to estimates various objects defined in Appendix B2 and B3 in Arraiz et al., 2007.
Gianfranco Piras [email protected]