[R] Population growthrate with Euler-Lotka

Mark Christjani m_christjani at gmx.de
Mon Jun 30 15:35:46 CEST 2014


   Thank you Simon and David for your suggestions. They were most helpful. The
   Skript is now working as it was originally planed.

   Greetings
   Mark

   Gesendet: Montag, 30. Juni 2014 um 13:06 Uhr
   Von: "Simon Blomberg" <s.blomberg1 at uq.edu.au>
   An: "Mark Christjani" <m_christjani at gmx.de>
   Cc: "r-help at r-project.org" <r-help at r-project.org>
   Betreff: Re: Aw: Re: [R] Population growthrate with Euler-Lotka
   Hmm. Try setting extendInt="yes" in the call to uniroot. You should also
   look at the help page for uniroot. help(uniroot) May give you a clue. It's
   difficult for me to debug code on my iphone. Well, more difficult than
   usual.

   Best,

   Simon.
   Sent from my iPhone
   On 30 Jun 2014, at 8:53 pm, "Mark Christjani" <[1]m_christjani at gmx.de>
   wrote:

   Thank you, Simon, for your input.

   Data import works fine now, but the final equation still won`t work.

   Console reads now:

   > setwd("c:/Mark")
   >
   > table <- read.table("r-TCO-Scene-Kontrolle.csv", header=TRUE, sep=";")
   >
   > table
       x  lx  mx
   1   1 1.0 0.0
   2   2 1.0 0.0
   3   3 1.0 0.0
   4   4 1.0 0.0
   5   5 1.0 0.0
   6   6 1.0 0.0
   7   7 1.0 0.0
   8   8 1.0 0.0
   9   9 1.0 0.0
   10 10 1.0 0.0
   11 11 0.2 3.5
   >
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   >
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
     f() values at end points not of opposite sign
   >
   > res$root
   Error: object 'res' not found

   Any idea on this "Error in uniroot(f = eulerlotka, interval = r.range, tol =
   1e-08) :
     f() values at end points not of opposite sign"-matter?

   Kind regards,
   Mark



   Gesendet: Montag, 30. Juni 2014 um 12:41 Uhr
   Von: "Simon Blomberg" <[2]s.blomberg1 at uq.edu.au>
   An: "Mark Christjani" <[3]m_christjani at gmx.de>
   Cc: "[4]r-help at r-project.org" <[5]r-help at r-project.org>
   Betreff: Re: [R] Population growthrate with Euler-Lotka
   Your script is failing at the first hurdle because you data are not being
   imported properly. You should include
   header=TRUE. sep=";"
   In the call to read.table.
   Cheers.
   Simon.
   Sent from my iPhone
   Sent from my iPhone
   > On 30 Jun 2014, at 7:10 pm, "Mark Christjani" <[6]m_christjani at gmx.de>
   wrote:
   >
   >
   > Hi everybody,
   >
   >  I`m  Mark  and I do my PhD in biology. I try using R to calculate a
   population
   > growth rate of animals grown on different types of food. Our workgroup has
   a
   > R-skript to do so, but sadly nobody, who knows how this works. I`ve never
   > used R before, but got some stuff figured out myself. The skript goes:
   >
   > setwd("c:/Mark")
   > table <- read.table("r-TCO-Scene-Kontrolle.csv")
   > table
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   > res$root
   >
   > I understood that the first 3 lines are simply to load my data and show it
   > in the workspace console. The next 4 lines define variables of my .csv
   table
   >  for  R.  Thus far, everything works fine. Now comes the Euler-Lotka
   equation,
   > but somehow, this does not seem to work out as supposed. I tried to find a
   > solution on the internet, but I think this formula is somewhat special so
   I
   > could not find a suitible solution for my special problem. The console
   says:
   >
   >
   >> setwd("c:/Mark")
   >>
   >> table <- read.table("r-TCO-Scene-Kontrolle.csv")
   >>
   >> table
   > V1
   > 1 x;lx;mx
   > 2 1;1;0
   > 3 2;1;0
   > 4 3;1;0
   > 5 4;1;0
   > 6 5;1;0
   > 7 6;1;0
   > 8 7;1;0
   > 9 8;1;0
   > 10 9;1;0
   > 11 10;1;0
   > 12 11;0.2;3.5
   >>
   >> x <- c(table$x)
   >> L <- c(table$lx)
   >> m <- c(table$mx)
   >> r.range<- c(0, 5)
   >>
   >> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   >> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   > Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
   > f() values at end points not of opposite sign
   >>
   >> res$root
   >
   > Does anybody have an idea how to get this running?
   >
   > Thanks in advance
   >
   > Kind regards
   > Mark
   > ______________________________________________
   > [7]R-help at r-project.org mailing list
   > [8]https://stat.ethz.ch/mailman/listinfo/r-help
   > PLEASE do read the posting guide
   [9]http://www.R-project.org/posting-guide.html
   > and provide commented, minimal, self-contained, reproducible code.

References

   1. file://localhost/tmp/m_christjani@gmx.de
   2. file://localhost/tmp/s.blomberg1@uq.edu.au
   3. file://localhost/tmp/m_christjani@gmx.de
   4. file://localhost/tmp/r-help@r-project.org
   5. file://localhost/tmp/r-help@r-project.org
   6. file://localhost/tmp/m_christjani@gmx.de
   7. file://localhost/tmp/R-help@r-project.org
   8. https://stat.ethz.ch/mailman/listinfo/r-help
   9. http://www.R-project.org/posting-guide.html


More information about the R-help mailing list