Diviya Smith wrote on 09/20/2011 01:03:22 PM: > > Hello there, > > I am using NLS for fitting a complex model to some data to estimate a couple > of the missing parameters. The model is - > y ~ (C+((log(1-r))*exp(-A*d)*(-1+r+exp(d*(A-B)))/(r*(-A*d+d*B+log(1-r))))) > where A, B and C are unknown. > > In order to test the model, I generate data by setting values for all > parameters and add some noise (C). > > A <- 20 > B <- 500 > r <- 0.6881 > d <- (1:1000)/1000 > y ~ > (rnorm(d)*0.005)+(((log(1-r))*exp(-A*d)*(-1+r+exp(d*(A-B)))/(r*(-A*d > +d*B+log(1-r))))) > > I use Deoptim package to pick the optimum starting values. The model works > fine in most cases, but every now and again, I get the following error - > Error in numericDeriv(form[[3L]], names(ind), env) : > Missing value or an infinity produced when evaluating the model > > Any suggestions on how I can resolve this? Can you suggest a better way for > picking the starting parameters? > > Thanks, > Diviya
I'm not sure if this is the problem, but if r grows greater than 1, log(1-r) will be undefined, and you'll get an error. You can impose a constraint on r by rewriting your formula in terms of a variable that can take on any real value: R = log(1-r) So, replace log(1-r) in your formula with R, replace (-1 + r) with -exp(R), and replace r with 1 - exp(R): y ~ (C+(R*exp(-A*d)*(-exp(R)+exp(d*(A-B)))/((1 - exp(R))*(-A*d+d*B+R)))) If that doesn't fix the problem, then you are likely getting infinite values as result of large numbers in your exponents. Without example data to work through, I can only speculate. Jean [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.