plot_impactsnopar {pspatreg}R Documentation

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

Description

Plot direct, indirect and total impacts functions for non-parametric covariates included in a semiparametric spatial or spatio-temporal SAR model. This model must include a spatial lag of the dependent variable (SAR) to have indirect effects different from 0, otherwise, total and direct function effects are the same. The effect functions can be smoothed to overcome the instabilities created by the premultiplication of matrix (I - \rho W)^{-1}

Usage

plot_impactsnopar(
  impactsnopar,
  data,
  smooth = TRUE,
  span = c(0.1, 0.1, 0.2),
  dynamic = FALSE,
  nt = NULL
)

Arguments

impactsnopar

object returned from impactsnopar function.

data

dataframe with the data.

smooth

logical value to choose smoothing of the effects function prior to plot. Default TRUE.

span

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

dynamic

Logical value to set a dynamic model. Dynamic models include a temporal lag of the dependent variable in the right-hand side of the equation. Default = 'FALSE'.

nt

Number of temporal periods. It is needed for dynamic models.

Value

plot of the direct, indirect and total impacts function for each non-parametric covariate included in the object returned from impactsnopar.

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 = FALSE)
plot_impactsnopar(nparimpacts, data = ames_sf1, smooth = TRUE)
###### Examples using a panel data of rate of
###### unemployment for 103 Italian provinces in period 1996-2014.
library(pspatreg)
data(unemp_it)
## Wsp_it is a matrix. Create a neighboord list 
lwsp_it <- spdep::mat2listw(Wsp_it)
## short sample for spatial pure case (2d)
########  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, alpha = 0.05,
                            listw = lwsp_it, 
                            viewplot = TRUE)  
##### This returns the same result but using plot_impactsnopar()
imp_nparvar <- impactsnopar(gamsar, listw = lwsp_it, alpha = 0.05,
                            viewplot = FALSE)
plot_impactsnopar(imp_nparvar, data = unemp_it, 
                   smooth = TRUE)
                    


[Package pspatreg version 1.1.2 Index]