[R] Urgent: conditional formula for nls

From: Andrew Coop <andrew.e.coop_at_gmail.com>
Date: Sun, 01 May 2011 10:52:52 -0600


I have data vectors x and y both with 179 observations. I'm trying to fit a nonlinear model with five parameters using nls. The formula is only defined within a range of x-values, it should be zero otherwise, thus my attempted use of ifelse:

> df<-data.frame(x,y)
> nlsfit<-nls(y~ifelse(x>m&x<m+abs(s),abs(a)*d*abs(s)*exp(-(1/2)*(g+d*log((x-m)/(-x+m+abs(s)))^2))/(sqrt(2*pi)*(x-m)*(-x+m+abs(s))),0),data=df,start=list(a=0.37,g=0,d=1,m=0.42,s=0.24))
Error in nlsModel(formula, mf, start, wts) :   singular gradient matrix at initial parameter estimates In addition: Warning messages:

1: In log((x - m)/(-x + m + abs(s))) : NaNs produced
2: In log((x - m)/(-x + m + abs(s))) : NaNs produced
3: In log((x - m)/(-x + m + abs(s))) : NaNs produced
4: In log((x - m)/(-x + m + abs(s))) : NaNs produced
5: In log((x - m)/(-x + m + abs(s))) : NaNs produced
6: In log((x - m)/(-x + m + abs(s))) : NaNs produced
7: In log((x - m)/(-x + m + abs(s))) : NaNs produced

What am I doing wrong?

Thanks,
Andy



R-help_at_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. Received on Thu 05 May 2011 - 06:25:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive