[R] nls: formula error?

From: H. Paul Benton <hpbenton_at_scripps.edu>
Date: Tue 23 May 2006 - 11:52:12 EST


So thanks for the help,

I have a matrix (AB) which in the first column has my bin numbers so -4 - +4 in 0.1 bin units. Then I have in the second column the frequency from some data. I have plotted them and they look roughly Gaussian. So I want to fit them/ find/optimize "mu", "sigma", and "A".

So I call the nls function :

nls_AB <- nls(x ~ (A/sig*sqrt(2*pi))* exp(-1*((x-mu)^2/(2* sig^2))),data=temp, start= list(A=0.1, mu=0.01, sig=0.5), trace=TRUE) Error in eval(expr, envir, enclos) : numeric 'envir' arg not of length one

Temp looks like this:

       bin x

 [1,] -4.0   0
 [2,] -3.9   0
 [3,] -3.8   0
.........etc

[41,] 0.0 241
[42,] 0.1 229
[43,] 0.2 258
[44,] 0.3 305
[45,] 0.4 370
[46,] 0.5 388

So I don't get my error message. I looked at doing class(fo <- (x ~ (A/sig*sqrt(2*pi))* exp(-1*((x-mu)^2/(2* sig^2))))) terms(fo)

and that seems to work. So if anyone has any ideas I would welcome them.

Cheers,



R-help@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 Received on Tue May 23 11:57:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 23 May 2006 - 18:10:19 EST.

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