0
$\begingroup$

I want to plot the histogram and pdf of 2 X - 100 with X a binomial distribution, but I'm having trouble with the pdf -- I just get a line y = 0. I tried ploting a simple binomial distribution, but I don't get anything with that either and it takes so much time.

Li[n_] := 2*RandomVariate[BinomialDistribution[n, 1/2], n] - n;
Tb[n_, m_] := Table[Li[n], {i, 1, m}];
y = Tb[100, 1000];
Show[ 
 Histogram[y, 40, "PDF"], 
 Plot[PDF[2*BinomialDistribution[100, 1/2] - 100, x], {x, -10, 10}, 
   PlotStyle -> Thick]]
$\endgroup$
1
  • 1
    $\begingroup$ That's (among other things) because giving ...2*BinomialDistribution[100, 1/2]-100... as the argument to PDF is nonsense. I suggest you avail yourself of the documentation to understand how to properly utilize the probability functions. $\endgroup$
    – ciao
    Oct 9 '15 at 8:15
3
$\begingroup$

As commented, you're not using the functions properly. I think what you're after is:

DiscretePlot[PDF[TransformedDistribution[2*z - 100, 
                 z \[Distributed] BinomialDistribution[100, 1/2]], x], {x, -10, 10}]

enter image description here

Note the use of DiscretePlot - the binomial is a discrete distribution, so a discrete plot is appropriate. You can cajole things to use Plot, but that's goofy IMO...

$\endgroup$
3
  • $\begingroup$ @ciao...the quick or the dead...just deleting my response :) $\endgroup$
    – ubpdqn
    Oct 9 '15 at 8:21
  • $\begingroup$ @ubpdqn: Lol, once again, you cause me to spit-laugh my tea onto my netbook. Cleaning now.... $\endgroup$
    – ciao
    Oct 9 '15 at 8:23
  • $\begingroup$ "…but that's goofy…" - Hyuck! :) $\endgroup$
    – J. M.'s torpor
    Oct 9 '15 at 9:31

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