0
$\begingroup$

cross-posted on the Wolfram Community forum

I'm trying to ilustrate the difficulties in assigning bins to a data set and then running a comparison of the bins against a binomial distribution for all values- n, p. The code I have so far is (mostly thanks to Nasser):

Manipulate[Show[Histogram[dataB, {-0.5, 7.5, c}, "PDF"], 
  DiscretePlot[PDF[BinomialDistribution[n, p], x], {x, 0, 20}, 
    PlotStyle -> PointSize[Large]], ImagePadding -> All],
  {{c, 8, "Column Width"}, 0, 4, .1, Appearance -> "Labeled"},
  {{n, 7, "Number Of Quarters"}, 1, 20, 1, Appearance -> "Labeled"},
  {{p, 0.5, "Fair Coin Toss"}, 0, 1, 0.01, Appearance -> "Labeled"}]

The remaining problem, scaling the number of quarters in the binomial to the width of the X-axis. Right now my X-axis ranges from 0 to 7.5 in agreement with the range of the numbers in my data set. I think I need two X-axes. One to illustrate the range of the numbers in my data set, and a second X-axis to illustrate the number of quarters in the binomial ensemble (1 to 20). Here is a data set (Binomial[n=7,p=0.65]): dataB = {0.38, 1.39, 1.51, 1.75, 1.97, 2.19, 2.43, 2.49, 2.51, 2.52, 2.71, 2.77, 2.81, 2.92, 2.94, 2.95, 3.00, 3.01, 3.29, 3.36, 3.42, 3.43, 3.45, 3.47, 3.49, 3.51, 3.52, 3.53, 3.54, 3.55, 3.56, 3.57, 3.58, 3.59, 3.60, 3.70, 3.75, 3.80, 4.00, 4.10, 4.12, 4.15, 4.18, 4.19, 4.20, 4.21, 4.22, 4.23, 4.24, 4.27, 4.30, 4.35, 4.37, 4.40, 4.41, 4.42, 4.43, 4.44, 4.45, 4.46, 4.50, 4.51, 4.52, 4.53, 4.54, 4.55, 4.60, 4.61, 4.62, 4.63, 4.70, 4.72, 4.75, 4.79, 4.82, 4.85, 4.86, 4.87, 4.89, 4.92, 5.10, 5.15, 5.16, 5.17, 5.18, 5.19, 5.20, 5.25, 5.27, 5.28, 5.30, 5.31, 5.32, 5.35, 5.37, 5.40, 5.42, 5.45, 5.50, 5.55, 5.57, 5.62, 5.64, 5.65, 5.70, 5.77, 5.82, 5.87, 5.89, 5.94, 5.99, 6.00, 6.01, 6.22, 6.23, 6.42, 6.43, 6.44, 6.46, 6.47, 6.48, 6.49, 6.50, 6.51, 6.57, 6.59, 6.64, 6.75, 7.00}

$\endgroup$
  • 1
    $\begingroup$ Could you provide a small data set, dataB, so that the code can be executed? $\endgroup$ – C. E. Aug 21 '13 at 12:22
1
$\begingroup$

Instead of using a DiscretePlot I believe the best option (for visual comparisons) is to use a Plot.

So, my suggestion is to use:

Manipulate[
 Show[Histogram[dataB, {0, 20, c}, "PDF"], 
  Plot[Evaluate@PDF[BinomialDistribution[n, p], x], {x, 0, 20} , 
   PlotStyle -> {Thick, Red}, PlotRange -> All, 
   Exclusions -> None]], {{c, .5, "Column Width"}, .05, 4, .05, 
  Appearance -> "Labeled"}, {{n, 7, "Number Of Quarters"}, 1, 20, 1, 
  Appearance -> "Labeled"}, {{p, 0.65, "Fair Coin Toss"}, 0, 1, 0.01, 
  Appearance -> "Labeled"}]

Result:

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Dear Rod Lm- Thanks for the help. Your solution works, but I'm not wanting to display a binomial distribution as a smooth histogram. Looks like I have to offer up side by side manipulates to get my point across. Thanks again. @Rod Lm $\endgroup$ – Joel Mayer Aug 27 '13 at 14:37

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.