Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

HistogramDistribution takes a list of data points, creates a histogram from them, and returns this histogram in a form that can be used as a distribution.

I already have the binned data, and I do not have the original data points. How can I create a distribution object equivalent to a histogram distribution using this binning data?

Let's assume we have the binned data in the same format that HistogramList returns.

Example data: bins = N@HistogramList@RandomVariate[NormalDistribution[], 1000].

share|improve this question

1 Answer 1

up vote 5 down vote accepted

HistogramDistribution creates a DataDistribution object. The format of this object is not documented, but we can attempt guessing at the object structure and construct a DataDistribution directly.

Warning: The usual caveats about spelunking and using undocumented functionality apply. There's no guarantee that this will work in every situation or in future versions. The following seems to work in version 9.

DataDistribution objects have the following format:

DataDistribution[type, data, dimension, numberOfPoints]
  • type is a string describing the type of the data distribution. For histogram distributions it is "Histogram"

  • data must have the format {pdf, binSpec} for histogram distributions (it is different for other distributions). binSpec is a list of bin boundaries, thus it must have a length one greater than the number of bins. pdf is a list of PDF values for each bin. Thus Total[Differences[binSpec] pdf] must be 1.

  • dimension is the dimension of the data. For 1D data, which we use here, it is 1.

  • numberOfPoints is the number of data points that the histogram was built from.

Starting from the example data bins, we can construct the distribution as

{binSpec, counts} = bins

dd = DataDistribution[
       "Histogram", (* type *)
       {counts/Differences[binSpec]/Total[counts], binSpec},  (* data *)
       1,         (* dimension *)
       Infinity   (* no. of data points *)
     ]

The usual functions such as Mean, Median, Variance, etc. can be used on dd.

Note: I am not sure if using Infinity for the number of data points can cause any problems.

share|improve this answer
    
Typo in the last code block? –  Verbeia May 12 at 20:42
    
@Verbeia Not one, but three ... thanks, fixed! –  Szabolcs May 12 at 21:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.