If I roll a 6-sided die x
times (or roll x
6-sided dice at once), what is the probability that the sum of the result is greater than another y
rolls (or one roll of y
dice)?
1 Answer
To give an answer, here is some R code, both doing the calculation exactly and with a normal approximation with continuity correction.
probdice <- function(numberdice, sides=6){
probmatrix <- matrix(0, ncol=numberdice, nrow=numberdice*sides)
probmatrix[1:sides, 1] <- 1 / sides
for (d in 2:numberdice){
for (s in 1:sides){
probmatrix[(d-1+s):((d-1)*sides+s), d] <-
probmatrix[(d-1+s):((d-1)*sides+s), d] +
probmatrix[(d-1):((d-1)*sides), d-1] / sides
}
}
return(probmatrix)
}
probXgtY <- function(X, Y, sides=6){
distXplusY <- probdice(X+Y, sides)[, X+Y]
XgtY <- c(sum(distXplusY[(1:((X+Y)*sides)) > 7*Y]),
sum(distXplusY[(1:((X+Y)*sides)) == 7*Y]),
sum(distXplusY[(1:((X+Y)*sides)) < 7*Y]))
names(XgtY) <- c("P[sum(X)>sum(Y)]", "P[sum(X)=sum(Y)]", "P[sum(X)<sum(Y)]")
return(XgtY)
}
pnormalapprox <- function(X, Y, sides=6){
meandiff <- (X-Y) * (sides+1) / 2
sddiff <- sqrt((X+Y) * (sides^2-1) / 12)
PXgtY <- c(1 - pnorm(1/2, meandiff, sddiff),
pnorm(1/2, meandiff, sddiff) - pnorm(-1/2, meandiff, sddiff),
pnorm(-1/2, meandiff, sddiff))
names(PXgtY) <- c("P[sum(X)>sum(Y)]","P[sum(X)=sum(Y)]","P[sum(X)<sum(Y)]")
return(PXgtY)
}
Trying with $X=51$ dice and $Y=49$ dice gives these probabilities. The normal approximation with continuity correction is close.
probXgtY(51,49)
# P[sum(X)>sum(Y)] P[sum(X)=sum(Y)] P[sum(X)<sum(Y)]
# 0.64805704 0.02145462 0.33048834
pnormalapprox(51,49)
# P[sum(X)>sum(Y)] P[sum(X)=sum(Y)] P[sum(X)<sum(Y)]
# 0.64825034 0.02147506 0.33027460
With small numbers of dice, the normal approximation is not bad, for example with $X=3,Y=2$:
probXgtY(3,2)
# P[sum(X)>sum(Y)] P[sum(X)=sum(Y)] P[sum(X)<sum(Y)]
# 0.77854938 0.06944444 0.15200617
pnormalapprox(3,2)
# P[sum(X)>sum(Y)] P[sum(X)=sum(Y)] P[sum(X)<sum(Y)]
# 0.78394450 0.06860851 0.14744699
In a more extreme cases in the tail of the distribution, the normal approximation is good in absolute terms but can be poor in relative terms, for example with $X=40,Y=80$:
probXgtY(40,80)
# P[sum(X)>sum(Y)] P[sum(X)=sum(Y)] P[sum(X)<sum(Y)]
# 6.444190e-15 3.694881e-15 1.000000e+00
pnormalapprox(40,80)
# P[sum(X)>sum(Y)] P[sum(X)=sum(Y)] P[sum(X)<sum(Y)]
# 2.953193e-14 1.487699e-14 1.000000e+00
-
$\begingroup$ Alternatively, you could use the code I posted at stats.stackexchange.com/a/116913/919 to compute (say)
mean(d(40,6) > d(80, 6))
ormean(d(40,6) == d(80, 6))
or whatever: that's fairly convenient. $\endgroup$– whuber ♦Commented Mar 27 at 16:45
x
andy
grow large (around 10 or so), Normal approximations work well (provided some care is taken also to estimate the chance of a tie). $\endgroup$