-2

I want to analyse a logarithmic growth curve in more detail. Especially I would like to kow the time point when the slope becomes >0 (which is the starting point of growth after a lag phase). Therefore I fitted a logarithmic function to my growth data with the grofit package of R. I got values for the three parameters (lambda, mu, maximal assymptote). Now I thought, I could use the first derivative of the logarithmic growth function to put mu=0 (the slope of any time point during growth) and this way solve the equation for the time (x). I'm not sure if this is possible, since the mu=0 will be correct for a longer timespan at the beginning of the curve (and no unique timepoint). But maybe I could approximate to that point by putting mu=0.01. This should be more specific. Anyway I used the Deriv package to find the first derivative of my logarithmic function:

Deriv(a/(1+exp(((4*b)/a)*(c-x)+2)), "x")

where a=assymptote, b=maximal slope, c=lambda.

As a result I got:

{.e2 <- exp(2 + 4 * (b * (c - x)/a))

4 * (.e2 * b/(.e2 + 1)^2)}

Or in normal writing:

f'(x)=(4*exp(2+((4b(c-x))/a))*b)/((exp(2+((4b(c-x))/a))+1)^2)

Now I would like to solve this function for x with f'(x)=0.01. Can anyone tell me, how best to do it?

Also, do you have comments on my way of thinking or the R functions I used?

Thank you. Anne

Anne
  • 241
  • 1
  • 3
  • 9
  • you mean you want to find `a,b,c` ??? – Mateusz1981 Jan 12 '17 at 13:01
  • Sorry, for being unclear. I know a,b and c for the different treatments I used. They are constants, but change for every replicate. I would like to know x, based on the different a,b,c values. – Anne Jan 12 '17 at 17:24

3 Answers3

1

Using a root solving function is more appropriate than using an optimization function. I'll give an example with two packages.

It would also be a good idea to plot the function for a range of values. Like this:

curve(fn,-.1,.1)

You can see that using the base R function uniroot will present problems since it needs function values at the endpoints of the interval to be of opposite sign.

Using package nleqslv like this

library(nleqslv)
nleqslv(1,fn)

gives

$x
[1] 0.003388598

$fvec
[1] 8.293101e-10

$termcd
[1] 1

$message
[1] "Function criterion near zero"

<more info> ......

Using function fsolve from package pracma

library(pracma)
fsolve(fn,1)

gives

$x
[1] 0.003388585

$fval
[1] 3.136539e-10

The solutions given by both packages are very close to each other.

Bhas
  • 1,844
  • 1
  • 11
  • 9
0

Might not be the best approach but you can use the optim function to find the solution. Check the code below, I am basically trying to find the value of x which minimizes abs(f(x) - 0.01)

There starting seed value for x may be important, the optim function might not converge for some seeds.

fn <- function(x){
    a <- 1
    b<- 1
    c <- 1

return( abs((4*exp(2+((4*b*(c-x))/a))*b)/ ((exp(2+((4*b*(c-x))/a))+1)^2)  - 0.01) )
}

x <- optim(10,fn)
x$par
ab90hi
  • 435
  • 1
  • 4
  • 11
0

Thank you very much for your efforts. Unfortunately, none of the above solutions worked for me :-( I figured the problem out the old fashioned way (pencil + paper + mathematics book). Have a good day Anne

Anne
  • 241
  • 1
  • 3
  • 9