Let $(A,B,C)$ follow a multinomial distribution: $$(A,B,C) \sim \text{MultiNom}\left(n=100,p_1=p_2=p_3=\frac13\right).$$ Define $X$, a discrete random variable as $$X = f(A,C) = 2A + 3B + 4C = 2A + 3(100-A-C) + 4C = 300 + C - A$$ where $X$ has integer support from $[200,400]$.
If you wish to find the probability for $X$ being at or above a given value: $$Pr(X \ge x)$$ you can use the following code to sum the different multinomial events
n <- 100
probs <- rep.int(0,n+1)
for(X in n:0) {
ctr_x = n-X+1
for(ctr_j in 1:ceiling(ctr_x/2)) {
a <- ctr_j-1
c <- X+a
b <- n - a - c
probs[ctr_x] <- probs[ctr_x] + dmultinom(c(a,b,c),prob=c(1,1,1))
}
}
cumsum(probs)
(This code only calculates the probabilities for $X$ 300 or above, but the idea carries for any value of $X$.)
You can also obtain these values using a Fast Fourier Transform (code written by whuber). Here is the code for this
f <- fft(c(c(1/3,1/3,1/3), rep(0,253)))
fn <- Re(fft(f^100, inverse=TRUE))/length(f)
x <- seq_along(fn)+2*100-1
plot(x, cumsum(fn), xlim=c(270, 330))
And you can confirm that the results are the same:
cbind(1-cumsum(fn)[100:120],cumsum(probs)[101:81])
From this, I have a number of questions. First and foremost, ¿how does a fast Fourier transform yield the probabilities for a multinomial random variable?
Follow-up queries are...
- ¿why are there 253 zeros in the argument for
fft(·)? - ¿why is
fraised to the power 100? - ¿how does the real part of this result given the result?
- and, ¿does the imaginary part mean anything at all?
Any assistance in how to better understand this strategy would be appreciated.
Reto see. Finally, 253 is not magical, but the total length, 3+253 = 256, is: it's a power of 2. Type?fftto understand. – whuber Jun 12 '23 at 18:37fft-- which really computes the characteristic function of the distribution -- see the section "Intuition from Characteristic Functions" at https://stats.stackexchange.com/a/43075/919. – whuber Jun 13 '23 at 14:40