[R] Can someone Help in nls() package
Spencer Graves
spencer.graves at pdf.com
Sun Nov 20 08:29:05 CET 2005
When I tried to run your example, I got the following:
Error in func(times[1], y, parms) : object "Cum2" not found
While I couldn't replicate your error, I can tell you that the reason
"print(coef(fit))" gave the error it did was because "nls" refuses to
return anything when it encounters an error.
If it were my problem, I might write a least-squares wrapper and give
it to "optim(..., hessian=T)", as optim will still return an answer when
it seems overparameterized, etc.; in that case, computing the
eigenvalues and vectors of the hessian can help identify the problem.
If "optim" also generated an error like "Missing value or an infinity
produced", I might modify 'f' to print its arguments and output. From
that, I can usually figure out what I want to do about that.
hope this helps.
spencer graves
Raja Jayaraman wrote:
> Hello R-Community,
> we are running aprogram to fit Non-linear differential equations to Aphid
> population Data and to estimate the birth and death parameters,
> here is the code:
>
> dat<-data.frame(Time=c(0:60),Cur=c(5,6.2,59,39,38,44,20.4,19.4,34.2,35.4,38.2,48.2,55.4,113.2,
> 97,112,115,126,136.6,140.6,147.2,151.6,157.8,170,202,210.4,221.2,224.4,248.2,266,
> 277,291.4,392,461.2,470,418,410.8,395.6,365.2,189.4,43.4,33.2,32,29,26,26,25.6,24.6,
> 24,23.4,18.4,17.6,15.8,13.6,10.6,8.4,6.4,5.4,4.2,3.6,2.7))
>
> times<-c(0:60)
> f <- function(t,xx,pars){
> Cur<- xx[1]
> Cum<- xx[2]
> a <- pars[1]
> b <- pars[2]
> dCur <- a*Cur-b*Cur*Cum^2
> dCum <- Cur
> list(c(dCur,dCum))
> }
>
>
> require(nls)
> fit <- nls(Cur ~ lsoda(c(Cur=1,Cum=1), times, f, c(a=a, b=b))[,2],
> data=dat,
> start=list(a=2.5, b=.01),
> trace=T
> )
> print(coef(fit))
>
> It runs the first iterations and shows the output, after the intial
> eveluation it send the following error message:
>
> 92 : 2.50 0.01
> Error in numericDeriv(form[[3]], names(ind), env) :
> Missing value or an infinity produced when evaluating the model
> In addition: There were 50 or more warnings (use warnings() to see the first 50)
>
>>print(coef(fit))
>
> Error in coef(fit) : object "fit" not found
>
> Looking forward to hear soon
> Thanks
> Raj
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list