From bcp v4.0.3
0th

Percentile

##### Creating the adjacency structure for grid graphs

makeAdjGrid() produces a sparse representation of the adjacency structure for grid graphs, useful as the adj argument in bcp().

Keywords
datasets
##### Usage
makeAdjGrid(n, m = NULL, k = 8)
##### Arguments
n

the number of rows of vertices in the graph data.

m

(optional) the number of column of vertices in the graph data. If not given, we assume m = n.

k

(optional) the number of neighbors assumed for a typical vertex (see details below), either 4 or 8. Default number of neighbors is assumed to be 8.

##### Details

makeAdjGrid() produces a list representation of the adjacency structure for grid graphs. The $i$-th entry in the list gives a vector of neighbor ids for the $i$-th node. Note that neighbor ids are offset by 1 because indexing starts at 0 in C++. If k = 8, then we assume each node is joined via edges to its 8 neighbors in the (top left, top middle, top right, left, right, bottom left, bottom middle, and bottom right) directions, where applicable. If k = 4, then we assume each node is joined via edges to its 4 neighbors in the (top, right, bottom, left) directions, where applicable.

bcp for performing Bayesian change point analysis.

##### Examples
# NOT RUN {
# generates an adjacency list for a 10 node by 5 node grid, assuming a maximum of 8 neighbors

# generates an adjacency list for a 10 node by 5 node grid, assuming a maximum of 4 neighbors

### show a grid example
# }
# NOT RUN {
set.seed(5)
z <- rep(c(0, 2), each=200)
y <- z + rnorm(400, sd=1)

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') +
ggtitle("Observed Data")
print(g)

# visualize the means
g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = mean), color='white') +
ggtitle("True Means")
print(g)

# visualize the posterior means/probs
g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = post.means), color='white') +
ggtitle("Posterior Means")
print(g)

g <- ggplot(df, aes(i,j)) +
geom_tile(aes(fill = post.probs), color='white') +