A clinical trial is run with two groups of five patients. The first group is given a placebo, while the second group is given a newly developed pain medication. If the placebo succeeds in alleviating headache pain with probability 0.4 for each patient while the pain medication alleviates headache pain with probability 0.5, what is the probability that group 1 experiences more successes than group 2?

placebo <- dbinom(0:5, size=5, prob=.4)
treatment <- dbinom(0:5, size=5, prob=.5)
placebo
## [1] 0.07776 0.25920 0.34560 0.23040 0.07680 0.01024
treatment
## [1] 0.03125 0.15625 0.31250 0.31250 0.15625 0.03125
g <- expand.grid(placebo, treatment) ## In order to create a data frame for all combinations of vectors
g1 <- g[,1]*g[,2] ## Then multiply placebo successes and treatment successes together
m <- matrix(g1,nrow=6) ## Then create a matrix of the x’s that we’re interested in for this problem. 
m
##         [,1]    [,2]   [,3]   [,4]    [,5]    [,6]
## [1,] 0.00243 0.01215 0.0243 0.0243 0.01215 0.00243
## [2,] 0.00810 0.04050 0.0810 0.0810 0.04050 0.00810
## [3,] 0.01080 0.05400 0.1080 0.1080 0.05400 0.01080
## [4,] 0.00720 0.03600 0.0720 0.0720 0.03600 0.00720
## [5,] 0.00240 0.01200 0.0240 0.0240 0.01200 0.00240
## [6,] 0.00032 0.00160 0.0032 0.0032 0.00160 0.00032
m[lower.tri(m)] ## In order to get the values for the lower triangle
##  [1] 0.00810 0.01080 0.00720 0.00240 0.00032 0.05400 0.03600 0.01200
##  [9] 0.00160 0.07200 0.02400 0.00320 0.02400 0.00320 0.00160
sum(m[lower.tri(m)]) ## Then sum all the values we’re interested to get:
## [1] 0.26042

\(P(placebo \ successes \ exceed \ treatment \ successes) = 0.26042\)