You are on page 1of 10

Areal analysis in WinBUGS

Installing WinBUGS
1) Go to the website http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml.
2) Save and run the file WinBUGS14.exe.
3) With this educational version you can analyze small data sets. However, to analysis large
spatial datasets you need to register (for free) and obtain the key to unlock the full version.
Register at the website http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/register.shtml. BUGS will
email you the key.
4) Along with the key, youll receive these instructions for using the key.
To install the key for WinBUGS 1.4 please follow these
instructions:
1.

Start your copy of WinBUGS14.

2. Either a) open this file (menu File option Open) as a .txt


file or b) open a new empty window (menu File option New), and
cut and copy this email message into the window (WinBUGS will
ignore all this preceding text).
3. From the Tools menu pick the Decode option. A dialog box will
appear. Click on the "Decode All" button to install the key.
4.

Check the date of the file


c:\Program Files\WinBUGS14\Bugs\Code\Keys.ocf

(or wherever you have installed WinBUGS 1.4). If it shows the


current date and time then the upgrade has been successfully
installed.
Quit and restart WinBUGS to start using the full version.

Simple linear regression in WinBUGS


We observed the data:
X
Y

1
6

2
7

3
8

4
4

5
9

6
11

7
12

8
14

9
15

10
19

First lets do regression in R:


summary(lm(y~x))

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept)
2.8667
1.3574
2.112 0.067681 .
x
1.3879
0.2188
6.344 0.000222 ***

Here is WinBUGS code to perform simple linear regression


#The model:
model{
for(i in 1:n){
y[i]~dnorm(mu[i],taue)
#taue is a precision, not a variance!
mu[i] <- alpha + beta*x[i]
}
taue~dgamma(0.01,0.01)
alpha~dnorm(0,0.01)
beta~dnorm(0,0.01)
}
#The data
list(n=10,x=c(1,2,3,4,5,6,7,8,9,10),y=c(6,7,8,4,9,11,12,14,15,19))
#The initial values
list(taue=1,alpha=0,beta=1)
The steps for running this code are on the next page.
The WinBUGS output is very similar to the R output
node
alpha
beta

mean sd
MC error
2.8
1.531 0.004971
1.397 0.248 8.212E-4

2.5%
-0.2888
0.9059

median
2.813
1.396

97.5%
5.831
1.896

Running WinBUGS
1) Highlight the word model in the first line of the model code.
2) Go to model/specification and click check model. model is syntactically correct should
pop up on the bottom of the WinBUGS window.
3) Highlight list in the data list and click load data. data loaded should pop up on the
bottom of the WinBUGS window.
4) Highlight list in the initial values list and click load inits. Click gen inits to have BUGS
randomly generate initial values.
5) For each variable youd like to analyze, go to inference/sample, enter the name of the
variable in the nodes box, and click set. Samples of variables you dont request to record are
automatically discarded.
6) To begin sampling, go to model/update and click update.
7) When the MCMC sampling is completed, go back to inference/sample to view summaries
of the posterior.

Bayesian kriging in WinBUGS


The Surface elevation data can be found in the BUGS spatial manual, click on
maps/manual/examples. N is the number of observed locations, (x,y) are the N
observation locations, height (surface elevation) is the outcome, and (xpred, ypred) are
M locations where well make predictions of height.
Wed like to fit the model
height ~ N(beta*1,Sigma),
where the beta is the mean of each observation, 1 Nx1 vector of ones, Sigma is the
NxN covariance matrix with ij element equal to sigma2*exp(-phi*h), and h is the
distance between locations i and j. The hyperpriors are
beta ~ Norm(0,0.001) # normal with mean 0, precision 0.01
sigma2 ~ InvGamma(0.001,0,001)
phi ~ Unif(0.001,0.8).
The WinBUGS code for this model is:
model{
height[1:N] ~ spatial.exp(mu[], x[], y[], tau, phi, 1)
for(i in 1:N) {mu[i] <- beta}
beta ~ dnorm(0,0.001)
tau ~ dgamma(0.001, 0.001)
phi ~ dunif(0.001, 0.8)

# Flat prior for the intercept


# Conjugate inverse gamma on the precision
# Uniform prior on phi

for(j in 1:M) {
# Make predictions at unobserved locations
height.pred[j] ~ spatial.unipred(beta, x.pred[j], y.pred[j], height[])
}

}
There are two way to do prediction in BUGS, spatial.pred and spatial.unipred
BUGS manual says Spatial interpolation or prediction at arbitrary locations can be carried out using the
spatial.pred or spatial.unipred functions, in conjunction with fitting the spatial.exp model to a set of
observed data. spatial.pred carries out joint or simultaneous prediction at a set of target locations,
whereas spatial.unipred carries out single site prediction. The difference is that the single site prediction
yields marginal prediction intervals (i.e. ignoring correlation between prediction locations) whereas joint
prediction yields simultaneous prediction intervals for the set of target locations (which will tend to be
narrower than the marginal prediction intervals). The predicted means should be the same under joint or
single site prediction. The disadvantage of joint prediction is that it is very slow (the computational time is
of order P3, where P is the number of prediction sites).

Here are the initial values:


list(tau=0.001, phi=0.4, beta=820)

The data well be using is


list(N=52, M= 225,
x = c(0.3, 1.4, 2.4, 3.6, 5.7, 1.6, 2.9, 3.4, 3.4, 4.8, 5.3, 6.2, 0.2, 0.9, 2.3, 2.5,
3, 3.5, 4.1, 4.9, 6.3, 0.9, 1.7, 2.4, 3.7, 4.5, 5.2, 6.3, 0.3, 2, 3.8, 6.3, 0.6, 1.5,
2.1, 2.1, 3.1, 4.5, 5.5, 5.7, 6.2, 0.4, 1.4, 1.4, 2.1, 2.3, 3.1, 4.1, 5.4, 6, 5.7,
3.6),
y = c(6.1, 6.2, 6.1, 6.2, 6.2, 5.2, 5.1, 5.3, 5.7, 5.6, 5, 5.2, 4.3, 4.2, 4.8, 4.5,
4.5, 4.5, 4.6, 4.2, 4.3, 3.2, 3.8, 3.8, 3.5, 3.2, 3.2,
3.4, 2.4, 2.7, 2.3, 2.2, 1.7, 1.8, 1.8, 1.1, 1.1, 1.8, 1.7, 1, 1, 0.5, 0.6, 0.1, 0.7,
0.3, 0, 0.8, 0.4, 0.1, 3, 6),
height = c(870, 793, 755, 690, 800, 800, 730, 728,710, 780, 804, 855, 830, 813, 762,
765, 740, 765, 760, 790, 820, 855,
812, 773, 812, 827, 805, 840, 890, 820, 873, 875, 873, 865, 841, 862, 908, 855, 850,
882, 910, 940, 915, 890, 880, 870, 880, 960, 890, 860, 830, 705),
x.pred=c(0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21,
0.21, 0.21, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63,
0.63, 0.63, 0.63, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05,
1.05, 1.05, 1.05, 1.05, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47,
1.47, 1.47, 1.47, 1.47, 1.47, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89,
1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31,
2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73,
2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15,
3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.57, 3.57, 3.57, 3.57, 3.57,
3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.99, 3.99, 3.99, 3.99,
3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 4.41, 4.41, 4.41,
4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.83, 4.83,
4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 5.25,
5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25,
5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67,
5.67, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09,
6.09, 6.09),
y.pred=c(6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05,
0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47,
1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89,
1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31,
1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73,
2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15,
2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57,
3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99,
3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41,
3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83,
4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25,
4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67,
5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09,
5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21,
6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63,
0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05,
0.63, 0.21))

Map the predicted values at unobserved locations


1) Set a monitor on the variable height.pred and generate some MCMC samples.
2) Open the mapping tool, map/mapping tool.
3) Select map: Elevation. In general, the grid for the data youre working will not be predloaded
in WinBUGS. In this case, you can either load the grid or export your results to R or ArcGIS to
make plots.
4) Select variable: height.pred.
5) Select quantity=mean(sample).
6) Select plot .

Calling WinBUGS from R


library(R2WinBUGS) # Download this package from CRAN.
Step 1) Create a file with the WinBUGS commands to specify the model. For example, create
the file C:/Documents and Settings/fuentes/Desktop/Rbugs.txt with the following lines:
model{
height[1:N] ~ spatial.exp(mu[], x[], y[], tau, phi, 1)
for(i in 1:N) {mu[i] <- beta}
beta ~ dflat()
tau ~ dgamma(0.001, 0.001)
phi ~ dunif(0.001, 0.8)

# Flat prior for the intercept


# Conjugate inverse gamma on the precision
# Uniform prior on phi

for(j in 1:M) {
# Make predictions at unobserved locations
height.pred[j] ~ spatial.unipred(beta, x.pred[j], y.pred[j], height[])
}

}
Step 2) Load the data in R
Here is R code to load the surface elevation data.
N<-52
M<-225
x<-c(0.3, 1.4, 2.4, 3.6, 5.7, 1.6, 2.9, 3.4, 3.4, 4.8, 5.3, 6.2, 0.2, 0.9, 2.3, 2.5, 3, 3.5, 4.1, 4.9, 6.3, 0.9, 1.7, 2.4, 3.7, 4.5, 5.2,
6.3, 0.3, 2, 3.8, 6.3, 0.6, 1.5, 2.1, 2.1, 3.1, 4.5, 5.5, 5.7, 6.2, 0.4, 1.4, 1.4, 2.1, 2.3, 3.1, 4.1, 5.4, 6, 5.7, 3.6)
y <- c(6.1, 6.2, 6.1, 6.2, 6.2, 5.2, 5.1, 5.3, 5.7, 5.6, 5, 5.2, 4.3, 4.2, 4.8, 4.5, 4.5, 4.5, 4.6, 4.2, 4.3, 3.2, 3.8, 3.8, 3.5, 3.2, 3.2,
3.4, 2.4, 2.7, 2.3, 2.2, 1.7, 1.8, 1.8, 1.1, 1.1, 1.8, 1.7, 1, 1, 0.5, 0.6, 0.1, 0.7, 0.3, 0, 0.8, 0.4, 0.1, 3, 6)
height <- c(870, 793, 755, 690, 800, 800, 730, 728, 710, 780, 804, 855, 830, 813, 762, 765, 740, 765, 760, 790, 820, 855,
812, 773, 812, 827, 805, 840, 890, 820, 873, 875, 873, 865, 841, 862, 908, 855, 850, 882, 910, 940, 915, 890, 880, 870,
880, 960, 890, 860, 830, 705)
x.pred<-c(0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.21, 0.63, 0.63, 0.63, 0.63, 0.63,
0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 0.63, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05,
1.05, 1.05, 1.05, 1.05, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.47, 1.89,
1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 1.89, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31,
2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.31, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73, 2.73,
3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.15, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57,
3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.57, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99, 3.99,
3.99, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.41, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83,
4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 4.83, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25, 5.25,
5.25, 5.25, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 5.67, 6.09, 6.09, 6.09, 6.09, 6.09,
6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09, 6.09)

lat<- c(6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05,
0.63, 0.21)
y.pred<-c(rep(lat,15))
y.pred<- c(6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41,
3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47,
1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83,
4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89,
1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25,
4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31,
1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67,
5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73,

2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09,
5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15, 2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21, 6.09, 5.67, 5.25, 4.83, 4.41, 3.99, 3.57, 3.15,
2.73, 2.31, 1.89, 1.47, 1.05, 0.63, 0.21)

Step 3) Call WinBUGS from R


First, load the package R2WinBUGS from CRAN. Then submit the following code in R.
modelfile<-"Rbugs.txt
data<-list(N,M,x,y,height,x.pred,y.pred)
vars2keep<-list("phi,height.pred)
inits<-function(){list(tau=0.001, phi=0.4, beta=820)}
output<-bugs(
model.file=file.path(modelfile),
data=data,
inits = inits,
parameters.to.save = vars2keep,
n.chains=2,
n.iter=1000,
n.burnin=500,
n.thin=10,
debug=TRUE,
DIC=TRUE
)

Step 4) Analyze the MCMC output


# Check convergence
plot(output)
# Plot the posterior of phi
samples<-output$sims.matrix #samples is a matrix with all the MCMC samples.
#each variable is a column
hist(samples[,1],main=Posterior of phi)
#the first column is phi
#Plot the predicted values at the unobserved locations
predvals<-output$mean$height.pred
#predvals is a vector with the post
#pred means at the unobserved sites
# Lets use filled.contour to plot the predicted surface on the 15x15 grid. This
# Function needs a 15x1 vector of x and y coordinates and a 15x15 matrix of
# predicted values.
long<-sort(unique(x.pred))
lat<-sort(unique(y.pred))
z<-matrix(0,15,15)
for(i in 1:15){
for(j in 1:15){
z[i,j]<-predvals[x.pred==long[i] & y.pred==lat[j]]
}
}
filled.contour(long,lat,z,xlab=x,ylab=y,main=Predicted Height)

Analyzing areal data in WinBUGS


A model for spatial count data is: O[i] ~ Poisson(E[i]*exp(theta[i])
Where O[i] is the observed count in region I, E[i] is the known offset term (usually population
size) and theta[i] is the spatial random effect that controls whether the rate is above or below
average for region i.
The theta[i] are spatially smoothed with a conditionally autoregressive prior (CAR). Under the
CAR prior, theta[i] conditional on all theta at all sites other than site i is normal with mean equal
to the average of the neighboring theta[j] and variance equal to sigma^2/ m[i], where m[i] is the
number of neighbors and sigma^2 is an unknown variance parameters.
Here is the CAR model in WinBUGS for the lip cancer data in the BUGS map manual.
model{
for (i in 1 : N) {
O[i] ~ dpois(mu[i])
log(mu[i]) <- log(E[i]) + theta[i]
theta[i] <- a+b[i]
}
# BUGS automatically centers the CAR random effect to have mean zero, so you have to add an
# intercept (a) to allow the average of theta to be nonzero.
# CAR prior distribution for random effects, the sum of b is always zero
b[1:N] ~ car.normal(adj[], weights[], m[], tau)
for(k in 1:sumNumNeigh) {weights[k] <- 1} #weight each neighbor the same
#in the conditional prior mean of theta[i]
# Other priors:
a ~ dflat()
tau ~ dgamma(0.5, 0.0005)

# prior on precision

}
The initial values are
list(tau = 1, a=0, b=c(0,0,0,0,0,NA,0,NA,0,0, NA,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0))

#sites with no neighbors have b=NA


The data are:
list(N = 56,
O = c( 9, 39, 11, 9, 15, 8, 26, 7, 6, 20, 13, 5, 3, 8, 17, 9, 2, 7, 9, 7, 16, 31, 11, 7, 19, 15,
7, 10, 16, 11, 5, 3, 7, 8, 11, 9, 11, 8, 6, 4, 10, 8, 2, 6, 19, 3, 2, 3, 28, 6, 1, 1, 1, 1, 0, 0),
E = c( 1.4, 8.7, 3.0, 2.5, 4.3, 2.4, 8.1, 2.3, 2.0, 6.6, 4.4, 1.8, 1.1, 3.3, 7.8, 4.6, 1.1, 4.2, 5.5, 4.4, 10.5,22.7, 8.8, 5.6,15.5,12.5, 6.0,
9.0,14.4,10.2, 4.8, 2.9, 7.0, 8.5,12.3,10.1,12.7, 9.4, 7.2, 5.3, 18.8,15.8, 4.3,14.6,50.7, 8.2, 5.6, 9.3,88.7,19.6,3.4, 3.6, 5.7, 7.0, 4.2,
1.8),
m = c(3, 2, 1, 3, 3, 0, 5, 0, 5, 4, 0, 2, 3, 3, 2, 6, 6, 6, 5, 3, 3, 2, 4, 8, 3, 3, 4, 4, 11, 6, 7, 3, 4, 9, 4, 2, 4, 6, 3, 4, 5, 5, 4, 5, 4, 6, 6, 4, 9,
2, 4, 4, 4, 5, 6, 5),
sumNumNeigh = 234,

#Here is where we tell BUGS how to set up the adjacency structure. For example, site 1 neighbors sites 19,9, and 5.
adj = c(
19, 9, 5,
10, 7,
12,
28, 20, 18,
19, 12, 1,
#Site 6 has no neighbors
17, 16, 13, 10, 2,
29, 23, 19, 17, 1,
22, 16, 7, 2,
5, 3,
19, 17, 7,
35, 32, 31,
29, 25,
29, 22, 21, 17, 10, 7,
29, 19, 16, 13, 9, 7,
56, 55, 33, 28, 20, 4,
17, 13, 9, 5, 1,
56, 18, 4,
50, 29, 16,
16, 10,
39, 34, 29, 9,
56, 55, 48, 47, 44, 31, 30, 27,
29, 26, 15,
43, 29, 25,
56, 32, 31, 24,
45, 33, 18, 4,
50, 43, 34, 26, 25, 23, 21, 17, 16, 15, 9,
55, 45, 44, 42, 38, 24,
47, 46, 35, 32, 27, 24, 14,
31, 27, 14,
55, 45, 28, 18,
54, 52, 51, 43, 42, 40, 39, 29, 23,
46, 37, 31, 14,
41, 37,
46, 41, 36, 35,
54, 51, 49, 44, 42, 30,
40, 34, 23,
52, 49, 39, 34,
53, 49, 46, 37, 36,
51, 43, 38, 34, 30,
42, 34, 29, 26,
49, 48, 38, 30, 24,
55, 33, 30, 28,
53, 47, 41, 37, 35, 31,
53, 49, 48, 46, 31, 24,
49, 47, 44, 24,
54, 53, 52, 48, 47, 44, 41, 40, 38,
29, 21,
54, 42, 38, 34,
54, 49, 40, 34,
49, 47, 46, 41,
52, 51, 49, 38, 34,
56, 45, 33, 30, 24, 18,
55, 27, 24, 20, 18
))

You might also like