[FLR-list] FLCohort

Laurie lauriekell at googlemail.com
Tue Oct 18 11:26:52 CEST 2011


I am working on tagging models, where tags are released for a number of  
years and then recaptured in subsequent years. This allows M & Z to be 
estimated along a cohort.

The data are in the form of number of fish tagged and recovered each 
year of a cohort. This means that you can´t use FLCohort which has age & 
cohort as dims 1&2.

However, if you use the 1st dim for cohort then you can model this with 
an FLQuant, i.e.

library(plyr)

setGeneric("I",              function(object,...)
     standardGeneric("I"))
setGeneric('O',              function(object, ...)
     standardGeneric("O"))

setMethod('I', signature(object='FLQuant'),
   function(object,...){
     dmns <-dimnames(object)
     dmns[[1]] 
<-ac((dims(object)$minyear-dims(object)$max):(dims(object)$maxyear- 
dims(object)$min))
     names(dmns)[1]<-"quant"
     flc <-FLQuant(NA,dimnames=dmns)

     t. <-as.data.frame(object)
     t.$cohort <-t.$year-t.$age
     flc[] 
<-daply(t.,c("cohort","year","unit","season","area","iter"),function(x) 
sum(x$data))

     return(flc)})

setMethod('O', signature(object='FLQuant'),
   function(object,...){
     dmns <-dimnames(object)
     dmns[[1]] 
<-ac((dims(object)$maxyear-dims(object)$max):(dims(object)$minyear-dims(object)$min))
     names(dmns)[1]<-"age"
     flc <-FLQuant(NA,dimnames=dmns)

     t. <-as.data.frame(object)
     t.$age <-t.$year-t.$quant
     t. <-t.[!is.na(t.$data),]
     flc[] 
<-daply(t.,c("age","year","unit","season","area","iter"),function(x) 
sum(x$data))

     return(flc)})

data(ple4)

m1=I(m(ple4))
m2=O(m1)

It is probably best to derive a new class for this object just to break 
VPAs etc. But what to call it? Also how does it relate to FLCohort.
Laurie


More information about the flr-list mailing list