[R] Optimization to fit data to custom density distribution

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Mar 21 14:16:40 CET 2015

One way using the standard R distribution:


No optimization is needed to fit a normal distribution, though.

On 21/03/2015 13:05, Johannes Radinger wrote:
> Hi,
> I am looking for a way to fit data (vector of values) to a density function
> using an optimization (ordinary least squares or maximum likelihood fit).
> For example if I have a vector of 100 values generated with rnorm:
> rnorm(n=100,mean=500,sd=50)
> How can I fit these data to a Gaussian density function to extract the mean
> and sd value of the underlying normal distribution. So the result should
> roughly meet the parameters of the normal distribution used to generate the
> data. The results will ideally be closer the true parameters the more data
> (n) are used to optimize the density function.

That's a concept called 'consistency' from the statistical theory of 
estimation.  If you skipped that course, time to read up (but it is 
off-topic here).

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK

More information about the R-help mailing list