I'm trying to simulate a release of fish over 5 non-consecutive years (2002, 2010, 2012, 2013, 2014).
The model is a simple constant phi and p. The results of the simulation are nowhere near my initial values. I get very similar results running the simulation directly in MARK, so there's either something very stupid I do upfront, or there's something fundamental I'm misunderstanding in the process. Any help would be appreciated...
- Code: Select all
library(RMark)
# create simulated data (code borrowed from here
#https://sites.google.com/site/wild8390/software/simulate)
simul.cjs <- function(phi, p, marked){
n.occasions <- length(p) + 1
Phi <- matrix(phi, n.occasions-1, nrow=sum(marked), byrow=T)
P <- matrix(p, n.occasions-1, nrow=sum(marked), byrow=T)
CH <- matrix(0, ncol = n.occasions, nrow = sum(marked))
#define a vector with marking occasion
mark.occ <- rep(1:length(marked), marked[1:length(marked)])
#fill in CH
for(i in 1:sum(marked)){
CH[i,mark.occ[i]] <- 1
if(mark.occ[i] == n.occasions)
next
for(t in (mark.occ[i]+1):n.occasions){
#survive?
sur <- rbinom(1, 1, Phi[i,t-1])
if(sur == 0)
break #move to next
#recaptured?
rp <- rbinom(1, 1, P[i,t-1])
if(rp == 1)
CH[i,t] <- 1
} #t
} #i
return(CH)
}
###function to create capture history character strings (need for input to RMARK)
pasty <- function(x){
k <- ncol(x)
n <- nrow(x)
out <- array(dim=n)
for(i in 1:n){
out[i] <- paste(x[i,], collapse="")
}
return(out) }
# simulate release of 10,000 fish every year - the number is crazy high to make sure there's no sample size issue in the estimates
marked <- rep(10000, 5)
data <- simul.cjs(rep(0.3, 4), rep(0.2, 4), marked)
data <- pasty(data)
data <- data.frame(ch = data)
data.proc <- process.data(data, model="CJS", begin.time=2002, time.intervals = diff(c(2002, 2010, 2012, 2013, 2014)), initial.ages = 0)
data.ddl <- make.design.data(data.proc)
data.analysis=function(){
Phi.1 = list(formula=~1)
p.1=list(formula=~1)
cml=create.model.list("CJS")
mark.wrapper(cml,data=data.proc,ddl=data.ddl,output=FALSE, retry = 0, delete = TRUE)
}
data.results <- data.analysis()
data.results$Phi.1.p.1$results$real