fit_terms | R Documentation |
The fit_terms
function compute both:
Non-parametric spatial (2d) or spatio-temporal (3d) trends including the decomposition in main and interaction trends when the model is ANOVA.
Smooth functions f(x_i) for non-parametric covariates in semiparametric models. It also includes standard errors and the decomposition of each non-parametric term in fixed and random parts.
fit_terms(sptsarfit, variables)
sptsarfit |
psar object fitted using |
variables |
vector including names of non-parametric covariates. To fit the terms of non-parametric spatial (2d) or spatio-temporal (3d) trend this argument must be set equal to spttrend. |
A list including:
fitted_terms | Matrix including terms in columns. |
se_fitted_terms | Matrix including standard errors of terms in columns. |
fitted_terms_fixed | Matrix including fixed part of terms in columns. |
se_fitted_terms_fixed | Matrix including standard errors of fixed part of terms in columns. |
fitted_terms_random | Matrix including random part of terms in columns. |
se_fitted_terms_random | Matrix including standard errors of random part of terms in columns. |
This object can be used as an argument of plot_terms
function
to make plots of both non-parametric trends and smooth functions of covariates.
See examples below.
Roman Minguez roman.minguez@uclm.es #'
Lee, D. and Durbán, M. (2011). P-Spline ANOVA Type Interaction Models for Spatio-Temporal Smoothing. Statistical Modelling, (11), 49-69.
Wood, S.N. (2017). Generalized Additive Models.
An Introduction with R
(second edition). CRC Press, Boca Raton.
psar
estimate spatial or spatio-temporal semiparametric PS-SAR
regression models.
plot_terms
plot smooth functions of non-parametric
covariates.
plot_main_spt
plot main non-parametric functions in
ANOVA trends.
################################################ ###################### Examples using a panel data of rate of ###################### unemployment for 103 Italian provinces in period 1996-2014. library(sptpsar) data(unemp_it); Wsp <- Wsp_it ###################### No Spatial Trend: PSAR including a spatial ###################### lag of the dependent variable form1 <- unrate ~ partrate + agri + cons + pspl(serv,nknots=15) + pspl(empgrowth,nknots=20) gamsar <- psar(form1,data=unemp_it,sar=TRUE,Wsp=Wsp_it) summary(gamsar) ###################### Fit non-parametric terms (spatial trend must be name "spttrend") list_varnopar <- c("serv","empgrowth") terms_nopar <- fit_terms(gamsar,list_varnopar) ###################### Plot non-parametric terms plot_terms(terms_nopar,unemp_it) ############################################### Examples of terms corresponding to spatial (2d) or spatio-temporal (3d) trends ############################################### # Spatial (2d) semiparametric ANOVA model without spatial lag # Interaction term f12 with nested basis form3 <- unrate ~ partrate + agri + cons + pspl(serv,nknots=15) + pspl(empgrowth,nknots=20) + pspt(long,lat,nknots=c(20,20),psanova=TRUE, nest_sp1=c(1,2),nest_sp2=c(1,2)) # Spatial trend fixed for period 1996-2014 geospanova <- psar(form3,data=unemp_it) summary(geospanova) ### Plot spatial trend (ANOVA) spttrend <- fit_terms(geospanova,"spttrend") lon <- scale(unemp_it$long); lat <- scale(unemp_it$lat) ### Plot main effects plot_main_spt(spttrend,sp1=lon,sp2=lat,nT=19) #' ############################################### # Spatio-temporal (3d) semiparametric ANOVA model without spatial lag # Interaction terms f12,f1t,f2t and f12t with nested basis # Remark: It is necessary to include ntime as argument # Remark: nest_sp1, nest_sp2 and nest_time must be divisors of nknots form4 <- 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),ntime=19) sptanova <- psar(form4,data=unemp_it, control=list(thr=1e-2,maxit=200,trace=FALSE)) summary(sptanova) ### Plot spatial trend (ANOVA) spttrend <- fit_terms(sptanova,"spttrend") lon <- scale(unemp_it$long); lat <- scale(unemp_it$lat) time <- unemp_it$year ### Plot main effects plot_main_spt(spttrend,sp1=lon,sp2=lat,time=time,nT=19) @export
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.