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

Douglas Bates bates at wisc.edu
Sat Jan 8 15:14:08 CET 2005


Berton Gunter wrote:
> 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=std4,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.

Also, it is very unusual to call nlsModel directly.  I think that if you 
did want to use nonlinear least squares to fit these data then you 
should call nls, not nlsModel.




More information about the R-help mailing list