kpjtest: Kelejian and Piras J-test

View source: R/kpjtest.R

kpjtestR Documentation

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=\lambda W y + X \beta + u

u=Re

with

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 \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) = 1-z^2

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

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

  • 'Parzen': K(z) = 1-6z^2+6 |z|^3 if z \leq 0.5 and K(z) = 2(1-|z|)^3 if 0.5 < z \leq 1

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

  • 'Rectangular': K(z) = 1

  • 'QS' (Quadratic Spectral): 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,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 gpiras@mac.com

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

gpiras/sphet documentation built on Feb. 21, 2024, 3:39 p.m.