# NOT RUN {
require(spdep);require(Matrix)
data(boston)
y <- boston.c[, "CMEDV" ]
x <- boston.c[,c("CRIM","ZN","INDUS", "CHAS", "NOX","RM", "AGE",
"DIS" ,"RAD", "TAX", "PTRATIO", "B", "LSTAT")]
xgroup<- boston.c[,"TOWN"]
coords<- boston.c[,c("LON","LAT")]
meig <- meigen(coords=coords)
# meig<- meigen_f(coords=coords) ## for large samples
######## Regression considering residual spatially dependence
res <- resf(y = y, x = x, meig = meig)
res
plot_s(res) ## spatially dependent component (intercept)
######## Compositionally-warped spatial regression (2 SAL transformations)
res2 <- resf(y = y, x = x, meig = meig, tr_num = 2)
res2 ## tr_num and tr_nonneg can be selected by comparing BIC (or AIC)
coef_marginal(res2)## marginal effects of x. The median might be useful as a summary statistic
######## Compositionally-warped spatial regression (2 SAL trans. + Box-Cox trans.)
res3 <- resf(y = y, x = x, meig = meig, tr_num = 2, tr_nonneg=TRUE)
res3 ## tr_num and tr_nonneg can be selected by comparing BIC (or AIC)
coef_marginal(res3)
######## Regression considering residual spatially dependence and NVC
######## (constant coefficients or NVC is selected)
#res4 <- resf(y = y, x = x, meig = meig, nvc = TRUE)
#res4 ## Note: Coefficients on 5,6,and 13-th covariates
## are estimated non-spatially varying (NVC) depending on x
#plot_n(res4,5) ## 1D plot of the 5-th NVC
#plot_n(res4,6) ## 1D plot of the 6-th NVC
#plot_n(res4,13)## 1D plot of the 13-th NVC
#plot_s(res4) ## spatially dependent component (intercept)
#plot_s(res4,5) ## spatial plot of the 5-th NVC
#plot_s(res4,6) ## spatial plot of the 6-th NVC
#plot_s(res4,13)## spatial plot of the 13-th NVC
######## Compositionally-warped spatial regression with NVC (2 SAL trans. + Box-Cox trans.)
######## (constant coefficients or NVC is selected)
#res5 <- resf(y = y, x = x, meig = meig, nvc = TRUE, tr_num = 2, tr_nonneg=TRUE)
######## Regression considering residual spatially dependence and NVC
######## (all the coefficients are NVCs)
#res6 <- resf(y = y, x = x, meig = meig, nvc = TRUE, nvc_sel=FALSE)
######## Regression considering residual spatially dependence and group effects
#res7 <- resf(y = y, x = x, meig = meig, xgroup = xgroup)
######## Regression considering group-level spatially dependence and group effects
#meig_g<- meigen(coords=coords, s_id = xgroup)
#res8 <- resf(y = y, x = x, meig = meig_g, xgroup = xgroup)
# }
Run the code above in your browser using DataLab