library(pspatreg)
library(spatialreg)
library(spdep)
library(sf)
library(plm)
library(ggplot2)
library(dplyr)
library(splm)
This section focuses on the semiparametric P-Spline model for spatial panel data. The model may include a smooth spatio-temporal trend, a spatial lag of dependent and independent variables, a time lag of the dependent variable and of its spatial lag, and a time series autoregressive noise. Specifically, we consider a spatio-temporal ANOVA model, disaggregating the trend into spatial and temporal main effects, as well as second- and third-order interactions between them.
The empirical illustration is based on data on regional unemployment in Italy. This example shows that this model represents a valid alternative to parametric methods aimed at disentangling strong and weak cross-sectional dependence when both spatial and temporal heterogeneity are smoothly distributed (see Mı́nguez, Basile, and Durbán 2020). The section is organized as follows:
Description of dataset, spatial weights matrix and model specifications;
Estimation results of linear spatial models and comparison with the results obtained with splm;
Estimation results of semiparametric spatial models.
The package provides the panel data unemp_it
(an object of class data.frame
) and the spatial weights matrix Wsp_it
(a 103 by 103 square matrix). The raw data - a balanced panel with 103 Italian provinces observed for each year between 1996 and 2019 - can be transformed in a spatial polygonal dataset of class sf
after having joined the data.frame
object with the shapefile of Italian provinces:
data(unemp_it, package = "pspatreg")
<- st_as_sf(dplyr::left_join(unemp_it, map_it, by = c("prov" = "COD_PRO"))) unemp_it_sf
The matrix Wsp_it
is a standardized inverse distance W matrix. Using spdep
we transform it in a list of neighbors object:
<- spdep::mat2listw(Wsp_it)
lwsp_it summary(lwsp_it)
## Characteristics of weights list object:
## Neighbour list object:
## Number of regions: 103
## Number of nonzero links: 434
## Percentage nonzero weights: 4.090866
## Average number of links: 4.213592
## Link number distribution:
##
## 1 2 3 4 5 6 7 8 9
## 7 20 15 16 17 11 10 6 1
## 7 least connected regions:
## 32 75 78 80 81 90 92 with 1 link
## 1 most connected region:
## 15 with 9 links
##
## Weights style: M
## Weights constants summary:
## n nn S0 S1 S2
## M 103 10609 103 74.35526 431.5459
Using these data, we first estimate fully parametric spatial linear autoregressive panel models using the function pspatfit()
included in the package pspatreg (in the default based on the REML estimator) and compare them with the results obtained using the functions provided by the package splm (based on the ML estimator).
pspatfit()
We consider here a fixed effects specification, including both fixed spatial and time effects:
\[y_{it}=\rho \sum_{j=1}^N w_{ij,N} y_{jt} + \sum_{k=1}^K \beta_k x_{k,it}+ \alpha_i+\theta_t+\epsilon_{it}\]
\[\epsilon_{it} \sim i.i.d.(0,\sigma^2_\epsilon)\]
<- unrate ~ empgrowth + partrate + agri + cons + serv
formlin
<- pspatfit(formula = formlin,
Linear_WITHIN_sar_REML data = unemp_it,
listw = lwsp_it,
demean = TRUE,
eff_demean = "twoways",
type = "sar",
index = c("prov", "year"))
summary(Linear_WITHIN_sar_REML)
##
## Call
## pspatfit(formula = formlin, data = unemp_it, listw = lwsp_it,
## type = "sar", demean = TRUE, eff_demean = "twoways", index = c("prov",
## "year"))
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## empgrowth -0.129538 0.014080 -9.2004 < 2.2e-16 ***
## partrate 0.391656 0.023297 16.8112 < 2.2e-16 ***
## agri -0.036743 0.027245 -1.3486 0.1775934
## cons -0.166868 0.044475 -3.7519 0.0001795 ***
## serv 0.012198 0.020581 0.5927 0.5534403
## rho 0.265799 0.018848 14.1023 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Goodness-of-Fit
##
## EDF Total: 6
## Sigma: 1.86934
## AIC: 5396.52
## BIC: 5431.4
<- spml(formlin,
Linear_WITHIN_sar_ML data = unemp_it,
index=c("prov","year"),
listw = lwsp_it,
model="within",
effect = "twoways",
spatial.error="none",
lag=TRUE,
Hess = FALSE)
round(data.frame(Linear_WITHIN_sar_REML = c(Linear_WITHIN_sar_REML$rho,
$bfixed),
Linear_WITHIN_sar_REMLLinear_WITHIN_sar_ML = c(Linear_WITHIN_sar_ML$coefficients[1],
$coefficients[-1])),3) Linear_WITHIN_sar_ML
## Linear_WITHIN_sar_REML Linear_WITHIN_sar_ML
## rho 0.266 0.266
## fixed_empgrowth -0.130 -0.130
## fixed_partrate 0.392 0.392
## fixed_agri -0.037 -0.037
## fixed_cons -0.167 -0.167
## fixed_serv 0.012 0.012
Clearly, both methods give exactly the same results, at least at the third digit level.
Extract coefficients:
coef(Linear_WITHIN_sar_REML)
## rho empgrowth partrate agri cons serv
## 0.2657991 -0.1295384 0.3916562 -0.0367427 -0.1668684 0.0121982
Extract fitted values and residuals:
<- fitted(Linear_WITHIN_sar_REML)
fits <- residuals(Linear_WITHIN_sar_REML) resids
Extract log-likelihood and restricted log-likelihhod:
logLik(Linear_WITHIN_sar_REML)
## 'log Lik.' -2692.26 (df=6)
logLik(Linear_WITHIN_sar_REML, REML = TRUE)
## 'log Lik.' -2711.11 (df=6)
Extract the covariance matrix of estimated coefficients. Argument bayesian
allows to get frequentist (default) or bayesian covariances:
vcov(Linear_WITHIN_sar_REML)
## empgrowth partrate agri cons serv
## empgrowth 1.982376e-04 -8.094238e-05 -3.045614e-06 0.0000302811 -6.851324e-06
## partrate -8.094238e-05 5.427641e-04 -7.222182e-05 -0.0001647323 -7.878910e-05
## agri -3.045614e-06 -7.222182e-05 7.423076e-04 0.0001888545 2.737076e-04
## cons 3.028110e-05 -1.647323e-04 1.888545e-04 0.0019780673 2.429180e-04
## serv -6.851324e-06 -7.878910e-05 2.737076e-04 0.0002429180 4.235754e-04
vcov(Linear_WITHIN_sar_REML, bayesian = TRUE)
## empgrowth partrate agri cons serv
## empgrowth 1.982376e-04 -8.094238e-05 -3.045614e-06 0.0000302811 -6.851324e-06
## partrate -8.094238e-05 5.427641e-04 -7.222182e-05 -0.0001647323 -7.878910e-05
## agri -3.045614e-06 -7.222182e-05 7.423076e-04 0.0001888545 2.737076e-04
## cons 3.028110e-05 -1.647323e-04 1.888545e-04 0.0019780673 2.429180e-04
## serv -6.851324e-06 -7.878910e-05 2.737076e-04 0.0002429180 4.235754e-04
A print method to get printed coefficients, standard errors and p-values of parametric terms:
print(Linear_WITHIN_sar_REML)
## Estimate Std. Error t value Pr(>|t|)
## empgrowth -0.1295 0.0141 -9.2004 0.0000
## partrate 0.3917 0.0233 16.8112 0.0000
## agri -0.0367 0.0272 -1.3486 0.1776
## cons -0.1669 0.0445 -3.7519 0.0002
## serv 0.0122 0.0206 0.5927 0.5534
## rho 0.2658 0.0188 14.1023 0.0000
summary(Linear_WITHIN_sar_REML)
##
## Call
## pspatfit(formula = formlin, data = unemp_it, listw = lwsp_it,
## type = "sar", demean = TRUE, eff_demean = "twoways", index = c("prov",
## "year"))
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## empgrowth -0.129538 0.014080 -9.2004 < 2.2e-16 ***
## partrate 0.391656 0.023297 16.8112 < 2.2e-16 ***
## agri -0.036743 0.027245 -1.3486 0.1775934
## cons -0.166868 0.044475 -3.7519 0.0001795 ***
## serv 0.012198 0.020581 0.5927 0.5534403
## rho 0.265799 0.018848 14.1023 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Goodness-of-Fit
##
## EDF Total: 6
## Sigma: 1.86934
## AIC: 5396.52
## BIC: 5431.4
summary(Linear_WITHIN_sar_ML)
## Spatial panel fixed effects lag model
##
##
## Call:
## spml(formula = formlin, data = unemp_it, index = c("prov", "year"),
## listw = lwsp_it, model = "within", effect = "twoways", lag = TRUE,
## spatial.error = "none", Hess = FALSE)
##
## Residuals:
## Min. 1st Qu. Median 3rd Qu. Max.
## -8.045700 -1.068404 -0.035768 1.014227 7.816307
##
## Spatial autoregressive coefficient:
## Estimate Std. Error t-value Pr(>|t|)
## lambda 0.266004 0.020636 12.89 < 2.2e-16 ***
##
## Coefficients:
## Estimate Std. Error t-value Pr(>|t|)
## empgrowth -0.129530 0.014078 -9.2009 < 2.2e-16 ***
## partrate 0.391597 0.023464 16.6894 < 2.2e-16 ***
## agri -0.036771 0.027219 -1.3510 0.1767102
## cons -0.166896 0.044420 -3.7572 0.0001718 ***
## serv 0.012191 0.020559 0.5930 0.5532105
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Computing average direct, indirect and total marginal impacts:
<- impactspar(Linear_WITHIN_sar_REML, listw = lwsp_it)
imp_parvar_sar summary(imp_parvar_sar)
##
## Total Parametric Impacts (sar)
## Estimate Std. Error t value Pr(>|t|)
## empgrowth -0.175398 0.019256 -9.108768 0.0000
## partrate 0.534911 0.033781 15.834469 0.0000
## agri -0.049592 0.036674 -1.352219 0.1763
## cons -0.227932 0.060940 -3.740248 0.0002
## serv 0.016441 0.028461 0.577658 0.5635
##
## Direct Parametric Impacts (sar)
## Estimate Std. Error t value Pr(>|t|)
## empgrowth -0.131836 0.013971 -9.436574 0.0000
## partrate 0.402083 0.023203 17.328881 0.0000
## agri -0.037268 0.027545 -1.352955 0.1761
## cons -0.171306 0.045408 -3.772598 0.0002
## serv 0.012359 0.021388 0.577847 0.5634
##
## Indirect Parametric Impacts (sar)
## Estimate Std. Error t value Pr(>|t|)
## empgrowth -0.0435624 0.0062628 -6.9557209 0.0000
## partrate 0.1328285 0.0145549 9.1260224 0.0000
## agri -0.0123240 0.0092063 -1.3386478 0.1807
## cons -0.0566258 0.0162126 -3.4926938 0.0005
## serv 0.0040819 0.0071000 0.5749133 0.5653
pspatfit()
:\[y_{it}= \sum_{k=1}^K \beta_k x_{k,it}+\alpha_i+\theta_t+ \epsilon_{it}\]
\[\epsilon_{it}=\theta \sum_{j=1}^N w_{ij,N}\epsilon_{it}+u_{it}\]
\[u_{it} \sim i.i.d.(0,\sigma^2_u)\]
<- pspatfit(formlin,
Linear_WITHIN_sem_REML data = unemp_it,
demean = TRUE,
eff_demean = "twoways",
listw = lwsp_it,
index = c("prov", "year"),
type = "sem")
<- spml(formlin,
Linear_WITHIN_sem_ML data = unemp_it,
index=c("prov","year"),
listw = lwsp_it,
model="within",
effect = "twoways",
spatial.error="b",
lag=FALSE,
Hess = FALSE)
round(data.frame(Linear_WITHIN_sem_REML = c(Linear_WITHIN_sem_REML$delta,
$bfixed),
Linear_WITHIN_sem_REMLLinear_WITHIN_sem_ML = c(Linear_WITHIN_sem_ML$spat.coef,
$coefficients[-1])),3) Linear_WITHIN_sem_ML
## Linear_WITHIN_sem_REML Linear_WITHIN_sem_ML
## delta 0.283 0.283
## fixed_empgrowth -0.134 -0.134
## fixed_partrate 0.399 0.399
## fixed_agri -0.033 -0.033
## fixed_cons -0.188 -0.188
## fixed_serv 0.031 0.031
Now, we estimate an additive semiparametric model with three parametric linear terms (for partrate
, agri
, and cons
) and two nonparametric smooth terms (for serv
and empgrowth
), but without including any control for spatial and temporal autocorrelation and for the spatio-temporal heterogeneity: \[y_{it}= \sum_{k=1}^K \beta_k z_{k,it} + \sum_{\delta=1}^{\Delta} g_\delta(x_{\delta_{it}}) + \epsilon_{it}\]
\[\epsilon_{it} \sim i.i.d.(0,\sigma^2_\epsilon)\]
<- unrate ~ partrate + agri + cons +
formgam pspl(serv, nknots = 15) +
pspl(empgrowth, nknots = 20)
<- pspatfit(formgam, data = unemp_it)
gam summary(gam)
##
## Call
## pspatfit(formula = formgam, data = unemp_it)
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 27.146067 1.351459 20.0865 < 2.2e-16 ***
## partrate -0.376093 0.018224 -20.6377 < 2.2e-16 ***
## agri 0.346388 0.020066 17.2621 < 2.2e-16 ***
## cons -0.183072 0.055367 -3.3065 0.0009582 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Non-Parametric Terms
## EDF
## pspl(serv, nknots = 15) 6.1545
## pspl(empgrowth, nknots = 20) 5.0393
##
## Goodness-of-Fit
##
## EDF Total: 15.1938
## Sigma: 4.07275
## AIC: 9468.61
## BIC: 9556.93
The same model, but with a spatial autoregressive term (SAR): \[y_{it}= \rho \sum_{j=1}^N w_{ij,N} y_{jt} +\sum_{k=1}^K \beta_k z_{k,it} + \sum_{\delta=1}^{\Delta} g_\delta(x_{\delta_{it}}) + \epsilon_{it}\]
\[\epsilon_{it} \sim i.i.d.(0,\sigma^2_\epsilon)\]
<- pspatfit(formgam, data = unemp_it, listw = lwsp_it, method = "eigen", type = "sar")
gamsar summary(gamsar)
##
## Call
## pspatfit(formula = formgam, data = unemp_it, listw = lwsp_it,
## type = "sar", method = "eigen")
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 10.654476 0.942909 11.2996 < 2.2e-16 ***
## partrate -0.161267 0.011928 -13.5200 < 2.2e-16 ***
## agri 0.090099 0.013063 6.8970 6.731e-12 ***
## cons -0.091416 0.036007 -2.5388 0.01118 *
## rho 0.659201 0.011253 58.5783 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Non-Parametric Terms
## EDF
## pspl(serv, nknots = 15) 8.2438
## pspl(empgrowth, nknots = 20) 6.6508
##
## Goodness-of-Fit
##
## EDF Total: 19.8946
## Sigma: 3.55622
## AIC: 7789.23
## BIC: 7904.87
and a spatial error term: \[y_{it}= \sum_{k=1}^K \beta_k z_{k,it} + \sum_{\delta=1}^{\Delta} g_\delta(x_{\delta_{it}}) + \epsilon_{it}\]
\[\epsilon_{it} = \delta \sum_{j=1}^N w_{ij,N}\epsilon_{it}+u_{it}\]
\[u_{it} \sim i.i.d.(0,\sigma^2_u)\]
<- pspatfit(formgam, data = unemp_it, listw = lwsp_it, method = "eigen", type = "sem") gamsem
## Error in solve(H) :
## Lapack dgecon(): system computationally singular, reciprocal condition number = 3.03277e-30
## Error in solve(H) :
## Lapack dgecon(): system computationally singular, reciprocal condition number = 2.28852e-30
## Error in solve(H) :
## Lapack dgecon(): system computationally singular, reciprocal condition number = 2.02096e-30
## Error in solve(H) :
## Lapack dgecon(): system computationally singular, reciprocal condition number = 1.98488e-30
summary(gamsem)
##
## Call
## pspatfit(formula = formgam, data = unemp_it, listw = lwsp_it,
## type = "sem", method = "eigen")
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 19.170184 1.160976 16.5121 < 2e-16 ***
## partrate -0.214748 0.021033 -10.2098 < 2e-16 ***
## agri 0.019002 0.015024 1.2647 0.20609
## cons -0.080432 0.039158 -2.0541 0.04008 *
## delta 0.751669 0.010955 68.6127 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Non-Parametric Terms
## EDF
## pspl(serv, nknots = 15) 8.8955
## pspl(empgrowth, nknots = 20) 8.0356
##
## Goodness-of-Fit
##
## EDF Total: 21.9311
## Sigma: 4.87876
## AIC: 8106.45
## BIC: 8233.93
We can control for spatio-temporal heterogeneity by including a PS-ANOVA spatial trend in 3d. The interaction terms (f12
,f1t
,f2t
and f12t
) with nested basis. Remark: nest_sp1
, nest_sp2
and nest_time
must be divisors of nknots
.
\[y_{it}= \sum_{k=1}^K \beta_k z_{k,it} + \sum_{\delta=1}^{\Delta} g_\delta(x_{\delta_{it}}) + f_1(s_{1i})+f_2(s_{2i})+f_{\tau}(\tau_t)+ \\ f_{1,2}(s_{1i},s_{2i})+f_{1,\tau}(s_{1i},\tau_t)+f_{2,\tau}+(s_{2i},\tau_t)+f_{1,2,\tau}(s_{1i},s_{2i},\tau_t)+\epsilon_{it}\]
\[\epsilon_{it} \sim i.i.d.(0,\sigma^2_\epsilon)\]
<- unrate ~ partrate + agri + cons +
form3d_psanova 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))
<- pspatfit(form3d_psanova, data = unemp_it,
sp3danova listw = lwsp_it, method = "Chebyshev")
summary(sp3danova)
##
## Call
## pspatfit(formula = form3d_psanova, data = unemp_it, listw = lwsp_it,
## method = "Chebyshev")
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## Intercept 3.488736 3.169725 1.1006 0.2712
## partrate 0.150451 0.021169 7.1070 1.585e-12 ***
## agri -0.015291 0.017985 -0.8502 0.3953
## cons -0.050682 0.039092 -1.2965 0.1949
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Non-Parametric Terms
## EDF
## pspl(serv, nknots = 15) 16.563
## pspl(empgrowth, nknots = 20) 16.629
##
## Non-Parametric Spatio-Temporal Trend
## EDF
## f1 10.960
## f2 9.771
## ft 7.763
## f12 45.013
## f1t 4.262
## f2t 23.343
## f12t 76.807
##
## Goodness-of-Fit
##
## EDF Total: 222.112
## Sigma: 1.54052
## AIC: 6166.55
## BIC: 7457.64
A semiparametric model with a PS-ANOVA spatial trend in 3d with the exclusion of some ANOVA components
<- unrate ~ partrate + agri + cons +
form3d_psanova_restr 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),
f1t = FALSE, f2t = FALSE)
<- pspatfit(form3d_psanova_restr, data = unemp_it,
sp3danova_restr listw = lwsp_it, method = "Chebyshev")
summary(sp3danova_restr)
##
## Call
## pspatfit(formula = form3d_psanova_restr, data = unemp_it, listw = lwsp_it,
## method = "Chebyshev")
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## Intercept 4.588218 3.204267 1.4319 0.1523
## partrate 0.150194 0.021166 7.0959 1.717e-12 ***
## agri -0.021500 0.017925 -1.1994 0.2305
## cons -0.033021 0.039301 -0.8402 0.4009
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Non-Parametric Terms
## EDF
## pspl(serv, nknots = 15) 16.715
## pspl(empgrowth, nknots = 20) 18.436
##
## Non-Parametric Spatio-Temporal Trend
## EDF
## f1 10.915
## f2 9.700
## ft 7.737
## f12 45.072
## f1t 0.000
## f2t 0.000
## f12t 113.228
##
## Goodness-of-Fit
##
## EDF Total: 230.802
## Sigma: 1.53811
## AIC: 6255.02
## BIC: 7596.62
Now we add a spatial lag (sar) and temporal correlation in the noise of PSANOVA 3d model.
\[y_{it}= \rho \sum_{j=1}^N w_{ij,N} y_{jt}+\sum_{k=1}^K \beta_k z_{k,it} + \sum_{\delta=1}^{\Delta} g_\delta(x_{\delta_{it}}) + f_1(s_{1i})+f_2(s_{2i})+f_{\tau}(\tau_t)+ \\ f_{1,2}(s_{1i},s_{2i})+f_{1,\tau}(s_{1i},\tau_t)+f_{2,\tau}+(s_{2i},\tau_t)+f_{1,2,\tau}(s_{1i},s_{2i},\tau_t)+\epsilon_{it}\]
\[\epsilon_{it} \sim i.i.d.(0,\sigma^2_\epsilon)\]
<- pspatfit(form3d_psanova_restr, data = unemp_it,
sp3danovasarar1 listw = lwsp_it, method = "Chebyshev",
type = "sar", cor = "ar1")
summary(sp3danovasarar1)
##
## Call
## pspatfit(formula = form3d_psanova_restr, data = unemp_it, listw = lwsp_it,
## type = "sar", method = "Chebyshev", cor = "ar1")
##
## Parametric Terms
## Estimate Std. Error t value Pr(>|t|)
## Intercept 4.606443 3.147781 1.4634 0.14350
## partrate 0.149115 0.020740 7.1896 8.785e-13 ***
## agri -0.027534 0.020373 -1.3515 0.17667
## cons -0.022196 0.041580 -0.5338 0.59353
## rho 0.050358 0.021801 2.3099 0.02098 *
## phi 0.322279 0.013919 23.1544 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Non-Parametric Terms
## EDF
## pspl(serv, nknots = 15) 16.430
## pspl(empgrowth, nknots = 20) 17.891
##
## Non-Parametric Spatio-Temporal Trend
## EDF
## f1 10.434
## f2 9.736
## ft 7.842
## f12 42.134
## f1t 0.000
## f2t 0.000
## f12t 89.716
##
## Goodness-of-Fit
##
## EDF Total: 204.183
## Sigma: 1.59451
## AIC: 5741.58
## BIC: 6928.45
Examples of LR test:
anova(gam, gamsar, lrtest = TRUE)
## logLik rlogLik edf AIC BIC LRtest p.val
## gam -4719.1 -4728.3 15.194 9468.6 9575.3
## gamsar -3874.7 -3886.1 19.895 7789.2 7927.4 1684.5 0
anova(gam, gamsar, lrtest = TRUE)
## logLik rlogLik edf AIC BIC LRtest p.val
## gam -4719.1 -4728.3 15.194 9468.6 9575.3
## gamsar -3874.7 -3886.1 19.895 7789.2 7927.4 1684.5 0
anova(gamsar, gamsem, lrtest = FALSE)
## logLik rlogLik edf AIC BIC
## gamsar -3874.7 -3886.1 19.895 7789.2 7927.4
## gamsem -4031.3 -4041.6 21.931 8106.4 8254.4
anova(gam, sp3danova_restr, lrtest = TRUE)
## logLik rlogLik edf AIC BIC LRtest p.val
## gam -4719.1 -4728.3 15.194 9468.6 9575.3
## sp3danova_restr -2896.7 -2893.3 230.802 6255.0 7567.2 3670 0
anova(sp3danova_restr, sp3danovasarar1, lrtest = FALSE)
## logLik rlogLik edf AIC BIC
## sp3danova_restr -2896.7 -2893.3 230.80 6255.0 7567.2
## sp3danovasarar1 -2666.6 -2664.7 204.18 5741.6 6907.0
Plot of non-parametric terms
<- c("serv", "empgrowth")
list_varnopar <- fit_terms(sp3danova_restr, list_varnopar)
terms_nopar names(terms_nopar)
## [1] "fitted_terms" "se_fitted_terms" "fitted_terms_fixed" "se_fitted_terms_fixed" "fitted_terms_random"
## [6] "se_fitted_terms_random"
plot_terms(terms_nopar, unemp_it, conflevel = 0.95)
<- impactspar(sp3danovasarar1, listw = lwsp_it)
imp_nparvar summary(imp_nparvar)
##
## Total Parametric Impacts (sar)
## Estimate Std. Error t value Pr(>|t|)
## partrate 0.156051 0.022094 7.063070 0.0000
## agri -0.029270 0.021990 -1.331067 0.1832
## cons -0.023393 0.044522 -0.525428 0.5993
##
## Direct Parametric Impacts (sar)
## Estimate Std. Error t value Pr(>|t|)
## partrate 0.148392 0.020604 7.202227 0.0000
## agri -0.027823 0.020868 -1.333310 0.1824
## cons -0.022296 0.042391 -0.525960 0.5989
##
## Indirect Parametric Impacts (sar)
## Estimate Std. Error t value Pr(>|t|)
## partrate 0.0076592 0.0037641 2.0348026 0.0419
## agri -0.0014473 0.0013902 -1.0410385 0.2979
## cons -0.0010975 0.0024082 -0.4557437 0.6486
<- impactsnopar(sp3danovasarar1, listw = lwsp_it, viewplot = TRUE) imp_nparvar
Plot of spatial trends in 1996, 2005 and 2019
plot_sp3d(sp3danovasarar1, data = unemp_it_sf,
time_var = "year", time_index = c(1996, 2005, 2019),
addmain = FALSE, addint = FALSE)
Plot of spatio-temporal trend, main effects and interaction effect for a year:
plot_sp3d(sp3danovasarar1, data = unemp_it_sf,
time_var = "year", time_index = c(2019),
addmain = TRUE, addint = TRUE)
Plot of temporal trend for each province:
plot_sptime(sp3danovasarar1, data = unemp_it,
time_var = "year", reg_var = "prov")
Plots of fitted and residuals of the last model:
<- fitted(sp3danovasarar1)
fits <- residuals(sp3danovasarar1)
resids plot(fits, unemp_it$unrate)
plot(fits, resids)