Histogram of overlaid standard normal draws

3 views (last 30 days)
Snoopy
Snoopy on 24 Oct 2021
Commented: Snoopy on 26 Oct 2021
The code below overlays histograms of two sets of standard normal draws. I also attach the graph itself. These draws are based on two Halton sequences, but that is (probably) not relevant to my question. Both sets use the same number of draws (3573) from the Halton sequence. I am a bit puzzled with the overlaid histograms. It looks as if the frequency count of one set (dark blue) is almost everywhere larger than that for the other set (white). But this is impossible because both sets have the same number of draws. That is, I would either expect a very close overlay, or that if one set has more counts at some regions, the other should have more at other regions, so that the number of counts (of draws) are the same in total.
H = haltonset(2,'Skip',50+1);
H = net(H,3573*3);
H = reshape(H,3573,3,2);
S = norminv(H);
histogram(S(:,3,1),100,'FaceColor','blue','EdgeAlpha',0.5);
hold on
histogram(S(:,3,2),100,'FaceColor','white','EdgeAlpha',0.5);
legend('Standard normal draws for 1st dimension','Standard normal draws for 2nd dimension')
hold off

Accepted Answer

the cyclist
the cyclist on 25 Oct 2021
Edited: the cyclist on 25 Oct 2021
If you look carefully, you will notice that your bins are not at precisely the same locations. If you instead choose the exact bin locations (instead of just using 100 bins), you'll get what you expect:
H = haltonset(2,'Skip',50+1);
H = net(H,3573*3);
H = reshape(H,3573,3,2);
S = norminv(H);
binEdges = -4:0.1:4;
histogram(S(:,3,1),binEdges,'FaceColor','blue','EdgeAlpha',0.5);
hold on
histogram(S(:,3,2),binEdges,'FaceColor','white','EdgeAlpha',0.5);
legend('Standard normal draws for 1st dimension','Standard normal draws for 2nd dimension')
hold off
Just illustrate it a bit more, here are the differences in bin counts for your method. You see that away from the peak, the values are negative, so the rear bins are fully hidden behind the front bins.
H = haltonset(2,'Skip',50+1);
H = net(H,3573*3);
H = reshape(H,3573,3,2);
S = norminv(H);
hc1 = histcounts(S(:,3,1),100);
hc2 = histcounts(S(:,3,2),100);
figure
plot(hc1-hc2)
  1 Comment
Snoopy
Snoopy on 26 Oct 2021
Thanks for the comprehensive and clear answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!