# NOT RUN {
require(spdep)
data(boston)
y <- boston.c[, "CMEDV"]
x <- boston.c[,c("CRIM", "AGE")]
xconst <- boston.c[,c("ZN","DIS","RAD","NOX", "TAX","RM", "PTRATIO", "B")]
xgroup <- boston.c[,"TOWN"]
coords <- boston.c[,c("LON", "LAT")]
meig <- meigen(coords=coords)
# meig <- meigen_f(coords=coords) ## for large samples
############## SVC modeling1 #################
######## - SVC or constant coefficients on x
######## - Constant coefficients on xconst
res <- resf_vc(y=y,x=x,xconst=xconst,meig=meig )
res
plot_s(res,0) # Spatially varying intercept
plot_s(res,1) # 1st SVC (Not shown because the SVC is estimated constant)
plot_s(res,2) # 2nd SVC
############## Compositionally-warped SVC modeling #################
######## - SVC or constant coefficients on x
######## - Constant coefficients on xconst
######## - 2 SAL transformations on y
#res2 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig, tr_num = 2 )
#res2 # tr_num and tr_nonneg can be selected by comparing BIC (or AIC)
#coef_marginal_vc(res2) # marginal effects of x.
# The median might be useful as a summary statistic
######## - 2 SAL transformations + Box-Cox transformation on y
#res3 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig, tr_num = 2, tr_nonneg=TRUE )
#res3
#coef_marginal_vc(res3)
############## SVC modeling2 #################
######## (SVC on x; Constant coefficients on xconst)
#res4 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig, x_sel = FALSE )
############## SVC modeling3 #################
######## - Group-level SVC or constant coefficients on x
######## - Constant coefficients on xconst
######## - Group effects
#meig_g <- meigen(coords, s_id=xgroup)
#res5 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig_g,xgroup=xgroup)
############## SNVC modeling1 #################
######## - SNVC, SVC, NVC, or constant coefficients on x
######## - Constant coefficients on xconst
#res6 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig, x_nvc =TRUE)
############## Compositionally-warped SNVC modeling #################
######## - SNVC, SVC, NVC, or constant coefficients on x
######## - 2 SAL transformations + Box-Cox transformation on y
#res7 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig, x_nvc =TRUE, tr_num = 2, tr_nonneg=TRUE)
#res7 # tr_num and tr_nonneg can be selected by comparing BIC (or AIC)
############## SNVC modeling2 #################
######## - SNVC, SVC, NVC, or constant coefficients on x
######## - NVC or Constant coefficients on xconst
#res8 <- resf_vc(y=y,x=x,xconst=xconst,meig=meig, x_nvc =TRUE, xconst_nvc=TRUE)
#plot_s(res8,0) # Spatially varying intercept
#plot_s(res8,1) # Spatial plot of 1st SNVC (SVC + NVC)
#plot_s(res8,1,btype="svc")# Spatial plot of SVC in the SNVC on x[,1]
#plot_s(res8,1,btype="nvc")# Spatial plot of NVC in the SNVC on x[,1]
#plot_n(res8,1) # 1D plot of NVC in the SNVC on x[,1]
#plot_s(res8,6,xtype="xconst")# Spatial plot of NVC in the SNVC on xconst[,6]
#plot_n(res8,6,xtype="xconst")# 1D plot of NVC on xconst[,6]
# }
Run the code above in your browser using DataLab