Não sei o nome dessa distribuição, mas você pode derivá-la da lei da probabilidade total. Suponha que tenham distribuições binomiais negativas com parâmetros ( r 1 , p 1 ) e ( r 2 , p 2 ) , respectivamente. Estou usando a parametrização em que X , Y representam o número de sucessos antes das falhas r 1 'e er 2 ', respectivamente. Então,X, Y( r1, p1)( r2, p2)X, Yr1r2
P( X- Y= k ) = EY( P( X- Y= k ) ) = EY( P( X= k + Y) ) =∑y= 0∞P(Y= y) P( X= k + y)
Nós sabemos
P( X= k + y) = ( k + y+ r1- 1k + y) (1-p1)r1pk + y1
e
P(Y=y) = (y+ r2- 1y) (1-p2)r2py2
assim
P(X−Y=k)=∑y=0∞(y+r2−1y)(1−p2)r2py2⋅(k+y+r1−1k+y)(1−p1)r1pk+y1
Isso não é bonito (caramba!). A única simplificação que vejo imediatamente é
pk1(1−p1)r1(1−p2)r2∑y=0∞(p1p2)y(y+r2−1y)(k+y+r1−1k+y)
which is still pretty ugly. I'm not sure if this is helpful but this can also be re-written as
pk1(1−p1)r1(1−p2)r2(r1−1)!(r2−1)!∑y=0∞(p1p2)y(y+r2−1)!(k+y+r1−1)!y!(k+y)!
I'm not sure if there is a simplified expression for this sum but it could be approximated numerically if you only need it to calculate p-values
I verified with simulation that the above calculation is correct. Here is a crude R function to calculate this mass function and carry out a few simulations
f = function(k,r1,r2,p1,p2,UB)
{
S=0
const = (p1^k) * ((1-p1)^r1) * ((1-p2)^r2)
const = const/( factorial(r1-1) * factorial(r2-1) )
for(y in 0:UB)
{
iy = ((p1*p2)^y) * factorial(y+r2-1)*factorial(k+y+r1-1)
iy = iy/( factorial(y)*factorial(y+k) )
S = S + iy
}
return(S*const)
}
### Sims
r1 = 6; r2 = 4;
p1 = .7; p2 = .53;
X = rnbinom(1e5,r1,p1)
Y = rnbinom(1e5,r2,p2)
mean( (X-Y) == 2 )
[1] 0.08508
f(2,r1,r2,1-p1,1-p2,20)
[1] 0.08509068
mean( (X-Y) == 1 )
[1] 0.11581
f(1,r1,r2,1-p1,1-p2,20)
[1] 0.1162279
mean( (X-Y) == 0 )
[1] 0.13888
f(0,r1,r2,1-p1,1-p2,20)
[1] 0.1363209
I've found the sum converges very quickly for all of the values I tried, so setting UB higher than 10 or so
is not necessary. Note that R's built in rnbinom function parameterizes the negative binomial in terms of
the number of failures before the r'th success, in which case you'd need to replace all of the p1,p2's
in the above formulas with 1−p1,1−p2 for compatibility.