# Set up constants and initial values for defining the model
x <- matrix(c(0,0,0,0,
1,1,1,0,
0,0,0,0,
0,0,1,0,
0,0,0,0), nrow = 4)
start <- c(1,1,2,1,1)
end <- c(5,5,5,4,5)
init <- 0.7
probPersist <- 0.5
probColonize <- 0.2
p <- matrix(rep(0.5, 20), nrow = 4)
# Define code for a nimbleModel
nc <- nimbleCode({
x[1:2, 1:5] ~ dDynOcc_vvm(init,
probPersist[1:2], probColonize[1:2], p[1:2,1:5],
start = start[1:4], end = end[1:4])
init ~ dunif(0,1)
for (i in 1:2) {
probPersist[i] ~ dunif(0,1)
probColonize[i] ~ dunif(0,1)
}
for (i in 1:2) {
for (j in 1:5) {
p[i,j] ~ dunif(0,1)
}
}
})
# Build the model, providing data and initial values
DynOcc_model <- nimbleModel(nc, data = list(x = x),
constants = list(start = start, end = end),
inits = list(p = p, probPersist = probPersist,
init = init, probColonize = probColonize))
# Calculate log probability of data from the model
DynOcc_model$calculate("x")
# Use the model for a variety of other purposes...
Run the code above in your browser using DataLab