##################################################
#### Run the model on simulated data on a lattice
##################################################
### Set up a square lattice region
x.easting <- 1:10
x.northing <- 1:10
Grid <- expand.grid(x.easting, x.northing)
n <- nrow(Grid)
#### Generate the covariates and response data
x1 <- rnorm(n)
x2 <- rnorm(n)
E <- rep(40,n)
theta <- rnorm(n, sd=0.05)
risk <- exp(-0.2 + 0.1 * x1 + 0.1*x2 + theta)
fitted <- E * risk
Y <- rpois(n=n, lambda=fitted)
#### Run the independence model
#### Let the function randomly generate starting values for the parameters
#### Use the default priors specified by the function (for details see the help files)
formula <- Y ~ x1 + x2 + offset(log(E))
model <- poisson.independent(formula=formula, burnin=5000, n.sample=10000)
model <- poisson.independent(formula=formula, burnin=20, n.sample=50)
Run the code above in your browser using DataLab