0
$\begingroup$

I made a histogram of 1000 random coin tosses.How can I normalize the numbers in order to get the probabilities for each number. Basically, scaling the Y axis by a factor of 1/1000

The data are in the Table format.

$\endgroup$

closed as off-topic by Alexey Popkov, m_goldberg, corey979, Feyre, user31159 Oct 23 '16 at 17:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Alexey Popkov, m_goldberg, Feyre, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Maybe this just is a bit of semantics but you get the proportions of the observed two numbers (usually 0 and 1) rather than the probabilities. And if there are just two numbers, why would you want to create a histogram when reporting just two 2 numbers (1,000 and the proportion of observed heads) will tell as much about the results in a lot less space? $\endgroup$ – JimB Sep 22 '16 at 23:29
  • 2
    $\begingroup$ Does Histogram[data,Automatic,"Probability"] do what you want? $\endgroup$ – Lukas Sep 23 '16 at 6:39
4
$\begingroup$

As a summary, here are the different possibilities available to you.

The Easy Way

As often in Mathematica, the easiest way is usually to use a built-in construct. As @Lukas mentioned in the comments, you can use the special height specification "Probability" in Histogram[] to get what you want.

data=Table[RandomInteger[],{1000}]
Histogram[data,Automatic,"Probability"]

The Alternative

But maybe, as @Jim Baldwin said, an alternative visualisation is best? Sometimes, you can't beat a simple table...

counts = Tally@Table[RandomInteger[], {1000}];
Grid[{Text /@ {"", "heads", "tails"}, 
  Text /@ {"count", counts[[1, 2]], counts[[2, 2]]}, 
  Text /@ {"probability", N[counts[[1, 2]]/1000], 
    N[counts[[2, 2]]/1000]}}, Frame -> All]

The Straight Answer

Strictly speaking however, you are asking to normalize the histogram scale. To do this, you need to define a custom height function as defined in the "Details and Options" section of the reference on Histogram.

heightfunction[bins_, counts_] := counts/1000;
Histogram[Table[RandomInteger[], {1000}], {{0, 0.5, 1.1}}, heightfunction]

Note: I also adjusted the bins to remove the empty space on the left

$\endgroup$

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