[R] Fitting Distributions Directly From a Histogram

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jun 12 13:55:53 CEST 2006


On Mon, 12 Jun 2006, Lorenzo Isella wrote:

> Dear All,
>
> A simple question: packages like fitdistr should be ideal to analyze
> samples of data taken from a univariate distribution, but what if
> rather than the raw data of the observations you are given directly
> and only a histogram?

(It is unusual for the actual data not to be available in real problems.)

> I was thinking about generating artificially a set of data
> corresponding to the counts binned in the histogram, but this sounds
> too cumbersome.

And that is not in any case a correct approach, since the mle from 
binned data is not the same as the mle from any dataset corresponding to 
the binned counts.

You could use mle (package stats4) to estimate parameters from the 
likelihood of the grouped data.

> Another question is the following: fitdistr provides the value of the
> log-likely hood function, but what if I want e.g. a chi square test to
> get some insight on the goodness of the fitting?
> I am sure there must be a way to get it straightforwardly without
> coding it myself.

It is not well-defined, as you need to choose a binning to do a chisq 
test.  Once you have (e.g. via cut and table), chisq.test() will produce 
the test statistic and refer it to a reference distribution (which will 
not take any parameter estimation into account).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list