[R] Help in customising the NLS function to spit out mean and SD ofnew fit!!

Liaw, Andy andy_liaw at merck.com
Fri Jan 7 22:03:21 CET 2005


Doesn't look like nonparametric fit to me, since nls() is used to fit to a
gaussian density, so the result is a gaussian density (with estimated
parameter).

What I do not understand is why people would do this.  This is not the first
time I've seen people doing this, on both R-help and S-news (if my memory is
still any good).  If the objective is to fit a Gaussian distribution to the
data, the `best' Gaussian curve is the one where mu = mean(data) and sigma^2
= var(data).  Why go through all that trouble?  What am I missing?

Andy

> From: Berton Gunter
> 
> It **sounds ** like you are trying to fit a nonparametric 
> density to 6000
> values...  If so, please stop what you are doing and see 
> ?density. You could
> also search on "fit density" or something similar on the R 
> site search, as
> there are other R functions in R packages that do density 
> fitting (ash is
> one, but other recommendations anyone?).
> 
> If this is not what you are trying to do, I think you are 
> still likely going
> about it in the wrong way -- histograms lose information and 
> are notoriously
> dependent on the choice of cutpoints (which is part of the 
> motivation for
> Scott's ash package). You might wish to consult a local 
> statistician to get
> some better approaches to whatever it is that you're trying to do.
> 
> Cheers,
> Bert Gunter
> 
> 
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> Jagarlamudi, Choudary
> Sent: Friday, January 07, 2005 10:50 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Help in customising the NLS function to spit out 
> mean and SD
> ofnew fit!!
> 
>  i'm coding in  R(first time) for a paper my colleague is publishing.
>  i plotted a histogram for 6000 values. Taking the mean and sd of the
> midpoints i did a dnorm and got the densities.
>  pl<-dnorm(trimmedvals,mean=midsmean,sd=midsSD)
>  (now in a loop of 5 times)
>  i plotted these experimental values against theoretical values using
>  the nls function the following way.
>  nlsresult<-nlsModel(pl ~ 1/sqrt(2
> *pi)*std)*2.71828^2/(2*std4^2)),data=answer,start=list(std4=st
> d4,sm=sm))
>  in the formula mean was mid point of 1st frequency bar and 
> sd was sd  of
> 6000 values.I do this 5 times each time changing the mean in 
> the formula to
> be the mid point of the next frequency bar.
>  now i plotted plot(fittedvals ~trimmedvals)
>  
> I am told to plot experimental vs theoretical vlaues from the 
>  histogram and
> get a non linear least square curve fit.
>  I need the mean and sd of this new fit to proceed to my next 
>  module.I'm
> not sure if i'm on track. Excuse me if this sounds too  
> naive.If nls is not
> what i should be using can you please give me some  pinters 
> to solve this.
> 
>  Thanks in advance.
> 
> Choudary Jagarlamudi
> Instructor
> Southwestern Oklahoma State University
> STF 254
> 100 campus Drive
> Weatherford OK 73096
> Tel 580-774-7136
> 
> ______________________________________________
> R-help at 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
> 
>




More information about the R-help mailing list