Package 'sphet'

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

Help Index


Estimation of spatial models with heteroskedastic innovations

Description

A set of functions to estimate spatial models with heteroskedastic innovations

Details

Package: sphet
Type: Package
Version: 1.12
Date: 2021-06-17
License: GPL
LazyLoad: yes

Author(s)

Gianfranco Piras [email protected]

References

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.


Generate circular weigthing matrices

Description

The function generates k-ahead and k-behind weighting matrices as in Kelejian and Prucha (1999)

Usage

circular(nrow, ncol, ab)

Arguments

nrow

Number of rows

ncol

Number of columns

ab

Ahead - behind

Details

Generate circular weigthing matrices

Value

An object of class nb

Author(s)

Gianfranco Piras [email protected]

Examples

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

Description

Object of class distance for Columbus dataset 10-nearest neighbors matrix for columbus dataset

Format

A list of neighbors and distances for the columbus neighborhoods

Author(s)

Gianfranco Piras [email protected]


Distance measures available in distance

Description

Reads points coordinates and generates objects of class distance.matrix

Usage

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)

Arguments

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 ("NN","distance","inverse"). Nearest neighbors, distance or inverse distance

measure

one of ("euclidean","gcircle","chebyshev","braycur","canberra").The distance measure to be employed in the calculations (See Details)

nn

the number of nearest neighbors

cutoff

If type is distance or inverse. Assumes values 1, 2 or 3. When 1, the cutoff is set to the first quantile of the distribution of distances. When 2 to the median, and when 3 to the third quantile. Only observations with distance less than cutoff distance are neighbors.

miles

If TRUE (default), distances are in miles, otherwise in Km. (See spDists wcich returns km, and are converted if required)

R

deprecated, spDists uses an approximation to the WGS84 spheroid

shape.name

The name of the shape file. See Details

region.id.name

The name of the region.id variable. See Details

firstline

If TRUE, a first line is added to the output file. See Details

file.name

If output, the name of the output file. See Details

Details

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': (xiyi)2\sqrt{\sum{(x_i - y_i)^2}}

  • 'chebyshev': max(xiyi)max(|x_i - y_i|)

  • 'braycur': xiyixi+yi\frac{\sum{|x_i - y_i|}}{\sum{|x_i + y_i|}}

  • 'canberra': xiyixi+yi\frac{\sum{|x_i - y_i|}}{\sum{|x_i| + |y_i|}}

  • 'gcircle': see spDists, which uses an approximation to the WGS84 spheroid.

Value

A matrix of three columns: from, to, and distance

Author(s)

Gianfranco Piras [email protected]

Examples

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)

GM estimation of a Cliff-Ord type model with Heteroskedastic Innovations

Description

Multi step GM/IV estimation of a linear Cliff and Ord -type of model of the form:

y=λWy+Xβ+uy=\lambda W y + X \beta + u

u=ρWu+eu=\rho W u + e

with

e N(0,σi2)e ~ N(0,\sigma^2_i)

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.

Usage

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)

Arguments

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 listw created for example by nb2listw

na.action

a function which indicates what should happen when the data contains missing values. See lm for details.

zero.policy

See lagsarlm for details

initial.value

The initial value for ρ\rho. It can be either numeric (default is 0.2) or set to 'SAR', in which case the optimization will start from the estimated coefficient of a regression of the 2SLS residuals over their spatial lag (i.e. a spatial AR model)

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

TRUE. If FALSE, an appoximated inverse is calculated. See Details.

sarar

TRUE. If FALSE, a spatial error model is estimated.

Details

The procedure consists of two steps alternating GM and IV estimators. Each step consists of sub-steps. In step one δ=[β,λ]\delta = [\beta',\lambda]' is estimated by 2SLS. The 2SLS residuals are first employed to obtain an initial (consistent but not efficient) GM estimator of ρ\rho 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 ρ\rho.

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 IρWI-\rho W'. When inverse is FALSE, the inverse is calculated using the approximation I+ρW+ρ2W2+...+ρnWnI +\rho W' + \rho^2 W'^2 + ...+ \rho^n W'^n. 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 ρiWi\rho^i W^i is greater than a fixed ϵ\epsilon (eps). By default eps is set to 1e-5.

Value

A list object of class sphet

coefficients

Generalized Spatial two stage least squares coefficient estimates of δ\delta and GM estimator for ρ\rho.

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

'gs2slshac'

W

Wald test for both ρ\rho and λ\lambda are zero

Author(s)

Gianfranco Piras [email protected]

References

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.

See Also

stslshac

Examples

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

Description

Generate impacts for objects of class error_sphet created in sphet

Usage

## S3 method for class 'error_sphet'
impacts(
  obj,
  ...,
  tr = NULL,
  R = NULL,
  listw = NULL,
  evalues = NULL,
  tol = 1e-06,
  empirical = FALSE,
  Q = NULL
)

Arguments

obj

A spreg spatial regression object created by spreg with model ="lag"

...

Arguments passed through to methods in the coda package

tr

A vector of traces of powers of the spatial weights matrix created using trW, for approximate impact measures; if not given, listw must be given for exact measures (for small to moderate spatial weights matrices); the traces must be for the same spatial weights as were used in fitting the spatial regression

R

If given, simulations are used to compute distributions for the impact measures, returned as mcmc objects

listw

a listw object

evalues

vector of eigenvalues of spatial weights matrix for impacts calculations

tol

Argument passed to mvrnorm: tolerance (relative to largest variance) for numerical lack of positive-definiteness in the coefficient covariance matrix

empirical

Argument passed to mvrnorm (default FALSE): if true, the coefficients and their covariance matrix specify the empirical not population mean and covariance matrix

Q

default NULL, else an integer number of cumulative power series impacts to calculate if tr is given

Value

Estimate of the Average Total, Average Direct, and Average Indirect Effects

Examples

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

Description

Generate impacts for spreg lag and sarar models

Generate impacts for objects of class sarar_gmm created in sphet

Usage

## 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
)

Arguments

obj

A spreg spatial regression object created by spreg with model ="sarar"

...

Arguments passed through to methods in the coda package

tr

A vector of traces of powers of the spatial weights matrix created using trW, for approximate impact measures; if not given, listw must be given for exact measures (for small to moderate spatial weights matrices); the traces must be for the same spatial weights as were used in fitting the spatial regression

R

If given, simulations are used to compute distributions for the impact measures, returned as mcmc objects

listw

a listw object

evalues

vector of eigenvalues of spatial weights matrix for impacts calculations

tol

Argument passed to mvrnorm: tolerance (relative to largest variance) for numerical lack of positive-definiteness in the coefficient covariance matrix

empirical

Argument passed to mvrnorm (default FALSE): if true, the coefficients and their covariance matrix specify the empirical not population mean and covariance matrix

Q

default NULL, else an integer number of cumulative power series impacts to calculate if tr is given

KPformula

default FALSE, else inference of the impacts based on Kelejian and Piras (2020)

prt

prints the KP summary of the VC matrix

Value

Estimate of the Average Total, Average Direct, and Average Indirect Effects

Estimate of the Average Total, Average Direct, and Average Indirect Effects

References

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.

Examples

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

Description

Generate impacts for objects of class ols_sphet created in sphet

Usage

## S3 method for class 'ols_sphet'
impacts(
  obj,
  ...,
  tr = NULL,
  R = NULL,
  listw = NULL,
  evalues = NULL,
  tol = 1e-06,
  empirical = FALSE,
  Q = NULL
)

Arguments

obj

A spreg spatial regression object created by spreg with model ="lag"

...

Arguments passed through to methods in the coda package

tr

A vector of traces of powers of the spatial weights matrix created using trW, for approximate impact measures; if not given, listw must be given for exact measures (for small to moderate spatial weights matrices); the traces must be for the same spatial weights as were used in fitting the spatial regression

R

If given, simulations are used to compute distributions for the impact measures, returned as mcmc objects

listw

a listw object

evalues

vector of eigenvalues of spatial weights matrix for impacts calculations

tol

Argument passed to mvrnorm: tolerance (relative to largest variance) for numerical lack of positive-definiteness in the coefficient covariance matrix

empirical

Argument passed to mvrnorm (default FALSE): if true, the coefficients and their covariance matrix specify the empirical not population mean and covariance matrix

Q

default NULL, else an integer number of cumulative power series impacts to calculate if tr is given

Value

Estimate of the Average Total, Average Direct, and Average Indirect Effects

Examples

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

Description

Generate impacts for objects of class lag_gmm created in sphet

Usage

## 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
)

Arguments

obj

A spreg spatial regression object created by spreg with model ="lag"

...

Arguments passed through to methods in the coda package

tr

A vector of traces of powers of the spatial weights matrix created using trW, for approximate impact measures; if not given, listw must be given for exact measures (for small to moderate spatial weights matrices); the traces must be for the same spatial weights as were used in fitting the spatial regression

R

If given, simulations are used to compute distributions for the impact measures, returned as mcmc objects

listw

a listw object

evalues

vector of eigenvalues of spatial weights matrix for impacts calculations

tol

Argument passed to mvrnorm: tolerance (relative to largest variance) for numerical lack of positive-definiteness in the coefficient covariance matrix

empirical

Argument passed to mvrnorm (default FALSE): if true, the coefficients and their covariance matrix specify the empirical not population mean and covariance matrix

Q

default NULL, else an integer number of cumulative power series impacts to calculate if tr is given

KPformula

default FALSE, else inference of the impacts based on Kelejian and Piras (2020)

prt

prints the KP summary of the VC matrix

Value

Estimate of the Average Total, Average Direct, and Average Indirect Effects

References

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.

Examples

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)

Kelejian and Piras J-test

Description

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:

y=λWy+Xβ+uy=\lambda W y + X \beta + u

u=Reu=Re

with

e N(0,σi2)e ~ N(0,\sigma^2_i)

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 σi2\sigma^2_i are all the same (and R is an identity matrix) than the error term is neither heteroskedastic nor autocorrelated.

Usage

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)

Arguments

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 listw, matrix, or Matrix. The spatial weighting matrix under the null model

listw1

an object of class listw, matrix, or Matrix. The spatial weighting matrix under the alternative model

endogH0

additional endogenous variables under the null model. Default NULL. If not NULL should be specified as a formula with no dependent variable (endog = ~ x1 + x2). Note the ~ before the expression

endogH1

additional endogenous variables under the alternative model. Default NULL. If not NULL should be specified as a formula with no dependent variable (endog = ~ x1 + x2). Note the ~ before the expression

instrumentsH0

external instruments for the null model. Default NULL. If not NULL should be specified as a formula with no dependent variable (instruments = ~ x1 + x2). Note the ~ before the expression

instrumentsH1

external instruments for the alternative model. Default NULL. If not NULL should be specified as a formula with no dependent variable (instruments = ~ x1 + x2). Note the ~ before the expression

lag.instr

should the external instruments be spatially lagged?

model

one of lag, or sarar. The current version of the function only implements the lag model.

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 distance created for example by read.gwt2dist The object contains the specification of the distance measure to be employed in the estimation of the VC matrix. See Details.

type

One of c("Epanechnikov","Triangular","Bisquare","Parzen", "QS","TH","Rectangular"). The type of Kernel to be used. See Details.

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

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': K(z)=1z2K(z) = 1-z^2

  • 'Triangular': K(z)=1zK(z) = 1-z

  • 'Bisquare': K(z)=(1z2)2K(z) = (1-z^2)^2

  • 'Parzen': K(z)=16z2+6z3K(z) = 1-6z^2+6 |z|^3 if z0.5z \leq 0.5 and K(z)=2(1z)3K(z) = 2(1-|z|)^3 if 0.5<z10.5 < z \leq 1

  • 'TH' (Tukey - Hanning): K(z)=1+cos(πz)2K(z) = \frac{1+ \cos(\pi z)}{2}

  • 'Rectangular': K(z)=1K(z) = 1

  • 'QS' (Quadratic Spectral): K(z)=2512π2z2(sin(6πz)/5)6πz/5cos(6πz)/5)K(z) = \frac{25}{12\pi^2z^2} (\frac{\sin(6\pi z)/5)}{6\pi z/5} - \cos(6\pi z)/5)).

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 H=[X,WX,W2X2]H=[X,WX,W^2X^2].

Value

A list object of class sphet

coefficients

Generalized Spatial two stage least squares coefficient estimates of δ\delta and GM estimator for ρ\rho.

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

's2slshac'

Author(s)

Gianfranco Piras [email protected]

References

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/.

Examples

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

Description

Interface between Matrix class objects and weights list

Usage

listw2dgCMatrix(listw, zero.policy = NULL)

Arguments

listw

a listw object created for example by nb2listw

zero.policy

See lagsarlm for details

Value

Matrix class object: a sparse Matrix

Author(s)

Gianfranco Piras [email protected]

Examples

library(spdep)
data(columbus)
listw <- nb2listw(col.gal.nb)
spW <- listw2dgCMatrix(listw)

print method for class sphet

Description

Method used to print objects of class 'summary.sphet' and 'sphet'

Usage

## S3 method for class 'sphet'
print(x, digits = max(3, getOption("digits") - 3),...)

Arguments

x

an object of class 'sphet'

digits

minimal number of significant digits, see print.default

...

additional arguments to be passed

Details

The summary function summary.sphet returns an objects of class 'sphet' organized in a coefficient matrix.

Author(s)

Gianfranco Piras[email protected]

See Also

gstslshet, stslshac

Examples

library(spdep)
data(columbus)
listw <- nb2listw(col.gal.nb)
res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar")
summary(res)

print method for class sphet

Description

Method used to print objects of class 'summary.sphet' and 'sphet'

Usage

## S3 method for class 'summary.sphet'
print(x,digits= max(3, getOption("digits") - 2), 
width=getOption("width"), obsinfo=FALSE,...)

Arguments

x

an object of class 'sphet'

digits

minimal number of significant digits, see print.default

width

controls the maximum number of columns on a line used in printing

obsinfo

for objects of class distance: if TRUE prints observation-wise information

...

additional arguments to be passed

Details

The summary function summary.sphet returns an objects of class 'sphet' organized in a coefficient matrix.

Author(s)

Gianfranco Piras[email protected]

See Also

gstslshet, stslshac

Examples

library(spdep)
data(columbus)
listw <- nb2listw(col.gal.nb)
res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar")
summary(res)

Read distance ojbects

Description

The function reads "GWT" files (i.e. generated using distance. It will read also other more general formats (as for example .txt files).

Usage

read.gwt2dist(file, region.id = NULL, skip = 1)

Arguments

file

name of file to be read

region.id

variable that defines the ordering of the observations

skip

number of lines to skip

Details

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.

Value

An object of class distance

Author(s)

Gianfranco Piras [email protected]

Examples

## Not run: 
library(spdep)
data(columbus)
dist <- read.gwt2dist(file = system.file('extdata/knn10columbus.GWT',
package = "sphet"), region.id = columbus$POLYID)

## End(Not run)

GM estimation of a Cliff-Ord type model with Heteroskedastic Innovations

Description

Multi step GM/IV estimation of a linear Cliff and Ord -type of model of the form:

y=λWy+Xβ+uy=\lambda W y + X \beta + u

u=ρWu+eu=\rho W u + e

with

e N(0,σi2)e ~ N(0,\sigma^2_i)

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.

Usage

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)

Arguments

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 listw, matrix, or Matrix

listw2

an object of class listw, matrix, or Matrix specified only when sarar is true

endog

additional endogenous variables. Default NULL. If not NULL should be specified as a formula with no dependent variable (endog = ~ x1 + x2). Note the ~ before the expression.

instruments

external instruments. Default NULL. If not NULL should be specified as a formula with no dependent variable (instruments = ~ x1 + x2). Note the ~ before the expression.

lag.instr

should the external instruments be spatially lagged?

initial.value

The initial value for ρ\rho. It can be either numeric (default is 0.2) or set to 'SAR', in which case the optimization will start from the estimated coefficient of a regression of the 2SLS residuals over their spatial lag (i.e. a spatial AR model)

q

default equal 2, if 1 the only WX is considered in matrix of instruments

model

one of lag, error, sarar, ivhac, or ols. If HAC is TRUE, model should be one of ivhac, or ols.

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 distance created for example by read.gwt2dist The object contains the specification of the distance measure to be employed in the estimation of the VC matrix. See Details.

type

One of c("Epanechnikov","Triangular","Bisquare","Parzen", "QS","TH","Rectangular"). The type of Kernel to be used. default = "Epanechnikov" See Details.

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 FALSE should be specified as a formula with no dependent variable (Durbin = ~ x1 + x2) or set to TRUE. See details.

Details

The procedure consists of two steps alternating GM and IV estimators. Each step consists of sub-steps. In step one δ=[β,λ]\delta = [\beta',\lambda]' is estimated by 2SLS. The 2SLS residuals are first employed to obtain an consistent GM estimator of ρ\rho.

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 ρ\rho.

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': K(z)=1z2K(z) = 1-z^2

  • 'Triangular': K(z)=1zK(z) = 1-z

  • 'Bisquare': K(z)=(1z2)2K(z) = (1-z^2)^2

  • 'Parzen': K(z)=16z2+6z3K(z) = 1-6z^2+6 |z|^3 if z0.5z \leq 0.5 and K(z)=2(1z)3K(z) = 2(1-|z|)^3 if 0.5<z10.5 < z \leq 1

  • 'TH' (Tukey - Hanning): K(z)=1+cos(πz)2K(z) = \frac{1+ \cos(\pi z)}{2}

  • 'Rectangular': K(z)=1K(z) = 1

  • 'QS' (Quadratic Spectral): K(z)=2512π2z2(sin(6πz)/5)6πz/5cos(6πz)/5)K(z) = \frac{25}{12\pi^2z^2} (\frac{\sin(6\pi z)/5)}{6\pi z/5} - \cos(6\pi z)/5)).

If the kernel type is not one of the six implemented, the function will terminate with an error message.

Value

A list object of class sphet

coefficients

Generalized Spatial two stage least squares coefficient estimates of δ\delta and GM estimator for ρ\rho.

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

'gs2slshac'

Author(s)

Gianfranco Piras [email protected]

References

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.

See Also

stslshac

Examples

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)

Spatial two stages least square with HAC standard errors

Description

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:

u=Rϵu = R \epsilon

where RR is a non-stochastic matrix.

Usage

stslshac(formula, data = list(), listw,
             na.action = na.fail, zero.policy = NULL, HAC = TRUE,
             distance = NULL, type = "Epanechnikov", 
             bandwidth = "variable", W2X = TRUE)

Arguments

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 listw created for example by nb2listw

na.action

a function which indicates what should happen when the data contains missing values. See lm for details.

zero.policy

See lagsarlm for details

HAC

if FALSE traditional standard errors are provided.

distance

an object of class distance created for example by read.gwt2dist The object contains the specification of the distance measure to be employed in the estimation of the VC matrix. See Details.

type

One of c("Epanechnikov","Triangular","Bisquare","Parzen", "QS","TH"). The type of Kernel to be used. See Details.

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.

Details

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': K(z)=1z2K(z) = 1-z^2

  • 'Rectangular': K(z)=1K(z) = 1

  • 'Triangular': K(z)=1zK(z) = 1-z

  • 'Bisquare': K(z)=(1z2)2K(z) = (1-z^2)^2

  • 'Parzen': K(z)=16z2+6z3K(z) = 1-6z^2+6 |z|^3 if z0.5z \leq 0.5 and K(z)=2(1z)3K(z) = 2(1-|z|)^3 if 0.5<z10.5 < z \leq 1

  • 'TH' (Tukey - Hanning): K(z)=1+cos(πz)2K(z) = \frac{1+ \cos(\pi z)}{2}

  • 'QS' (Quadratic Spectral): K(z)=2512π2z2(sin(6πz)/5)6πz/5cos(6πz)/5)K(z) = \frac{25}{12\pi^2z^2} (\frac{\sin(6\pi z)/5)}{6\pi z/5} - \cos(6\pi z)/5)).

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 H=[X,WX,W2X2]H=[X,WX,W^2X^2].

Value

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

's2slshac'

Author(s)

Gianfranco Piras [email protected]

References

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.

See Also

gstslshet, distance, distance

Examples

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)

print method for class sphet

Description

Method used to print objects of class 'summary.sphet' and 'sphet'

Usage

## S3 method for class 'sphet'
summary(object, width=getOption("width"), digits=getOption("digits"),obsinfo=FALSE,...)

Arguments

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 print.default

obsinfo

for objects of class distance: if TRUE prints observation-wise information

...

additional arguments to be passed

Details

The summary function summary.sphet returns an objects of class 'sphet' organized in a coefficient matrix.

Author(s)

Gianfranco Piras[email protected]

See Also

gstslshet, stslshac

Examples

library(spdep)
data(columbus)
listw <- nb2listw(col.gal.nb)
res <- spreg(CRIME~HOVAL + INC, data=columbus, listw=listw, model ="sarar")
summary(res)

Functions used by gstslshet.

Description

  • 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.

Author(s)

Gianfranco Piras [email protected]