Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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). That's what I think. @Nasser

share|improve this question
What are the variables you want to control with the slider bars? – C. E. Aug 19 '13 at 18:55
what is your control variables? i.e. what are the parameters you want to change? The first question to ask when making a Manipulate is: What do I want to control? – Nasser Aug 19 '13 at 18:55

I have replaced your dataA with some live value,

   RandomVariate[NormalDistribution[s, f], 200], {-0.5, 6.5, 1}, 
   "PDF"], DiscretePlot[PDF[BinomialDistribution[a, b], x], {x, 0, 7},
    PlotStyle -> PointSize[Large]]}, {a, 1, 10, 1}, {b, 0, 1, .1}, {s,
   0.1, 1, .1}, {f, 0.1, 1, .01}]
share|improve this answer

If you need additional controls, need to be more specific.

 Show[Histogram[dataA, {-0.5, 6.5, 1}, "PDF"], 
  DiscretePlot[PDF[BinomialDistribution[n, p], x], {x, 0, 7}, 
   PlotStyle -> PointSize[Large]], ImagePadding -> 10],
 {{n, 6, "how many trials?"}, 2, 20, 1, Appearance -> "Labeled"},
 {{p, .5, "success probabilty?"}, 0, 1, 0.01, Appearance -> "Labeled"},
 Initialization :>
   dataA = RandomInteger[{-1, 7}, 100];

Mathematica graphics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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