Random occupancy model using colext? (1-epsilon)=gamma?

108 views
Skip to first unread message

Carl Schwarz

unread,
Jan 20, 2017, 6:52:56 PM1/20/17
to unmarked
It it possible to fit the random occupancy model using colext() (or other function) in unmarked?

This is the model where (1-epsilon)=gamma so that occupancy in season t+1 does not depend on occupancy in the previous season. Some models can be fit using separate occupancy models for each season, but then you can't share information about p across seasons.

Thanks

Carl Schwarz

Jim Baldwin

unread,
Jan 20, 2017, 11:33:21 PM1/20/17
to unma...@googlegroups.com
I'm going to to out on a limb and  say "No."  How complex is the model you envision?  Do you have covariates?  Do you need separate estimates  of occupancy for each season?  The fitting of some function of the logits of the seasonal occupancy probabilities?

Jim


--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim Baldwin

unread,
Jan 20, 2017, 11:45:36 PM1/20/17
to unma...@googlegroups.com
Actually, thinking about it a bit more you could fit such a model just using occu.

Jim

Kery Marc

unread,
Jan 21, 2017, 1:17:02 AM1/21/17
to unma...@googlegroups.com
Dear Jim,

what's your reasoning to come to this conclusion ? Isn't it that when we model each year with a separate parameter for psi, then we make this assumption of (1-eps) = gamma implicitly ?

Best wishes  --- Marc
 

From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Jim Baldwin [jbald...@gmail.com]
Sent: 21 January 2017 05:45
To: unma...@googlegroups.com
Subject: Re: [unmarked] Random occupancy model using colext? (1-epsilon)=gamma?

To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.

Jim Baldwin

unread,
Jan 21, 2017, 1:45:46 AM1/21/17
to unma...@googlegroups.com
Yes.  Each year has a separate parameter for psi (or one could fit some function that relates the psi values among years).  It's as if there's a new random set of sites for each year.  (Offhand I don't know if the AIC values could be directly compared between occu models and colext models.  But there might be a constant that could be determined to add to the occu AIC values to make model comparisons.  It would be convenient if that constant were zero.)

However, I would wonder how one could assume such independence AND the same exact detection probability among years without a lot of previous data.  I understand that pooling data gets one more precise estimates (but only if one can assume rather than just willing to assume that there's a common detection probability).

Jim

Richard Chandler

unread,
Jan 21, 2017, 10:20:28 AM1/21/17
to Unmarked package
Hi everyone,

I think it would be good to have this option with colext so I added it to the to-do list:


Richard
 
Richard Chandler
Assistant Professor
Warnell School of Forestry and Natural Resources
University of Georgia

Carl Schwarz

unread,
Jan 22, 2017, 4:52:34 PM1/22/17
to unmarked
Thanks for everyone' replies...The context for this request is acoustic monitoring for bird calls - the same machines are used over many seasons so detection probabilities may be comparable across seasons. The species is thought to have a very low site fidelity across seasons so a random occupancy model may be sensible....

I was thinking over Jim's idea of using the occu() function and think I see a way to do it. He offered to write some code for this case. He and I will work offline to come up with an example and repost to the group.

Thanks.

Carl

Chris Sutherland

unread,
Jan 22, 2017, 5:03:31 PM1/22/17
to unma...@googlegroups.com
I'm coming to this a little late, but I wondered why a 'stacked' occupancy model isn't the obvious choice here? I.e., where all data are modeled using a single season model with psi ~ year (or any other covariate that sites in a specific year have in common?).

It is likely I missed something along the way so feel free to ignore this 🤐

Chris 

--

Carl Schwarz

unread,
Jan 22, 2017, 7:11:52 PM1/22/17
to unmarked
Yes, that is my current thinking and it seem to work. TO allow time covariates over the entire set of seasons, it is not a simple stacking but we need to split the data into separate sets of sites for each season and put all NA's before and after the season of interest

COnsider a study with 3 seasons and 2 visits/season
The history 101101 is broken into 3 pseudo-histories
     10....
     ..11..
     ....01
 Then to allow a separate psi for each season, you add a site covariate to give
 SiteCov  History
     T1     10....
     T2     ..11..
     T3     ....01
and then fit the model with  psi~SiteCov


On Friday, January 20, 2017 at 3:52:56 PM UTC-8, Carl Schwarz wrote:

Carl Schwarz

unread,
Jan 22, 2017, 10:58:55 PM1/22/17
to unmarked
Here is my sample code to fit a random occupancy model using the occu() function.  The test data is a 3 seasons of 2 visits/season as indicated by the visits vector in the code. The code assumes that a row.name is available for the input history -- it fails if there is no row name, so you should add a simple row.name such as the site id or 1:nsites. 

library(unmarked)

history <-read.csv('test-random.csv',  header=TRUE, as.is=TRUE, row.names=1)
head(history)

# We need to split the data into separate sets of sites for each season
# and put all NA's before and after the season of interest
# COnsider a study with 3 seasons and 2 visits/season
# The history 101101 is broken into 3 pseudo-histories
#     10....
#     ..11..
#     ....01
# Then to allow a separate psi for each season, you add a site covariate to give
#   SiteCov  History
#     T1     10....
#     T2     ..11..
#     T3     ....01
# and then fit the model with  psi~SiteCov


visits <- c(2,2,2)  # 3 seasons with 2 visits per season
start.visit <- cumsum(c(0,visits[-length(visits)]))+1 # when does season start
end.visit   <- cumsum(visits)  # when does season end

rev.history <- NULL # revised history that isolates each season with NA in front and after the season's data
for(i in 1:length(visits)){
   season.history <- cbind(matrix(NA,nrow=nrow(history),ncol=max(0,start.visit[i]-1)),
                           history[, start.visit[i]:end.visit[i]],
                           matrix(NA,nrow=nrow(history),ncol=max(0,end.visit[length(end.visit)]-end.visit[i])))
   row.names(season.history) <- paste("SEAS.", formatC(i, digits=2, flag='0'),'.',row.names(season.history),sep="")
   names(season.history) <- names(history)  # fix up the visit names
   rev.history<- rbind(rev.history,season.history)
}

# create a site covariate that reflects the different seasons for the rev.history
rev.history.site.cov <- data.frame(Season=rep(paste("SEAS.", formatC(1:length(visits), digits=2, flag='0'),sep=""), each=nrow(history)))
library(unmarked)

history <-read.csv('test-random.csv',  header=TRUE, as.is=TRUE, row.names=1)
head(history)

# We need to split the data into separate sets of sites for each season
# and put all NA's before and after the season of interest
# COnsider a study with 3 seasons and 2 visits/season
# The history 101101 is broken into 3 pseudo-histories
#     10....
#     ..11..
#     ....01
# Then to allow a separate psi for each season, you add a site covariate to give
#   SiteCov  History
#     T1     10....
#     T2     ..11..
#     T3     ....01
# and then fit the model with  psi~SiteCov


visits <- c(2,2,2)  # 3 seasons with 2 visits per season
start.visit <- cumsum(c(0,visits[-length(visits)]))+1 # when does season start
end.visit   <- cumsum(visits)  # when does season end

rev.history <- NULL # revised history that isolates each season with NA in front and after the season's data
for(i in 1:length(visits)){
   season.history <- cbind(matrix(NA,nrow=nrow(history),ncol=max(0,start.visit[i]-1)),
                           history[, start.visit[i]:end.visit[i]],
                           matrix(NA,nrow=nrow(history),ncol=max(0,end.visit[length(end.visit)]-end.visit[i])))
   row.names(season.history) <- paste("SEAS.", formatC(i, digits=2, flag='0'),'.',row.names(season.history),sep="")
   names(season.history) <- names(history)  # fix up the visit names
   rev.history<- rbind(rev.history,season.history)
}

# create a site covariate that reflects the different seasons for the rev.history
rev.history.site.cov <- data.frame(Season=rep(paste("SEAS.", formatC(1:length(visits), digits=2, flag='0'),sep=""), each=nrow(history)))
rev.history.site.cov$Time <- rep(1:length(visits), each=nrow(history))


Seasons <- matrix( rep(c("T1","T2","T3"),each=2), nrow=nrow(rev.history), ncol=ncol(rev.history), byrow=TRUE)


occ.UMF <- unmarkedFrameOccu(
  y = rev.history,
  obsCovs=list(Season=Seasons),
  siteCovs=rev.history.site.cov)  
occ.UMF
summary(occ.UMF)
plot(occ.UMF, panels=1)


# Now to fit a model for random occupancy with a separate psi for each season
mod <- occu( ~1 ~Season, data=occ.UMF)

mod 
    
psi.pred.cov <- data.frame(Season=unique(rev.history.site.cov$Season))
psi.pred     <- predict(mod, type="state", newdata=psi.pred.cov)
cbind(psi.pred.cov, psi.pred)

p.pred.cov <- data.frame(one=1)
p.pred <- predict(mod, type="det", newdata=p.pred.cov)
cbind(p.pred.cov, p.pred)


Seasons <- matrix( rep(c("T1","T2","T3"),each=2), nrow=nrow(rev.history), ncol=ncol(rev.history), byrow=TRUE)


occ.UMF <- unmarkedFrameOccu(
  y = rev.history,
  obsCovs=list(Season=Seasons),
  siteCovs=rev.history.site.cov)  
occ.UMF
summary(occ.UMF)
plot(occ.UMF, panels=1)


# Now to fit a model for random occupancy with a separate psi for each season but a common p over all season.
mod <- occu( ~1 ~Season, data=occ.UMF)

mod 
    
psi.pred.cov <- data.frame(Season=unique(rev.history.site.cov$Season))
psi.pred     <- predict(mod, type="state", newdata=psi.pred.cov)
cbind(psi.pred.cov, psi.pred)

p.pred.cov <- data.frame(one=1)
p.pred <- predict(mod, type="det", newdata=p.pred.cov)
cbind(p.pred.cov, p.pred)

# Now to fit a model for random occupancy with a time trend across seasons but a common p across all seasons
mod2 <- occu( ~1 ~Time, data=occ.UMF)

mod2 
    
psi.pred.cov <- data.frame(Time=1:length(visits))
psi.pred     <- predict(mod2, type="state", newdata=psi.pred.cov)
cbind(psi.pred.cov, psi.pred)

p.pred.cov <- data.frame(one=1)
p.pred <- predict(mod2, type="det", newdata=p.pred.cov)
cbind(p.pred.cov, p.pred)


# Now to fit a model for random occupancy with a time trend across seasons and a separate p for each season.
mod3 <- occu( ~Season ~Time, data=occ.UMF)

mod3 
    
psi.pred.cov <- data.frame(Time=1:length(visits))
psi.pred     <- predict(mod3, type="state", newdata=psi.pred.cov)
cbind(psi.pred.cov, psi.pred)

p.pred.cov <- data.frame(Season=c("T1","T2","T3"))
p.pred <- predict(mod3, type="det", newdata=p.pred.cov)
cbind(p.pred.cov, p.pred)




On Friday, January 20, 2017 at 3:52:56 PM UTC-8, Carl Schwarz wrote:

Carl Schwarz

unread,
Jan 22, 2017, 11:01:03 PM1/22/17
to unmarked
Doh... just noticed that the code has the first section repeated twice... too late on a Sunday evening ....  Carl


On Friday, January 20, 2017 at 3:52:56 PM UTC-8, Carl Schwarz wrote:
Reply all
Reply to author
Forward
0 new messages