impactsnopar {pspatreg}R Documentation

Compute direct, indirect and total impacts functions for continous non-parametric covariates in semiparametric spatial regression models.

Description

Compute and plot direct, indirect and total impact functions for non-parametric covariates included in a semiparametric spatial or spatio-temporal econometric model. This model must include a spatial lag of the dependent variable and/or non-parametric covariates, to have indirect impacts different from 0, otherwise, total and direct function impacts are the same. The models can be of type ps-sar, ps-sarar, ps-sdm, ps-sdem or ps-slx.

Usage

impactsnopar(
  obj,
  variables = NULL,
  listw = NULL,
  alpha = 0.05,
  viewplot = TRUE,
  smooth = TRUE,
  span = c(0.1, 0.1, 0.2)
)

Arguments

obj

pspatfit object fitted using pspatfit function.

variables

vector including names of non-parametric covariates to obtain impulse functions. If NULL all the nonparametric covariates are included. Default = NULL.

listw

should be a spatial neighbours list object created for example by nb2listw from spdep package. It can also be a spatial weighting matrix of order (NxN) instead of a listw neighbours list object.

alpha

numerical value for the significance level of the pointwise confidence interval of the impact functions. Default 0.05.

viewplot

Default 'TRUE' to plot impacts. If FALSE use plot_impactsnopar to plot impacts

smooth

Default 'TRUE'. Whether to smooth fitted impacts or not.

span

span for the kernel of the smoothing (see loess for details). Default c(0.1, 0.1, 0.2)

Details

To compute the impact functions of the non-parametric covariates, first it is used the function fit_terms to get fitted values of the terms and standard errors of the fitted values for each non-parametric covariate. Then, the intervals for the fitted term are computed as

fitted_values plus/minus quantile*standard errors

where quantile is the corresponding quantile of the N(0,1) distribution. The total impact function is computed as:

solve(kronecker((I_N - rho*W_N), It), fitted_values)

where (I_N - rho*W_N) matrix is the spatial lag matrix and It is an identity matrix of order equals to the temporal periods (t). Obviously, t = 1 for pure spatial econometric models. The upper and lower bounds of the total impact functions are computed using the previous formula but using fitted_values plus/minus quantile*standard errors instead of fitted_values.

The direct impacts function is computed using the formula:

diag(solve(kronecker((I_N - rho*W_N), It), diag(fitted_values))

that is, the fitted values are put in the main diagonal of a diagonal matrix and, afterwards, the spatial lag is applied over this diagonal matrix. Finally, the main diagonal of the resulting matrix is considered the direct impact function. The upper and lower bounds of the direct impact functions are computed using the previous formula but using fitted_values plus/minus quantile*standard errors instead of fitted_values.

Eventually, the indirect impacts function are computed as the difference between both total and direct impact functions, that is:

indirect impact function = total impacts function - direct impacts function

In this way we can get both, the indirect impact functions and upper and lower bounds of the indirect impact functions.

It is important to remark that, usually, the indirect impact functions are very wiggly. To get ride of this problem, the argument smooth (default = 'TRUE') allows to smooth the impacts function using the loess function available in stats. This is very convenient when the indirect impacts function is plotted.

Value

A list including

impnopar_tot Matrix including total impacts in columns.
impnopar_dir Matrix including direct impacts in columns.
impnopar_ind Matrix including indirect impacts in columns.
impnopar_tot_up Matrix including upper bounds of total impacts in columns.
impnopar_dir_up Matrix including upper bounds of direct impacts in columns.
impnopar_ind_up Matrix including upper bounds of indirect impacts in columns.
impnopar_tot_low Matrix including lower bounds of total impacts in columns.
impnopar_dir_low Matrix including lower bounds of direct impacts in columns.
impnopar_ind_low Matrix including lower bounds of indirect impacts in columns.

Author(s)

Roman Minguez roman.minguez@uclm.es
Roberto Basile roberto.basile@univaq.it
Maria Durban mdurban@est-econ.uc3m.es
Gonzalo Espana-Heredia gehllanza@gmail.com

References

See Also

Examples

################################################
# Examples using spatial data of Ames Houses.
###############################################
# Getting and preparing the data
library(pspatreg)
library(spdep)
library(sf)
ames <- AmesHousing::make_ames() # Raw Ames Housing Data
ames_sf <- st_as_sf(ames, coords = c("Longitude", "Latitude"))
ames_sf$Longitude <- ames$Longitude
ames_sf$Latitude <- ames$Latitude
ames_sf$lnSale_Price <- log(ames_sf$Sale_Price)
ames_sf$lnLot_Area <- log(ames_sf$Lot_Area)
ames_sf$lnTotal_Bsmt_SF <- log(ames_sf$Total_Bsmt_SF+1)
ames_sf$lnGr_Liv_Area <- log(ames_sf$Gr_Liv_Area)
ames_sf1 <- ames_sf[(duplicated(ames_sf$Longitude) == FALSE), ]
form1 <- lnSale_Price ~ Fireplaces + Garage_Cars +
          pspl(lnLot_Area, nknots = 20) + 
          pspl(lnTotal_Bsmt_SF, nknots = 20) +
          pspl(lnGr_Liv_Area, nknots = 20)    


########### Constructing the spatial weights matrix
coord_sf1 <- cbind(ames_sf1$Longitude, ames_sf1$Latitude)
k5nb <- knn2nb(knearneigh(coord_sf1, k = 5, 
                          longlat = TRUE, use_kd_tree = FALSE), sym = TRUE)
lw_ames <- nb2listw(k5nb, style = "W", 
                  zero.policy = FALSE)
gamsar <- pspatfit(form1, data = ames_sf1, 
                   type = "sar", listw = lw_ames,
                   method = "Chebyshev")
summary(gamsar)
nparimpacts <- impactsnopar(gamsar, listw = lw_ames, viewplot = TRUE)
################################################
 ######## Examples using a panel data of rate of
 ######## unemployment for 103 Italian provinces in period 1996-2014.
library(pspatreg)
data(unemp_it, package = "pspatreg") 
## Wsp_it is a matrix. Create a neighboord list 
lwsp_it <- spdep::mat2listw(Wsp_it)
######  No Spatial Trend: PSAR including a spatial 
######  lag of the dependent variable
form1 <- unrate ~ partrate + agri + cons + empgrowth +
                 pspl(serv, nknots = 15)
gamsar <- pspatfit(form1, 
                    data = unemp_it, 
                    type = "sar", 
                    listw = lwsp_it)
 summary(gamsar)
 ###### Non-Parametric Total, Direct and Indirect impacts
 imp_nparvar <- impactsnopar(gamsar, 
                             listw = lwsp_it, 
                             viewplot = TRUE)
                              


[Package pspatreg version 1.1.2 Index]