1
$\begingroup$

I've noticed that my normalized histograms are not always normalized to 1. For example:

tlist = RandomVariate[NormalDistribution[20, 5], 1000];
Histogram[tlist, Automatic, "PDF"]
dataList = HistogramList[tlist, Automatic, "PDF"];
pdfVal = dataList[[2]];
Total[pdfVal]

If you change the standard deviation of the NormalDistribution, you may see a change in the sum of pdfVal elements:

StdDev >>> Total[pdfVal]
1 >>> 2 or 5
2 >>> 2
3 >>> 1
4 >>> 1
5 >>> 0.5

I've noticed this with other histograms and other distributions as well (i.e. it is not specific to NormalDistribution).

Is there a way to force this to properly normalize to 1, or do I just have to do it by hand?

$\endgroup$
2
$\begingroup$

Change "PDF" to "Probability" (see this question for a discussion of the two options)

Compare

Plot[Total[
  HistogramList[RandomVariate[NormalDistribution[20, sd], 1000], 
    Automatic, "PDF"][[2]]], {sd, 1, 5}]

Plot[Total[
  HistogramList[RandomVariate[NormalDistribution[20, sd], 1000], 
    Automatic, "Probability"][[2]]], {sd, 1, 5}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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