Learn R Programming

pspatreg (version 1.1.2)

plot_sptime: Plot of time trends for spatio-temporal models in 3d.

Description

Make plots of the temporal trends for each region fitted with pspatfit function.

Usage

plot_sptime(object, data, time_var, reg_var)

Value

time series plots of the temporal trend for each region

Arguments

object

object returned from pspatfit

data

either sf or dataframe with the data.

time_var

name of the temporal variable in data.

reg_var

name of the regional variable in data.

Author

Roman Minguezroman.minguez@uclm.es
Roberto Basileroberto.basile@univaq.it
Maria Durbanmdurban@est-econ.uc3m.es
Gonzalo Espana-Herediagehllanza@gmail.com

References

  • 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. (2013). Regression. Models, Methods and Applications. Springer.

  • Wood, S.N. (2017). Generalized Additive Models. An Introduction with R (second edition). CRC Press, Boca Raton.

Examples

Run this code
library(pspatreg)
data(unemp_it, package = "pspatreg")
lwsp_it <- spdep::mat2listw(Wsp_it)

###### FORMULA OF THE MODEL
form3d_psanova <- unrate ~ partrate + agri + cons +
                  pspl(serv, nknots = 15) + 
                  pspl(empgrowth, nknots = 20) +
                  pspt(long, lat, year, 
                       nknots = c(18, 18, 8),
                       psanova = TRUE, 
                       nest_sp1 = c(1, 2, 3), 
                       nest_sp2 = c(1, 2, 3),
                       nest_time = c(1, 2, 2))

# \donttest{
####### FIT the model
sp3danova <- pspatfit(form3d_psanova, 
                      data = unemp_it, 
                      listw = lwsp_it, 
                      method = "Chebyshev") 

summary(sp3danova)

######## Plot of temporal trend for each province 
plot_sptime(sp3danova, 
            data = unemp_it, 
            time_var = "year", 
            reg_var = "prov")
# }

Run the code above in your browser using DataLab