Learn R Programming

secr (version 5.0.0)

BUGS: Convert Data To Or From BUGS Format

Description

Convert data between `capthist' and BUGS input format.

Usage

read.DA(DAlist, detector = "polygonX", units = 1, session = 1,
    Y = "Y", xcoord = "U1", ycoord = "U2", xmin = "Xl",
    xmax = "Xu", ymin = "Yl", ymax = "Yu", buffer = "delta",
    verify = TRUE)

write.DA(capthist, buffer, nzeros = 200, units = 1)

Value

For read.DA, an object of class `capthist'.

For write.DA, a list with the components

Xlleft edge of state spaceXu
right edge of state spaceYlbottom edge of state space
Yutop edge of state spacedelta
buffer between edge of state space and quadratnindnumber of animals observed
nzerosnumber of added all-zero detection historiesT
number of sampling occasionsYbinary matrix of detection histories (dim = c(nind+nzeros, T))
U1matrix of x-coordinates, dimensioned as YU2

U1 and U2 are `NA' where animal was not detected.

Arguments

DAlist

list containing data in BUGS format

detector

character value for detector type: `polygon' or `polygonX'

units

numeric for scaling output coordinates

session

numeric or character label used in output

Y

character, name of binary detection history matrix (animals x occasions)

xcoord

character, name of matrix of x-coordinates for each detection in Y

ycoord

character, name of matrix of y-coordinates for each detection in Y

xmin

character, name of coordinate of state space boundary

xmax

character, name of coordinate of state space boundary

ymin

character, name of coordinate of state space boundary

ymax

character, name of coordinate of state space boundary

buffer

see Details

verify

logical if TRUE then the resulting capthist object is checked with verify

capthist

capthist object

nzeros

level of data augmentation (all-zero detection histories)

Details

Data for OpenBUGS or WinBUGS called from R using the package R2WinBUGS (Sturtz et al. 2005) take the form of an R list.

These functions are limited at present to binary data from a square quadrat such as used by Royle and Young (2008). Marques et al. (2011) provide an R function create.data() for generating simulated datasets of this sort (see sim.capthist for equivalent functionality).

When reading BUGS data --

The character values Y, xcoord, ycoord, xmin etc. are used to locate the data within DAlist, allowing for variation in the input names.

The number of sampling occasions is taken from the number of columns in Y. Each value in Y should be 0 or 1. Coordinates may be missing

A numeric value for buffer is the distance (in the original units) by which the limits Xl, Xu etc. should be shrunk to give the actual plot limits. If buffer is character then a component of DAlist contains the required numeric value.

Coordinates in the output will be multiplied by the scalar units.

Augmentation rows corresponding to `all-zero' detection histories in Y, xcoord, and ycoord are discarded.

When writing BUGS data --

Null (all-zero) detection histories are added to the matrix of detection histories Y, and missing (NA) rows are added to the coordinate matrices xcoord and ycoord.

Coordinates in the output will be divided by the scalar units.

References

Marques, T. A., Thomas, L. and Royle, J. A. (2011) A hierarchical model for spatial capture--recapture data: Comment. Ecology 92, 526--528.

Royle, J. A. and Young, K. V. (2008) A hierarchical model for spatial capture--recapture data. Ecology 89, 2281--2289.

Sturtz, S., Ligges, U. and Gelman, A. (2005) R2WinBUGS: a package for running WinBUGS from R. Journal of Statistical Software 12, 1--16.

See Also

hornedlizardCH, verify, capthist

Examples

Run this code

write.DA (hornedlizardCH, buffer = 100, units = 100)

## In this example, the input uses Xl, Xu etc.
## for the limits of the plot itself, so buffer = 0.
## Input is in hundreds of metres.
## First, obtain the list lzdata
olddir <- setwd (system.file("extdata", package="secr"))
source ("lizarddata.R")
setwd(olddir)
str(lzdata)
## Now convert to capthist
tempcapt <- read.DA(lzdata, Y = "H", xcoord = "X",
    ycoord = "Y", buffer = 0, units = 100)

if (FALSE) {

plot(tempcapt)
secr.fit(tempcapt, trace = FALSE)
## etc.

}

Run the code above in your browser using DataLab