I have some issue using nls()
to estimate parameters. I have a following set of functions to explain some data in hand:
funk1 <- function(a,x) { x^2*exp(-(l*(1-exp(-r*a))/r)) }
funk2 <- function(x) { sapply(x, function (s)
{ integrate(funk1, lower = 0, upper = s, x=s)$value }) }
I am trying to fit funk2
to y
:
y <- sort(runif(100, 0, 10^8))
When I use nls()
:
nls(y ~ funk2(z1$days.post.bmt), data= z1, start=list(l=0.02, r=0.002), trace=T)
it shows me following error:
Error in f(x, ...) : object 'l' not found
Isn't the whole point of nls()
to substitute different values for parameters l
and r
from parameter space to fit the function by minimizing SSR and give the parameter estimates? why it needs value of l
for it to work? I am definitely missing something big here. Please help!
Thanks in advance!