PG {secr} | R Documentation

## Telemetry Fixes in Polygons

### Description

For a telemetry dataset, either as a standalone capthist object with detector type ‘telemetryonly’ or the xylist attribute of a combined capthist object resulting from `addTelemetry`, determine the proportion of fixes of each individual that lie within a set of polygons. Typically used to obtain the proportion of fixes on a trapping grid, hence ‘proportion on grid’.

### Usage

    PG(CH, poly = NULL, includeNULL = FALSE, plt = FALSE, ...)

### Arguments

`CH` | capthist object including telemetry locations
`poly` | SpatialPolygonsDataFrame object from sp
`includeNULL` | logical; if TRUE then missing values are returned for animals without telemetry data
`plt` | logical; if TRUE then poly and telemetry locations are plotted
`...` | other arguments passed to `buffer.contour`

### Details

By default `poly` is obtained by applying `buffer.contour` with arguments ... to the traps attribute of `CH`. Note that either a positive `buffer` argument or `convex = TRUE` is needed for the polygon to have area > 0.

If `plt = TRUE`, `buffer.contour` is used to plot `poly` and the points are overplotted (open circles outside, filled circles inside). To control the framing of the plot, create an initial plot (e.g., with plot.traps, setting the `border` argument) and use `add = TRUE` (see Examples).

### Value

Numeric vector of proportions. If `includeNULL = TRUE` length equal to number of animals (rows) in `CH`; otherwise length is the number of animals for which there is telemetry data (because xylist may cover only a subset of animals in `CH`).

### References

Grant, T. J. and Doherty, P. F. (2007) Monitoring of the flat-tailed horned lizard with methods incorporating detection probability. Journal of Wildlife Management 71, 1050–1056

### See Also

`addTelemetry`, `buffer.contour`, `SpatialPolygonsDataFrame`, `pointsInPolygon`

### Examples

    ## Not run:
    setwd('d:/density communication/combining telemetry and secr/possums')
    CvilleCH <- read.capthist('CVILLE summer captures 4occ.txt',
                              'CVILLE detectors summer 4occ.txt',
                              detector = 'single')
    CvilleGPS <- read.telemetry('CVILLE GPS Combined 4occ.txt')
    CvilleGPSnew <- read.telemetry('CVILLE summer GPS New occasions.txt')
    CvilleBoth <- addTelemetry(CvilleCH, CvilleGPSnew)
    plot(CvilleBoth, border = 400)
    PG(CvilleBoth, buffer = 100, convex = TRUE, plt = TRUE, add = T, col = 'red')

    ###################################################################
    ## this code computes an area-adjusted density estimate
    ## cf Grant and Doherty 2007
    PGD <- function (CH, estimator = 'h2', ...) {
        pg <- PG(CH, ...)
        PGbar <- mean(pg)
        N <- closedN(CH, estimator)
        A <- polyarea(buffer.contour(traps(CH), ...)[[1]])
        Dhat <- N$Nhat / A * PGbar
        varDhat <- (N$Nhat^2 * var(pg) + PGbar^2 * N$seNhat^2) / A^2
        c(Dhat = Dhat, seDhat = sqrt(varDhat))
    }
    plot(traps(CvilleBoth), border = 400)
    PGD(CvilleBoth, buffer = 0, convex = TRUE, plt = TRUE, add = TRUE)
    PGD(CvilleBoth, est='null', buffer = 0, convex = TRUE, plt = FALSE)

    ###################################################################
    ## this code generates a PG summary for telemetry records randomly
    ## translated and rotated, keeping the centres within a habitat mask

    randomPG <- function(CH, poly = NULL, mask, reorient = TRUE, nrepl = 1,
                         seed = 12345, ...) {
        moveone <- function(xy, newcentre) {
            xy <- sweep(xy,2,apply(xy,2,mean))
            if (reorient)  ## random rotation about centre
                xy <- rotate(xy, runif(1)*360)
            sweep(xy,2,unlist(newcentre), "+")
        }
        onerepl <- function(r) {   ## r is dummy for replicate
            centres <- sim.popn(D = D, core = mask, model2D = "IHP",
                                Ndist = "fixed")
            xyl <- mapply(moveone, xyl, split(centres, rownames(centres)))
            attr(CH, 'xylist') <- xyl  ## substitute random placement
            PG(CH = CH , poly = poly, plt = FALSE, ...)
        }
        set.seed(seed)
        require(sp)
        if (is.null(poly)) {
            poly <- buffer.contour (traps(CH), ...)
            srl <- lapply(poly, function(x) Polygon(as.matrix(x)))
            tmp <- Polygons(srl,1)
            poly <- SpatialPolygons(list(tmp))
            poly <- SpatialPolygonsDataFrame(poly, data = data.frame(ID =
                                                   names(poly)))
        }
        xyl <- telemetryxy(CH)
        maskarea <- nrow(mask) * attr(mask, 'area')
        D <- length(xyl) / maskarea
        sapply(1:nrepl, onerepl)
    }

    mask <- make.mask (traps(CvilleBoth), buffer = 400, type = "trapbuffer")
    require(sp)
    pg <- randomPG (CvilleBoth, mask = mask, buffer = 100, convex = TRUE,
        nrepl = 20)
    apply(pg, 1, mean)
    ###################################################################

    ## End(Not run)

[Package secr version 3.2.1 Index]