When sending data to a WinBUGS model, one needs to specify, among other things, a list of:
- capture history matrix (rows is specimens, columns is sampling sessions)
- matrix of coordinates of northing for each individual for each sampling session (rows is specimens, columns is sampling sessions)
- matrix of coordinates of easting for each individual for each sampling session (rows is specimens, columns is sampling sessions)
In the `hornedlizardCH` dataset, capture history comes in a matrix as needed, but coordinates needed some tweaking.
There are 134 coordinates, which corresponds to the number of total capture events.
- Code: Select all
> tail(xy(hornedlizardCH))
x y
129 443.5293 536.9451
130 397.1012 321.8544
131 376.2096 462.3878
132 545.6080 456.2584
133 485.2161 415.5342
134 403.1627 321.9645
- Code: Select all
> nrow(xy(hornedlizardCH)) == sum(hornedlizardCH)
[1] TRUE
To me, the help file of the dataset wasn't explicit enough, so I queried Murray, who confirmed that each coordinate corresponds to a capture event as ordered in the capture history. First coordinate is of the first animal captured on occasion 8... and the last three coordinates correspond to animal 68 captured on occasion 7, 8 and 9.
Proof sent to me by Murray that shows which coordinates correspond to which animal.
- Code: Select all
cbind(occ = occasion(hornedlizardCH), ID = animalID(hornedlizardCH), xy(hornedlizardCH))
occ ID x y
1 2 38 482.7031 473.0377
2 2 44 456.4630 455.9538
3 3 35 485.8071 346.4861
4 3 37 458.3091 489.8591
5 3 48 439.0346 495.4281
6 3 49 395.4584 385.6218
7 3 53 469.7518 427.9140
8 3 57 409.0684 394.2549
9 3 58 548.3365 414.0505
10 4 7 473.5457 544.5610
Once we realize this, replacing capture events with coordinates for x and y is more or less trivial. Here's how I did it.
- Code: Select all
hl.U1 <- hl.U2 <- hornedlizardCH # create "empty" objects from capture history
all.zeros <- which(hl.cap == 0) # where are zeros?
all.one <- which(hl.cap == 1) # where are ones?
# replace values with NA or actual coordinates
hl.U1[all.zeros] <- NA
hl.U2[all.zeros] <- NA
hl.U1[all.one] <- xy(hornedlizardCH)[, "x"]
hl.U2[all.one] <- xy(hornedlizardCH)[, "y"]
> head(hl.U1)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
[1,] NA NA NA NA NA NA NA 581.8215 NA NA NA NA NA NA
[2,] NA NA NA NA NA NA NA 565.2918 NA NA NA NA NA NA
[3,] NA NA NA NA NA NA NA 522.8691 NA NA NA NA NA NA
[4,] NA NA NA NA NA NA NA 487.9365 NA NA NA NA NA NA
[5,] NA NA NA NA NA NA NA NA NA NA NA NA 598.0066 NA
[6,] NA NA NA NA NA NA NA NA NA NA NA NA 598.0066 NA