I tried to fit my data with a gaussian curve using nls. Because that didn't work, i tried to make an easy example to see what goes wrong:
>x=seq(-4,4,0.1)
>y=2*dnorm(x-0.4,2)+runif( length(x) , min = -0.01, max = 0.01)
>df=data.frame(x,y)
>m <- nls(y ~ k*dnorm(x-mu,sigma), data = df, start = list(k=2,mu=0.4,sigma=2))
Error in nlsModel(formula, mf, start, wts, upper) : singular gradient
matrix at initial parameter estimates
> m <- nls(y ~ k*dnorm(x-mu,sigma), data = df, start == list(k=1.5,mu=0.4,sigma=2))
Error in nlsModel(formula, mf, start, wts, upper) : singular gradient
matrix at initial parameter estimates
Why doesn't this work?