plot_sp2d | R Documentation |
Make plots and maps of the spatial trends
in 2d of the objects fitted with pspatfit
function.
plot_sp2d( object, data, coordinates = NULL, npoints = 300, cexpoints = 0.25, addcontour = TRUE, addpoints = TRUE, addmain = TRUE, addint = TRUE )
object |
object returned from |
data |
either sf or dataframe with the data. |
coordinates |
coordinates matrix if |
npoints |
number of points to use in the interpolation. |
cexpoints |
size of the points. Default = 0.25 |
addcontour |
Logical value to add contour lines. |
addpoints |
Logical value to add spatial points to the graphics. |
addmain |
Add f1_main and f2_main plots in psanova case. |
addint |
Add f12_int in psanova case. |
plots and maps of the spatial trends
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 |
Lee, D. and Durban, M. (2011). P-Spline ANOVA Type Interaction Models for Spatio-Temporal Smoothing. Statistical Modelling, (11), 49-69. <doi:10.1177/1471082X1001100104>
Eilers, P. and Marx, B. (2021). Practical Smoothing. The Joys of P-Splines. Cambridge University Press.
Fahrmeir, L.; Kneib, T.; Lang, S.; and Marx, B. (2021). Regression. Models, Methods and Applications (2nd Ed.). Springer.
Wood, S.N. (2017). Generalized Additive Models.
An Introduction with R
(second edition). CRC Press, Boca Raton.
library(pspatreg, package = "pspatreg") ######## EXAMPLE 2D WITH AMES DATA ######## getting and preparing the data library(spdep) 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) ########### Constructing the spatial weights matrix ames_sf1 <- ames_sf[(duplicated(ames_sf$Longitude) == FALSE), ] coord_sf1 <- cbind(ames_sf1$Longitude, ames_sf1$Latitude) ID <- row.names(as(ames_sf1, "sf")) col_tri_nb <- tri2nb(coord_sf1) soi_nb <- graph2nb(soi.graph(col_tri_nb, coord_sf1), row.names = ID) lw_ames <- nb2listw(soi_nb, style = "W", zero.policy = FALSE) ######## formula of the model IN AMES form2d <- lnSale_Price ~ Fireplaces + Garage_Cars + pspl(lnLot_Area, nknots = 20) + pspl(lnTotal_Bsmt_SF, nknots = 20) + pspl(lnGr_Liv_Area, nknots = 20) + pspt(Longitude, Latitude, nknots = c(10, 10), psanova = FALSE) ######## fit the model sp2dsar <- pspatfit(form2d, data = ames_sf1, listw = lw_ames, method = "Chebyshev", type = "sar") summary(sp2dsar) ####### plot spatial trend for spatial point coordinate plot_sp2d(sp2dsar, data = ames_sf1) ###### MODEL WITH ANOVA DESCOMPOSITION form2d_psanova <- lnSale_Price ~ Fireplaces + Garage_Cars + pspl(lnLot_Area, nknots = 20) + pspl(lnTotal_Bsmt_SF, nknots = 20) + pspl(lnGr_Liv_Area, nknots = 20) + pspt(Longitude, Latitude, nknots = c(10, 10), psanova = TRUE) sp2danovasar <- pspatfit(form2d_psanova, data = ames_sf1, listw = lw_ames, method = "Chebyshev", type = "sar") summary(sp2danovasar) ###### PLOT ANOVA DESCOMPOSITION MODEL plot_sp2d(sp2danovasar, data = ames_sf1, addmain = TRUE, addint = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.