[FLR-list] FLCohort

ernesto.jardim at jrc.ec.europa.eu ernesto.jardim at jrc.ec.europa.eu
Tue Oct 18 11:41:23 CEST 2011


On 10/18/2011 11:26 AM, Laurie wrote:
> 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

You may change the age in FLCohort

library(FLCore)
data(ple4)
flc <- FLCohort(catch.n(ple4))
quant(flc) <- "year"

why not using year in the first dimension ? it should work out of the box.

EJ




More information about the flr-list mailing list