[R] linear gradient in nls

Douglas Bates bates at stat.wisc.edu
Fri Sep 29 22:09:29 CEST 2006


On 9/29/06, H. Paul Benton <hpbenton at scripps.edu> wrote:
> Hello,
>
>
>
>             I hope this doesn't turn into a statistics question but here I
> go. I am using the nls function with a Gaussian distribution, see coding
> below. When I run the nls I get an error back saying that I have a linear
> gradient. I then, of course am unable to do anything else. The data that I
> am using are intensity values from some mass spectrometry data. Is there
> something I can do to stop the linear gradient, and I dare to ask why am I
> getting a linear gradient. I apologies if I haven't supplied enough
> information or I have made some mistake in my coding. The coding below works
> on some of the data but not all.
>
>
>
>             Thank you for your time,
>
>
>
>             Paul Benton
>
>
>
> brseq <- seq(-4.0, 4.0, by=0.1)
>
> AB<- A[,1]/A[,2]
>
> lgAB<-log(AB)
>
> freq_AB <-hist(lgAB, type="o", breaks=brseq, plot=F
>
> freq.tab <- as.data.frame(cbind(brseq, freq_AB$counts)
>
> class(fo <- (x ~ (A/(sig*sqrt(2*pi)))* exp(-1*((bin-mu)^2/(2* sig^2)))))
>
> nls.AB <- nls(fo,data=freq.tab, start= list(A=0.1*len, mu=0.01, sig=0.5),
> trace=TRUE)

I think you mean "singular gradient" not "linear gradient".  This
generally indicates that there is not enough information in the data
to estimate all the parameters that you are trying to estimate.  I see
that you have set trace = TRUE, which is a good start.  Take a look at
the progress of the parameter estimates during the iterations and look
at your data plots to see if the estimates appear to be sensible.



More information about the R-help mailing list