summary(fieldvoleCH, terse = TRUE)
m.array(fieldvoleCH)
JS.counts(fieldvoleCH)
attr(fieldvoleCH, 'ampm')
if (FALSE) {
maleCH <- subset(fieldvoleCH, function(x) covariates(x) == 'M')
fit <- openCR.fit(maleCH)
predict(fit)
# Read data object from DRYAD ASCII file
datadir <- system.file('extdata', package = 'openCR')
EG <- dget(paste0(datadir,'/ergonandgardner2013.rdat'))
# construct capthist object
onesession <- function (sess) {
mat <- EG$H[,,sess]
id <- as.numeric(row(mat))
occ <- as.numeric(col(mat))
occ[mat<0] <- -occ[mat<0]
trap <- abs(as.numeric(mat))
matrow <- rownames(mat)
df <- data.frame(session = rep(sess, length(id)),
ID = matrow[id],
occ = occ,
trapID = trap,
sex = c('F','M')[EG$gr],
row.names = 1:length(id))
# retain captures (trap>0)
df[df$trapID>0, , drop = FALSE]
}
tr <- read.traps(data = data.frame(EG$X), detector = "multi")
# recode matrix as mixture of zeros and trap numbers
EG$H <- EG$H-1
# code censored animals with negative trap number
# two ways to recognise censoring
censoredprimary <- which(EG$K < 4)
censoredsecondary <- which(apply(EG$J,1,function(x) any(x-c(3,5,4,5) < 0)))
censored <- unique(c(censoredprimary, censoredsecondary))
rownames(EG$H)[censored]
# [1] "ma193" "ma239" "ma371" "ma143" "ma348"
censorocc <- apply(EG$H[censored,,], 1, function(x) which.max(cumsum(x)))
censor3 <- ((censorocc-1) %/% 5)+1 # session
censor2 <- censorocc - (censor3-1) * 5 # occasion within session
censori <- cbind(censored, censor2, censor3)
EG$H[censori] <- -EG$H[censori]
lch <- lapply(1:4, onesession)
ch <- make.capthist(do.call(rbind,lch), tr=tr, covnames='sex')
# apply intervals in months
intervals(ch) <- EG$dt
fieldvoleCH <- ch
# extract time covariate - each secondary session was either am (2) or pm (1)
# EG$tod
# 1 2 3 4 5
# 1 2 1 2 NA NA
# 2 2 1 2 1 1
# 3 2 1 2 1 NA
# 4 2 1 2 1 2
# Note consecutive pm trap checks in session 2
ampm <- split(EG$tod, 1:4)
ampm <- lapply(ampm, na.omit)
attr(fieldvoleCH, 'ampm') <- data.frame(ampm = unlist(ampm))
}
Run the code above in your browser using DataLab