How to calculate the joint probability distribution of two binomially distributed variables in Python?

Is there an existing formula, perhaps in scipy.stats, that allows me to compute the joint probability of two binomials as shown in the image below?

enter image description here

What I would like to do is check if the joint probability is statistically significant compared to 1.

I'm not sure which test to use (binom.pmf, binom.sf, binom.cdf) to do this.

EDIT 1:

To give an example of how I would like to apply this. Consider a trader who trades in both an emerging market and a declining market. A trader can either buy an asset or sell it for a short time. Thus, a trader will make a profit, $ \ pi $, if he buys (sells) an asset when the market is in an uptrend (downtrend), and he takes a loss if he buys (sells) an asset when the market is in a downtrend (upward trend). Thus, I am interested in calculating the joint probability so that the trader will exceed the random probability of 50% in both an uptrend and a downtrend market. In other words:

$$ \ text {H $ _0 $: Pr} (i \ in Buy | profit> 0) + \ text {Pr} (i \ in Sell | profit> 0) = 1 $$

A trader is qualified if he can trade profitably in both uptrend and downtrend markets such that the sum of the probabilities exceeds 1 in the test of significance.

EDIT 2

Perhaps the first table is a little confusing. If I had drawn the contingency table of the previous example, it would be like this:

        Uptrend             Downtrend
Buy     profit>0 (Success)  profit<0 (Failure)
Sell    profit<0 (Failure)  profit>0 (Success)

      

I am interested in the joint probability of success in the Uptrend and Downtrend markets.

+3


source to share


1 answer


The formula you give shows that the joint probability density for any given y_1 and y_2 is simply the product of the probability y_1 and the probability y_2 (i.e. the events are independent). If you want to implement this programmatically to get a two-dimensional probability matrix, you need the outer product of two vectors, which gives the probability distributions y_1 and y_2. For example:



from scipy.stats import binom
import numpy
n1, p1 = 10, 0.3
n2, p2 = 15, 0.8
pdf1 = binom(n1, p1).pmf(numpy.arange(0, n1+1))
pdf2 = binom(n2, p2).pmf(numpy.arange(0, n2+1))
joint_pdf = numpy.outer(pdf1, pdf2)

      

0


source







All Articles