require(spdep)
data(boston)
samp <- sample( dim( boston.c )[ 1 ], 300)
d <- boston.c[ samp, ] ## Data at observed sites
y <- d[, "CMEDV"]
x <- d[,c("ZN", "LSTAT")]
xconst <- d[,c("CRIM", "NOX", "AGE", "DIS", "RAD", "TAX", "PTRATIO", "B", "RM")]
coords <- d[,c("LON", "LAT")]
d0 <- boston.c[-samp, ] ## Data at unobserved sites
y0 <- d0[, "CMEDV"]
x0 <- d0[,c("ZN", "LSTAT")]
xconst0 <- d0[,c("CRIM", "NOX", "AGE", "DIS", "RAD", "TAX", "PTRATIO", "B", "RM")]
coords0 <- d0[,c("LON", "LAT")]
############ Model estimation
meig <- meigen( coords )
mod <- resf_vc(y=y, meig=meig, x=x, xconst=xconst )
############ Spatial prediction of y and spatially varying coefficients
meig0 <- meigen0( meig=meig, coords0=coords0)
pred0 <- predict0_vc( mod = mod, meig0=meig0, x0 = x0, xconst0=xconst0 )
pred0$pred[1:5,] # Predicted explained variables
pred0$b_vc[1:5,] # Predicted SVCs
pred0$bse_vc[1:5,]# Predicted standard errors of the SVCs
pred0$z_vc[1:5,] # Predicted z-values of the SVCs
pred0$p_vc[1:5,] # Predicted p-values of the SVCs
plot(y0,pred0$pred[,1]);abline(0,1)
Run the code above in your browser using DataLab