0

I'm trying to fit an exponential model using nls, but I don't know how to select the starting values for the parameters. I know this question has been answered multiple times, but I spent some days surfing on forums and I couldn't find the solution for my particular case. Here they showed the very same problem, but the solution of liniarizing the data taking logs doesn't work wor me, because the fit of the transformed data is not linear. I would really appreciate a piece of advice here.

Here an example of my kind of data:

mes1 <- data.frame(CO2=c(354.68, 362.43, 374.12, 380.45, 385.92, 394.19, 400.2, 405.85, 407.81, 410.71, 414.77), time=c(1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 101))

CO2i <- mes1$CO2[1]
Timei <- mes1$time[1]
exp_eq <- function(time,B,CO2i,a,Timei){B + (CO2i- B)^(-a*(Timei-time))}

I know other kind of equations might work better, but I must use this one since is the reference in the field. The only thing I need is estimate the initial values for a and B

m <- nls(CO2 ~ exp_eq(time,B,CO2i,a,Timei)), data = mes1, start = list(B = 1, a = 1))

Many thanks in advance for your support.

jbarba
  • 1
  • I found many directly relevant answers by [searching](https://stats.stackexchange.com/search?tab=votes&q=nls%20start*%20-self%20%20exp%20is%3aanswer) and going through the top few hits. – whuber Feb 14 '20 at 16:23
  • Many thanks @whuber I've readed carefully the different posts on this topic, but probably because I'm not profficient in R (and probably in statistics) I couldn't find a solution for my data. From this post [link] (https://stats.stackexchange.com/questions/160552/why-is-nls-giving-me-singular-gradient-matrix-at-initial-parameter-estimates) I cannot estimate the initial parameters because one of them appears in two different parts of the model (and also data trend to an assymptot); I found multiple suggestions, but I couldn't make them work in my case. Many thanks in advance for your support. – jbarba Feb 17 '20 at 17:08
  • Additionally, my data tends to a limit, so I cannot estimate C.o as min("input")*0.5, as in the example – jbarba Feb 17 '20 at 17:22
  • Sure you can--it is, after all, just an *estimate* to get things started. But you need to assign the estimate to the correct variable: as time increases, the function approaches $B,$ not $C_0,$ in the limit. At the initial time, the function's value is$C_0.$ It's usually a good idea to graph your data and graph the function associated with your initial estimate to make sure they are reasonably close. – whuber Feb 17 '20 at 17:32
  • Thanks for your quick reply. I see that when time increases, the function approaches B, and at initial time, the function is CO2i (constant), but I still don't know how to linearize the data for estimating initial values for B and a. Sorry, I feel so dumb. I applied logs at both sides, but I guess B hinders the proper liniarization of the data – jbarba Feb 17 '20 at 17:57
  • Well, $a$ is the rate constant. Various ways to estimate it have been developed in different disciplines. A common one is to estimate the time the curve reaches 95% of its ultimate range and divide that by 3: this estimates $1/a.$ Another common one is to estimate the time the curve reaches 50% of its range (the "half life") and divide that by $\log(1/2)\approx 0.7:$ again this estimates $1/a.$ The main point, though, is by a little bit of trial and error in graphing your guesses you will quickly find some that already fit the data decently; the computer merely "polishes" that eyeball guess. – whuber Feb 17 '20 at 18:03
  • The range of your data is $60.$ Although that's likely not the full range, it's getting there, so divide it by two. The data have reached the midpoint of their range around time $40$ or so, so estimate $a \approx 1/40.$ Using the smallest $y$ value of $355$ to estimate $C_0$ and the largest $y$ value of $415$ to estimate $B,$ you will get a serviceable initial fit. – whuber Feb 17 '20 at 18:09
  • Again, many, many thanks. Even if I tried to put your initial values, I still get "Missing value or an infinity produced when evaluating the model". m.0 – jbarba Feb 17 '20 at 18:41
  • Hi @whuber. Please, don't waist an extra second on that. I found a mistake in my equation, and now, it works! There is a section I wrote (CO2i- B)^(-a*(Timei-time)) but it should be (CO2i- B)*exp(-a*(Timei-time)) Many tnaks for your time! – jbarba Feb 17 '20 at 19:53

0 Answers0