<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <font face="Courier New, Courier, monospace">Dear Iago,<br>
      <br>
      Thank you for updating this functionality. The fit does indeed
      converge now.<br>
      <br>
      This covariate was indeed arbitrary, so I have now provided an
      example below where the covariate is constructed based on the
      residuals of the ricker() fit. So, the rickerCa() should now make
      a significant improvement over the fit of the ricker(), but this
      is not clear by just looking at AIC.<br>
      <br>
      I'm also wondering where this model is described? I have come
      across another version of an adapted Ricker where the covariate
      term is exp(c*covar) rather than (1-c*covar). As is, the fitted </font><font
      face="Courier New, Courier, monospace"><font face="Courier New,
        Courier, monospace">rickerCa produces NAs. <br>
        <br>
        I've tried this alternate version and the fit looks quite good
        (as well as a substantially lower AIC). <br>
        <br>
        Anyway, thanks for fixing this so promptly. <br>
        <br>
        Cheers,<br>
        Marc<br>
        <br>
        p.s. </font></font><font face="Courier New, Courier, monospace"><font
        face="Courier New, Courier, monospace"><font face="Courier New,
          Courier, monospace"><font face="Courier New, Courier,
            monospace">Perhaps you are now updating the documentation
            for ?SRModels - At the moment I am not able to access its
            help page in the new FLCore version.</font></font><br>
        <br>
        ###<br>
      </font></font><br>
    <font face="Courier New, Courier, monospace"><font face="Courier
        New, Courier, monospace"><font face="Courier New, Courier,
          monospace">library(FLCore) # FLCore_2.6.0.20160401<br>
          data("ple4")<br>
          <br>
          <br>
          <br>
          # fit basic ricker
          --------------------------------------------------------<br>
          ple4SR <- as.FLSR(ple4) <br>
          model(ple4SR) <- "ricker"<br>
          ple4SR <- fmle(ple4SR)<br>
          summary(ple4SR)<br>
          plot(ple4SR)<br>
          <br>
          <br>
          # create environmental covariate with residuals
          ---------------------------<br>
          set.seed(1)<br>
          env <- c(2 * residuals(ple4SR) +
          rnorm(dims(ple4SR@ssb)$year, 0, 1))<br>
          env<br>
          plot(c(env), c(residuals(ple4SR)))<br>
          plot(c(env), t="l")<br>
          <br>
          <br>
          # make new SR obj with covariate
          ------------------------------------------<br>
          ple4SR2 <- as.FLSR(ple4) <br>
          covar(ple4SR2) <- FLQuants(covar=FLQuant(env,
          dimnames=dimnames(ssb(ple4SR2))))<br>
          <br>
          <br>
          # fit rickerCa<br>
          model(ple4SR2) <- rickerCa<br>
          ple4SR2 <- fmle(ple4SR2)<br>
          plot(ple4SR2)<br>
          params(ple4SR2)<br>
          plot(c(covar(ple4SR2)$covar), c(residuals(ple4SR2)))<br>
           c(residuals(ple4SR2)) # produces NAs<br>
          <br>
          <br>
          <br>
          # Compare AIC
          -------------------------------------------------------------<br>
          AIC(ple4SR)<br>
          AIC(ple4SR2)<br>
          <br>
          <br>
          <br>
          # alt model (covariate term is exp(c*covar), initial=0)
          ---------------------------------------------------------------<br>
          <br>
          # compare nls<br>
          START <- list(a=params(ple4SR)["a"], b=params(ple4SR)["b"],
          c=0)<br>
          R <- c(ple4SR2@rec)<br>
          S <- c(ple4SR2@ssb)<br>
          covar <- c(covar(ple4SR2)$covar)<br>
          fitnls <- nls(log(R) ~ log(a) + log(S) - b*S + c*covar,
          start=START)<br>
          summary(fitnls)<br>
          plot(log(R), predict(fitnls)); abline(0,1)<br>
          plot(S, resid(fitnls)); abline(h=0)<br>
          plot(covar, resid(fitnls)); abline(h=0)<br>
          <br>
          <br>
          rickerCa.alt <- function () <br>
          {<br>
              logl <- function(a, b, c, rec, ssb, covar)
          loglAR1(log(rec), <br>
                  log(a * ssb * exp(-b * ssb) * exp(c*covar)))<br>
              initial <- structure(function(rec, ssb) {<br>
                  res <- coefficients(lm(c(log(rec/ssb)) ~ c(ssb)))<br>
                  return(FLPar(a = max(exp(res[1])), b = -max(res[2]), <br>
                      c = 0))<br>
              }, lower = rep(-Inf, 3), upper = rep(Inf, 3))<br>
              model <- rec ~ a * ssb * exp(-b * ssb) * exp(c*covar)<br>
              return(list(logl = logl, model = model, initial =
          initial))<br>
          }<br>
          <br>
          ple4SR3 <- as.FLSR(ple4) <br>
          covar(ple4SR3) <- FLQuants(covar=FLQuant(env,
          dimnames=dimnames(ssb(ple4SR3))))<br>
          model(ple4SR3) <- rickerCa.alt<br>
          ple4SR3 <- fmle(ple4SR3,
          start=as.list(coefficients(fitnls)) )<br>
          plot(ple4SR3)<br>
          params(ple4SR3)<br>
          coefficients(fitnls)<br>
          <br>
          AIC(ple4SR)<br>
          AIC(ple4SR2)<br>
          AIC(ple4SR3)<br>
        </font><br>
        <br>
        <br>
      </font></font><br>
    <pre class="moz-signature" cols="72">Achtung: Das Thünen-Institut hat die Domain gewechselt. Bitte ändern Sie meine Mailadresse in Ihrem Adressbuch!
Notice: Thünen Institute has changed its domain. Please change my email address in your address book!

Dr. Marc Taylor
Marine Lebende Resourcen / Marine Living Resources
Thünen-Institut für Seefischerei / Thünen Institute of Sea Fisheries
Palmaille 9
22767 Hamburg, Germany

Tel:  +49 40 38905-143 
Mail: <a class="moz-txt-link-abbreviated" href="mailto:marc.taylor@thuenen.de">marc.taylor@thuenen.de</a>
Web:  <a class="moz-txt-link-abbreviated" href="http://www.ti.bund.de">www.ti.bund.de</a></pre>
    <div class="moz-cite-prefix">On 4/7/2016 4:46 PM, Iago MOSQUEIRA
      (JRC) wrote:<br>
    </div>
    <blockquote cite="mid:570672B0.5060006@jrc.ec.europa.eu" type="cite"><br>
      library(FLCore)
      <br>
      <br>
      data("ple4")
      <br>
      <br>
      ple4SR <- as.FLSR(ple4)
      <br>
      <br>
      env1 <- c(-0.81, -1.73, -0.09, 0.42, -1.01, -1.06, -0.79,
      -0.42, -0.74, -0.3, 0.25, 0.09, -0.18, -0.29, 0.13, 0.09, 0.48,
      0.33, 0.41, 0.4, -0.21, -0.64, -0.97, -0.02, -0.19, 0.28, -0.03,
      -0.19, -0.47, -0.97, -0.88, 0.23, 0.82, 0.92, 0.17, 0.67, -0.07,
      0.32, 0.9, -0.64, 0.97, 0.54, 1.18, 0.67, 0.44, 1.29, 1.54, 1.22,
      0.47, 1.04, 1.31, 1.06)
      <br>
      <br>
      covar(ple4SR) <- FLQuants(covar=FLQuant(env1,
      dimnames=dimnames(ssb(ple4SR))))
      <br>
      <br>
      model(ple4SR) <- rickerCa
      <br>
      <br>
      ple4SR <- fmle(ple4SR)
      <br>
      <br>
      plot(ple4SR)
    </blockquote>
    <br>
  </body>
</html>