View source: R/make.trapCovs.R
make.trapCovs | R Documentation |
This function takes a sensible "list of lists" format for covariates and converts it to the bizarre and unwiedly oSCR format. This will be internalized at some point but for now we suggest to use this function for convenience.
make.trapCovs(lol)
lol |
A list of lists. |
lol should be a list of lists where lol[[i]] is itself a LIST representing covariate i for each session. Thus lol[[i]][[s]] should be a J (traps) x K (occasions) matrix of covariate i for session s
This is indescribable. But it can be input as the trapCovs argument to the scrFrame.
Andy Royle
library(oSCR)
data(peromyscus)
o<- peromyscus
y<- o$Ycat # Data are categorical "trap of capture"
g<- o$group.mem
table(g)
# here we subset the data to trapping grid 19
y<- y[g==19,]
allna<- apply(is.na(y),1,sum) # Gets rid of individuals not captured here
y<- y[!allna,]
table(o$traps.avail[,19])
traps<- o$trap.locs
K<- ncol(y)
J<- nrow(traps)
# here we create the 3-d array format which is conveneient for a lot
# of analysis in BUGS but also oSCR requires the 3-d array format
y3d<- array(0, dim=c(nrow(y), nrow(traps), ncol(y)) )
for(i in 1:nrow(y)){
tmp<- y[i,]
kid<- (1:K)[tmp<=J]
jid<- tmp[tmp<=J]
y3d[cbind(i,jid,kid)]<- 1
}
# "to" is the trap operation matrix
to<- matrix(1,nrow=121,ncol=K)
colnames(traps)<- c("X","Y")
#
#
# Example of make.trapCovs
#
#
# We have an important covariate which is time of trap check, AM or PM
# we put this into a matrix and treat it as a "trap*time covariate"
# o$am.effect is a vector of length 10 , binary indicator
am<- matrix( o$am.effect, nrow=J,ncol=K,byrow=FALSE)
# Here is an example with two covariates although not meaningful ones
lol <- list(am=list(am),am2=list(am*am))
lol <- make.trapCovs(lol)
scrFrame <- make.scrFrame(
caphist=list(y3d),
indCovs=NULL,
traps=list(data.frame(traps)) ,
trapCovs=lol,
trapOperation=list(to))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.