Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
Manipulate[BarChart[Table[PDF[BinomialDistribution[n, p], i], {i, 0, 20}],
  PlotRange -> {{-.5, 21.5}, {-.1, 1}},
  Epilog -> {PointSize[0.03], RGBColor[1, 0, 0], Point[{n*p + 1, 0}]},
  ImageSize -> {450, 350}], 
  {{n, 10, "Variables"}, 1, 20, 1,Appearance -> "Labeled"}, 
  {{p, .5, "Skew"}, 0, 1, Appearance -> "Labeled"}]

Ladies and Gentlemen! How do I convert the binomial distribution inside this Manipulate (above) to a SmoothHistogram? Or, more simply put, where do I insert the term SmoothHistogram in this script?

share|improve this question

1 Answer 1

A few alternatives:

Using SmoothHistogram:

 Manipulate[ Module[{data = RandomVariate[BinomialDistribution[n, p], 500]}, 
   Show[Plot[PDF[BinomialDistribution[n, p], x], {x, 0, 20}, 
             PlotRange -> {{-.5, 21.5}, {-.1, 1}}, Evaluated -> True, 
             PlotStyle -> Directive[Thick, Blue], 
             Epilog -> {PointSize[0.03], RGBColor[1, 0, 0], 
             Point[{n*p + 1, 0}]}, ImageSize -> {450, 350}], 
        SmoothHistogram[data, PlotStyle -> Directive[Thick, Green]]]],
   {{n,  10, "Variables"}, 1, 20, 1,  Appearance -> "Labeled"},
   {{p, .5, "Skew"}, 0, 1, Appearance -> "Labeled"}]

enter image description here

Using SmoothKernelDistribution:

 Manipulate[Module[{data = RandomVariate[BinomialDistribution[n, p], 500]}, 
    Plot[{PDF[BinomialDistribution[n, p], x], 
          PDF[SmoothKernelDistribution[data], x]}, {x, 0, 20}, 
         PlotRange -> {{-.5, 21.5}, {-.1, 1}}, Evaluated -> True, 
         PlotStyle -> {Blue, Orange}, BaseStyle -> Thick, 
         Epilog -> {PointSize[0.03], RGBColor[1, 0, 0], Point[{n*p + 1, 0}]}, 
         ImageSize -> {450, 350}]], 
  {{n, 10, "Variables"}, 1, 20, 1, Appearance -> "Labeled"}, 
  {{p, .5, "Skew"}, 0, 1, Appearance -> "Labeled"}]

enter image description here

share|improve this answer

Your Answer

 
discard

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.