[FLR-list] FLCohort

Laurie lauriekell at googlemail.com
Tue Oct 18 15:38:14 CEST 2011


On 10/18/2011 03:07 PM, ernesto.jardim at jrc.ec.europa.eu wrote:
> On 10/18/2011 02:34 PM, Laurie wrote:
>> On 10/18/2011 01:34 PM, ernesto.jardim at jrc.ec.europa.eu wrote:
>>> On 10/18/2011 01:22 PM, Laurie wrote:
>>>> On 10/18/2011 01:10 PM, Ernesto Jardim wrote:
>>>>>
>>>>>
>>>>> On Tue, Oct 18, 2011 at 1:03 PM, Laurie <lauriekell at googlemail.com 
>>>>> <mailto:lauriekell at googlemail.com>> wrote:
>>>>>
>>>>>     On 10/18/2011 12:50 PM, ernesto.jardim at jrc.ec.europa.eu
>>>>>     <mailto:ernesto.jardim at jrc.ec.europa.eu> wrote:
>>>>>>     On 10/18/2011 12:02 PM, Laurie wrote:
>>>>>>>     On 10/18/2011 11:41 AM, ernesto.jardim at jrc.ec.europa.eu
>>>>>>>     <mailto:ernesto.jardim at jrc.ec.europa.eu> wrote:
>>>>>>>>     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 <http://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
>>>>>>>>
>>>>>>>>
>>>>>>>     But you don´t get what you want.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>     I(m(ple4))[1:10,1:10]
>>>>>>>     An object of class "FLQuant"
>>>>>>>     , , unit = unique, season = all, area = unique
>>>>>>>
>>>>>>>            year
>>>>>>>     quant  1957 1958 1959 1960 1961 1962 1963 1964 1965 1966
>>>>>>>        1947 0.1   NA   NA   NA   NA   NA   NA   NA   NA   NA
>>>>>>>        1948 0.1  0.1  <tel:1948%200.1%20%200.1>    NA   NA   NA   NA   NA   NA   NA   NA
>>>>>>>        1949 0.1  0.1  <tel:1949%200.1%20%200.1>   0.1   NA   NA   NA   NA   NA   NA   NA
>>>>>>>        1950 0.1  0.1  0.1  0.1   NA   NA   NA   NA   NA   NA
>>>>>>>        19510.1  0.1  0.1  0.1  0.1  <tel:0.1%20%200.1%20%200.1%20%200.1%20%200.1>    NA   NA   NA   NA   NA
>>>>>>>        1952 0.1  0.1  0.1  0.1  0.1  0.1   NA   NA   NA   NA
>>>>>>>        1953 0.1  0.1  0.1  0.1  0.1  0.1  0.1   NA   NA   NA
>>>>>>>        1954 0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1   NA   NA
>>>>>>>        1955 0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1   NA
>>>>>>>        1956 0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
>>>>>>>
>>>>>>>     units:  NA
>>>>>>>     >  FLCohort(m(ple4))[1:10,1:10]
>>>>>>>     An object of class "FLCohort"
>>>>>>>     , , unit = unique, season = all, area = unique
>>>>>>>
>>>>>>>          cohort
>>>>>>>     age  1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
>>>>>>>        1   NA   NA   NA   NA   NA   NA   NA   NA   NA  0.1
>>>>>>>        2   NA   NA   NA   NA   NA   NA   NA   NA  0.1  0.1
>>>>>>>        3   NA   NA   NA   NA   NA   NA   NA  0.1  0.1  0.1
>>>>>>>        4   NA   NA   NA   NA   NA   NA  0.1  0.1  0.1  0.1
>>>>>>>        5   NA   NA   NA   NA   NA0.1  0.1  0.1  0.1  0.1  <tel:0.1%20%200.1%20%200.1%20%200.1%20%200.1>
>>>>>>>        6   NA   NA   NA   NA  0.10.1  0.1  0.1  0.1  0.1  <tel:0.1%20%200.1%20%200.1%20%200.1%20%200.1>
>>>>>>>        7   NA   NA   NA  0.1  0.1  0.1  0.1  0.1  0.1  0.1
>>>>>>>        8   NA   NA  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
>>>>>>>        9   NA  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
>>>>>>>
>>>>>>>     laurie
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>     Lost me. What do you want ?
>>>>>>
>>>>>>     EJ
>>>>>>
>>>>>>
>>>>>>
>>>>>     There are three ways to represent the 1st two dims in an FLQuant.
>>>>>
>>>>>     i) age & year
>>>>>     ii) age & cohort
>>>>>     iii) cohort & year
>>>>>
>>>>>     (i) is FLQuant and (ii) is FLCohort; However we do not have
>>>>>     (iii) which is what I need for my tagging model.
>>>>>
>>>>>     I have created an "FLCohortYear" from an FLQuant by adding I()
>>>>>     & O() as coercion methods and validity that only allows 1st
>>>>>     dim to be called cohort.
>>>>>     But then we have two FLCohort objects which might conflict.
>>>>>
>>>>>     Laurie
>>>>>
>>>>>
>>>>>
>>>>> But you can use FLQuant and change the first dimension. You may 
>>>>> need a method to convert i) or ii) into it but shouldn't create 
>>>>> any conflicts. If you really need a new data structure and the 
>>>>> problem only affects tag data, call it FLTag and extend FLQuant.
>>>>>
>>>>> Best
>>>>> EJ
>>>>>
>>>> I would have called in FLCohort but some body got there 1st!
>>>>
>>>> Having 2 versions of FLCohorts with different properties does raise 
>>>> an issue though.
>>>>
>>>> Laurie
>>>
>>> Yes, sure ! But you get what you need computing year=cohort+age, so 
>>> I don't see the need for a new one.
>>>
>>> Best
>>>
>>> EJ
>>
>> Same argument applies to FLQuant! However, the maths is easier in my 
>> case using sweep & plyr if dims are year & cohort
>>
>> Laurie
>
> Fine, but we're not changing FLCohort so that you may use plyr. In 
> that case you should create a new class like you're suggesting and use it.
>
> Best
>
> EJ

I first looked at FLCohort in order to see if it could be modified to 
allow the two cases to be included (i.e. age-cohort & year-cohort), but 
found doing the aperms a bit tricky, hence the daply solution.

I will create an FLYrCls for now.

Laurie


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/flr-list/attachments/20111018/67a42f38/attachment-0001.htm>


More information about the flr-list mailing list