# NOT RUN {
# generates an adjacency list for a 10 node by 5 node grid, assuming a maximum of 8 neighbors
adj <- makeAdjGrid(10, 5)
# generates an adjacency list for a 10 node by 5 node grid, assuming a maximum of 4 neighbors
adj4 <- makeAdjGrid(10, 5, 4)
### show a grid example
# }
# NOT RUN {
set.seed(5)
adj <- makeAdjGrid(20)
z <- rep(c(0, 2), each=200)
y <- z + rnorm(400, sd=1)
out <- bcp(y, adj=adj, burnin=500, mcmc=500)
if (require("ggplot2")) {
df <- data.frame(mean=z, data = y, post.means = out$posterior.mean[,1],
post.probs = out$posterior.prob,
i = rep(1:20, each=20), j = rep(1:20, times=20))
# visualize the data
g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = data), color='white') +
scale_fill_gradientn(limits=range(y), colours=c('white', 'steelblue'))+
ggtitle("Observed Data")
print(g)
# visualize the means
g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = mean), color='white') +
scale_fill_gradientn(limits=range(y), colours=c('white', 'steelblue'))+
ggtitle("True Means")
print(g)
# visualize the posterior means/probs
g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = post.means), color='white') +
scale_fill_gradientn(limits=range(y), colours=c('white', 'steelblue'))+
ggtitle("Posterior Means")
print(g)
g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = post.probs), color='white') +
scale_fill_gradientn(limits=c(0, 1), colours=c('white', 'steelblue'))+
ggtitle("Posterior Boundary Probabilities")
print(g)
}
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab