---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
 Multinomial distribution

# An automatic oven produces on average 1 biscuit burnt every 8; biscuits are then
# automatically mixed and packaged in packs of 6. What is the distribution law of the
# random variable  N = "n. of burnt cookies in a pack"?
# It is a discrete probability distribution.
N = 6; p = 1/8; x = 0:N; y = dbinom(x, N, p)
# x[1]=0, ..., x[N+1]=N, y[1]=...
Piano(0,N, 0,max(y)); POINT(x,y, "blue")
# If the burnt cookies are 3:
a=2; b=dbinom(a,N,p); b; fraction(b); POINT(a,b,"red")
# graph on the left:
     
# Using multinomial instead of binomial:
N = 6; p = 1/8; x = 0:N
for(i in 0:N) y[i+1] = dmultinom(c(i,N-i), prob=c(p,1-p) )
Piano(0,N, 0,max(y)); POINT(x,y, "blue")
a=2; b=dmultinom(c(a,N-a),prob=c(p,1-p)); b; fraction(b); POINT(a,b,"green")
# graph on the right
#
# See here and here for specific examples.