Hi all,
I have a question that I haven't been able to find an answer for yet on the forum.
I've got a multi-season dataset (21 seasons, 150 sites, uneven effort at each site) that I'm running colext models for, so that I can model occupancy dynamics over time. Summary as follows:
unmarkedFrame Object
150 sites
Maximum number of observations per site: 252
Mean number of observations per site: 79.17
Number of primary survey periods: 21
Number of secondary survey periods: 12
Sites with at least one detection: 147
Tabulation of y observations:
0 1 <NA>
10620 1255 25925
My question that I am trying to answer is how occupancy, colonisation and extinction differ between two treatments. So my sitecov matrix looks like this:
sitecovs = data.frame(Treatment = matrix(c(rep("T",25), rep("C", 25), rep("T", 25),
rep("T", 25), rep("C", 25), rep("C",25)), nrow=150))
And I also want to test for differences across seasons, so this is in the yearlysitecovs:
season = matrix(c("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21"), 150, 21, byrow=TRUE)
And my formula looks like this:
m1 <- colext(psiformula = ~Treatment-1, # Occupancy
gammaformula = ~ Treatment*season-1, # Colonization
epsilonformula = ~ Treatment*season-1, # Extinction
pformula = ~ 1, # Detection
data = umf)
I am wanting to calculate Occupancy at each time step at each treatment. I have been able to follow the example in the dynamic occupancy model vignette and produce an occupancy estimate over time across all my sites, but I now want to look at the two treatments specifically.
My understanding is that I need to calculate this manually using the initial occupancy, and colonisation and extinction estimates and iterate through each time step using a function, and then use nonparboot to get the CIs. I've modified a function from a similar question which gets me most of the way there (https://groups.google.com/forum/#!topic/unmarked/xXAYH19pLvg), but I can't work out how best to modify it to capture the Treatment-specific and season-specific colonisation and extinction estimates (presumably they also require some for loops?): psi.year<-function(fm){
psi.hat<-plogis(c(sum(coef(fm, type='psi')),coef(fm, type='psi')[1]))
gam.hat<-plogis(c(sum(coef(fm, type='col')),coef(fm, type='col')[1]))
eps.hat<-plogis(c(sum(coef(fm, type='ext')),coef(fm, type='ext')[1]))
psi.mat<-matrix(NA,21,2) #21 'seasons' of data, 2 columns - 2 treatments
psi.mat[1,]<-psi.hat
for(t in 2:21){
psi.mat[t,]<-(psi.mat[t-1,]*(1-eps.hat))+((1-psi.mat[t-1,])*gam.hat)
}
return(c(psi.mat)) #Had to turn it into a vector so parboot would run
}
So, my question is, how should I modify the above function to get treatment and season-specific estimates of Occupancy? Or is there a better approach to achieving the same result that i'm missing (e.g. is it better to just use a stacked approach)?
Thanks in advance,
Billy