Sums of Discrete Random Variables
1. Convolution examples using sums of rolls of fair dice.
Let
equal the sum of
n
rolls of an
m
-sided die. Use animation to graph probability histograms of the p.d.f. of
.
First an example of how the Convolution program works using the sum of two
m
-sided dice.
>
m := 4:
k := 'k':
>
domain := [k$k=1..m];
probs := [1/m$k=1..m];
X[1] := zip((x,y)->(x,y),domain,probs);
P1 := ProbHistFill(X[1]):
P2 := plot([[0,0],[0,0]], x = 0 .. 4.7, xtickmarks=domain, labels=[``,``], title = `Probability Histogram, One 4-sided Die`, titlefont=[TIMES,BOLD,14]):
display({P1, P2});
>
Y[2] := Convolution(X[1], X[1]);
>
k := 'k':
xtics := [k$k=1..8]:
P2 := ProbHistFill(Y[2]):
T := plot([[0,0],[0,0]], x = 0 .. 8.7, xtickmarks=xtics, labels=[``,``], title = `Probability Histogram,\nSum of Two 4-sided Dice`, titlefont=[TIMES,BOLD,14]):
display({P2, T});
Now use animation on
n
to show the probability histograms for the p.d.f. of the sum of
n
m
-sided dice.
>
m := 4: # Number of faces on each die.
n := 5: # Number of dice that are used.
k := 'k':
xtics := [k$k=1 .. n*m]:
domain := [k$k=1..m]:
probs := [1/m$k=1..m]:
X[1] := zip((x,y)->(x,y),domain,probs):
Y[1] := X[1]:
P[1] := ProbHistFill(Y[1]):
P2 := plot([[0,0],[0,0]], x = 0 .. n*m+0.7, xtickmarks=xtics, labels=[``,``]):
tm := textplot([n*m/2,1/m, `m = `||m], font=[TIMES,BOLD,14]):
tn := textplot([n*m/2,.9/m, `n = `||1], font=[TIMES,BOLD,14]):
Pt[1] := display({P2, P[1],tm,tn}):
for j from 2 to n do
Y[j] := Convolution(Y[j-1], X[1]):
P[j] := ProbHistFill(Y[j]):
tm := textplot([n*m/2,1/m, `m = `||m], font=[TIMES,BOLD,14]):
tn := textplot([n*m/2,.9/m, `n = `||j], font=[TIMES,BOLD,14]):
Pt[j] := display({P2, P[j],tm,tn}):
od:
display([seq(Pt[j], j = 1 .. n)], title = `Sum of n m-sided Dice`, insequence=true, titlefont=[TIMES,BOLD,14]);
Change value of m and/or n
Return to Menu
2. Let
equal the sum of
n
rolls of an
m
-sided die. Use animation to graph probability histograms of the p.d.f. of
. Superimpose a normal p.d.f. with mean
and variance
.
>
m := 4: # Number of faces on each die.
n := 7: # Number of dice that are used.
k := 'k':
xtics := [k$k=1 .. n*m]:
domain := [k$k=1..m]:
probs := [1/m$k=1..m]:
X[1] := zip((x,y)->(x,y),domain,probs):
Y[1] := X[1]:
P[1] := ProbHistFill(Y[1]):
tm := textplot([n*m/2,.9/m, `m = `||m], font=[TIMES,BOLD,14]):
tn := textplot([n*m/2,.8/m, `n = `||1], font=[TIMES,BOLD,14]):
mu := (m+1)/2:
var := (m^2 - 1)/12:
normplot := plot(NormalPDF(mu, var, x), x = -0.5 .. n*m+1/2, color=magenta, thickness=2):
P2 := plot([[0,0],[0,0]], x = 0 .. n*m+0.7, xtickmarks=xtics, labels=[``,``]):
Pt[1] := display({P2, P[1],tm,tn}):
for j from 2 to n do
Y[j] := Convolution(Y[j-1], X[1]):
P[j] := ProbHistFill(Y[j]):
tm := textplot([n*m/2,.9/m, `m = `||m], font=[TIMES,BOLD,14]):
tn := textplot([n*m/2,.8/m, `n = `||j], font=[TIMES,BOLD,14]):
mu := j*(m+1)/2:
var := j*(m^2 - 1)/12:
normplot := plot(NormalPDF(mu, var, x), x = -0.5 .. n*m+1/2, color=blue, thickness=2):
Pt[j] := display({P[j],tm,tn,normplot}):
od:
display([seq(Pt[j], j = 1 .. n)], title = `Sum of n m-sided Dice,\nN[n(m + 1)/2, n(m^2 - 1)/12] p.d.f.`, insequence=true, titlefont=[TIMES,BOLD,14]);
Probability Histogram, Sum of
n
m
-sided Dice,
N
(
,
) p.d.f.
Change Values of m and/or n
Return to Menu