# NOT RUN {
# }
# NOT RUN {
# get a winbugs model and data ready, without a spatial effect
data(ontario)
forBugs = glmmBUGS(formula=observed + logExpected ~ 1,
effects="CSDUID", family="poisson",
data=data.frame(ontario))
# now add a spatial effect.
# first, compute the adjacency matrix
# if region ID's are stored as factors, make sure to convert
# them to characters rather than the default of converting them
# to integers
library(diseasemapping)
data(popdata)
popDataAdjMat = poly2nb(popdata,row.names=as.character(popdata[["CSDUID"]]) )
data(popDataAdjMat)
# add the adjacency matrix to the ragged array
raggedWithSpatial = addSpatial(popDataAdjMat, forBugs$ragged, "CSDUID")
# write a new bugs model with a spatial effect
writeBugsModel("model.bug", "CSDUID", NULL, c("count", "expected"),
"poisson", spatial="CSDUID")
startingValues = forBugs$startingValues
source("getInits.R")
library(R2WinBUGS)
popResult = bugs(raggedWithSpatial, getInits,
parameters.to.save = names(getInits()), model.file="model.bug",
n.chain=3, n.iter=1000, n.burnin=100, n.thin=10, program="winbugs")
# }
Run the code above in your browser using DataLab