# A function to define the correlations between a subset and its neighbors
# Returned values should not exceed the value of 1
cor.def <- function(subset, neighbors, k, ncase, ncntl) {
n <- ncol(neighbors)
mat <- matrix(subset, nrow=k, ncol=n, byrow=FALSE)
cor <- (mat + neighbors)*(1:k)/(k^2)
cor <- colSums(cor)
cor <- cor/max(cor)
dim(cor) <- c(n, 1)
cor
}
# Subset definition
sub.def <- function(logicalVec, args) {
# Only allow the cummulative subsets:
# TRUE FALSE FALSE FALSE ...
# TRUE TRUE FALSE FALSE ...
# TRUE TRUE TRUE FALSE ...
# etc
sum <- sum(logicalVec)
ret <- all(logicalVec[1:sum])
ret
}
k <- 5
t.vec <- 1:k
z.sub <- rep(1, k)
p.dlm(t.vec, z.sub, 1, 2, cor.def=cor.def, sub.def=sub.def,
cor.args=list(ncase=rep(1000, k), ncntl=rep(1000,k)))
Run the code above in your browser using DataLab