[FLR-list] Adding a segregAR1 in FLSR

Mark Payne mpa at aqua.dtu.dk
Mon Oct 14 14:08:20 CEST 2013


Brilliant. Cheers. Here it is: does anyone want to add it to SRmodels.r?

Mark

#SegregAR1
segregAR1 <- function(){
    logl <- function(a, b, rho, rec, ssb){
       loglAR1(log(rec), FLQuant(log(ifelse(c(ssb)<=b,a*c(ssb),a*b)),dimnames=dimnames(ssb)),rho=rho)}

    model <- rec ~ FLQuant(ifelse(c(ssb)<=b,a*c(ssb),a*b),dimnames=dimnames(ssb))

    initial <- structure(function(rec, ssb){
      return(FLPar(a=median(c(rec/ssb),na.rm=TRUE), b=median(c(ssb),na.rm=TRUE),rho=0))},
      lower=c( 0, 0,-1),
      upper=c(Inf, Inf,1))

return(list(logl=logl, model=model, initial=initial))
} # }}}




________________________________
Fra: flr-list-bounces at r-forge.wu-wien.ac.at [flr-list-bounces at r-forge.wu-wien.ac.at] på vegne af Laurie [lauriekell at gmail.com]
Sendt: 14. oktober 2013 13:44
Til: flr-list at r-forge.wu-wien.ac.at
Emne: Re: [FLR-list] Adding a segregAR1 in FLSR

You need to add the initial params and bounds also.

bevholtAR1 <- function()
  {
  ## log likelihood, assuming normal log.
  logl <- function(a, b, rho, rec, ssb)
      loglAR1(log(rec), log(a*ssb/(b+ssb)), rho=rho)

  ## initial parameter values
  initial <- structure(function(rec, ssb) {
      a <- max(quantile(c(rec), 0.75, na.rm = TRUE))
    b <- max(quantile(c(rec)/c(ssb), 0.9, na.rm = TRUE))
    return(FLPar(a = a, b = a/b, rho=0))
    },

  ## bounds
  lower=c(rep(10e-8, 2), -1),
    upper=c(rep(Inf, 2), 1))

  ## model to be fitted
  model  <- rec~a*ssb/(b+ssb)

    return(list(logl=logl, model=model, initial=initial))
} # }}}


i.e.
     initial <- structure(function(rec, ssb){
      return(FLPar(a=median(c(rec/ssb),na.rm=TRUE), b=median(c(ssb),na.rm=TRUE),rho=0.0))},
      lower=c( 0, 0,-1),
      upper=c(Inf,Inf,1))


On 14/10/13 08:49, Mark Payne wrote:
Hi,

I'm trying to define a segregAR1 FLSR model, as it seems to be missing from the SRmodels available in FLCore. I have modified the segreg model as follows, based on the bevholtAR1 and rickerAR1 models:

#SegregAR1
segregAR1 <- function(){
    logl <- function(a, b, rho, rec, ssb){
       loglAR1(log(rec), FLQuant(log(ifelse(c(ssb)<=b,a*c(ssb),a*b)),dimnames=dimnames(ssb)),rho=rho)}

    model <- rec ~ FLQuant(ifelse(c(ssb)<=b,a*c(ssb),a*b),dimnames=dimnames(ssb))

    initial <- structure(function(rec, ssb){
      return(FLPar(a=median(c(rec/ssb),na.rm=TRUE), b=median(c(ssb),na.rm=TRUE)))},
      lower=rep( 0, 0),
      upper=rep(Inf, 2))

return(list(logl=logl, model=model, initial=initial))
} # }}}


Basically, I've justed added a rho parameter to the likelihood which should, as I understand it, be sufficient to give me what I want. However, it doesn't seem to work when I go to fit it:
> model(base.dat) <- "segregAR1"
> res <- fmle(base.dat)
  Nelder-Mead direct search function minimizer
Error in .local(obs, hat, ...) :
  argument "rho" is missing, with no default
>

Any ideas what I've done wrong?

Mark







________________________________
Fra: flr-list-bounces at r-forge.wu-wien.ac.at<mailto:flr-list-bounces at r-forge.wu-wien.ac.at> [flr-list-bounces at r-forge.wu-wien.ac.at<mailto:flr-list-bounces at r-forge.wu-wien.ac.at>] på vegne af Luis Ridao [luridao at gmail.com<mailto:luridao at gmail.com>]
Sendt: 4. oktober 2013 16:08
Til: flr-list at flr-project.org<mailto:flr-list at flr-project.org>
Emne: [FLR-list] FLBRP<2 sorce code

FLR help,

trying to get the source code for FLBRP version<2 (e.g. FLBRP_1.4-1)
but can't find it anywhere.

anyone with an older source code version of the package around?

best,
Luis





_______________________________________________
flr-list mailing list
flr-list at flr-project.org<mailto:flr-list at flr-project.org>
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/flr-list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/flr-list/attachments/20131014/507d241d/attachment-0003.html>


More information about the flr-list mailing list