1
$\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$
2
  • $\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
    Commented Sep 22, 2016 at 23:29
  • 2
    $\begingroup$ Does Histogram[data,Automatic,"Probability"] do what you want? $\endgroup$
    – Lukas
    Commented Sep 23, 2016 at 6:39

1 Answer 1

5
$\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.