## 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)
# ###################################################################
#
## ---------------------------------------------
Run the code above in your browser using DataLab