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@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.