Las funciones características pueden hacer que los cálculos que involucran sumas y diferencias de variables aleatorias sean realmente fáciles. Mathematica tiene muchas funciones para trabajar con distribuciones estadísticas, incluida una función integrada para transformar una distribución en su función característica.
Me gustaría ilustrar esto con dos ejemplos concretos: (1) Suponga que desea determinar los resultados de lanzar una colección de dados con diferentes números de lados, por ejemplo, tirar dos dados de seis lados más un dado de ocho lados (es decir , 2d6 + d8 )? O (2) suponga que desea encontrar la diferencia de dos tiradas de dados (por ejemplo, d6-d6 )?
An easy way to do this would be to use the characteristic functions of the underlying discrete uniform distributions. If a random variable X has a probability mass function f, then its characteristic function φX(t) is just the discrete Fourier Transform of f, i.e., φX(t)=F{f}(t)=E[eitX]. A theorem tells us:
If the independent random variables X and Y have corresponding probability mass functions f and g, then the pmf h of the sum X+Y of these RVs is the convolution of their pmfs h(n)=(f∗g)(n)=∑∞m=−∞f(m)g(n−m).
We can use the convolution property of Fourier Transforms to restate this more simply in terms of characteristic functions:
The characteristic function φX+Y(t) of the sum of independent random variables X and Y equals the product of their characteristic functions φX(t)φY(t).
This Mathematica function will make the characteristic function for an s-sided die:
MakeCf[s_] :=
Module[{Cf},
Cf := CharacteristicFunction[DiscreteUniformDistribution[{1, s}],
t];
Cf]
The pmf of a distribution can be recovered from its characteristic function, because Fourier Transforms are invertible. Here is the Mathematica code to do it:
RecoverPmf[Cf_] :=
Module[{F},
F[y_] := SeriesCoefficient[Cf /. t -> -I*Log[x], {x, 0, y}];
F]
Continuing our example, let F be the pmf that results from 2d6+d8.
F := RecoverPmf[MakeCf[6]^2 MakeCf[8]]
There are 62⋅8=288 outcomes. The domain of support of F is S={3,…,20}. Three is the min because you're rolling three dice. And twenty is the max because 20=2⋅6+8. If you want to see the image of F, compute
In:= F /@ Range[3, 20]
Out= {1/288, 1/96, 1/48, 5/144, 5/96, 7/96, 13/144, 5/48, 1/9, 1/9, \
5/48, 13/144, 7/96, 5/96, 5/144, 1/48, 1/96, 1/288}
If you want to know the number of outcomes that sum to 10, compute
In:= 6^2 8 F[10]
Out= 30
If the independent random variables X and Y have corresponding probability mass functions f and g, then the pmf h of the difference X−Y of these RVs is the cross-correlation of their pmfs h(n)=(f⋆g)(n)=∑∞m=−∞f(m)g(n+m).
We can use the cross-correlation property of Fourier Transforms to restate this more simply in terms of characteristic functions:
The characteristic function φX−Y(t) of the difference of two independent random variables X,Y equals the product of the characteristic function φX(t) and φY(−t) (N.B. the negative sign in front of the variable t in the second characteristic function).
So, using Mathematica to find the pmf G of d6-d6:
G := RecoverPmf[MakeCf[6] (MakeCf[6] /. t -> -t)]
There are 62=36 outcomes. The domain of support of G is S={−5,…,5}. -5 is the min because −5=1−6. And 5 is the max because 6−1=5. If you want to see the image of G, compute
In:= G /@ Range[-5, 5]
Out= {1/36, 1/18, 1/12, 1/9, 5/36, 1/6, 5/36, 1/9, 1/12, 1/18, 1/36}