# \donttest{
data(scallops)
Y<-log(scallops[,5]+1)
s_coords <- scallops[,3:4] #lat and long
m <- dim(s_coords)[1]
# standardize spatial coordinates
smn <- apply(s_coords,2,mean)
ssd <- apply(s_coords,2,sd)
s_std <- t((t(s_coords) - smn)/ssd)
# Create a grid of prediction locations
np <- 10
sp <- expand.grid(seq(min(s_coords[,1]), max(s_coords[,1]),length=np),
seq(min(s_coords[,2]), max(s_coords[,2]), length=np))
sp_std <- t((t(sp) - smn)/ssd) # standardized prediction spatial coordinates
niter <- 20000
nburn <- 10000
nthin <- 10
nout <- (niter - nburn)/nthin
out <- sppm(y=Y,s=s_std,s.pred=sp_std,cohesion=4, M=1, draws=niter, burn=nburn, thin=nthin)
# fitted values
fitted.values <- out$fitted
fv.mn <- apply(fitted.values, 2,mean)
mean((Y - fv.mn)^2) # MSE
out$lpml #lpml value
ppred <- out$ppred
predmn <- apply(ppred,2,mean)
# The first partition iterate is used for plotting
# purposes only. We recommended using the salso
# R-package to estimate the partition based on Si
Si <- out$Si
plot(s_coords[,1], s_coords[,2], col=Si[1,])
# }
Run the code above in your browser using DataLab