简体   繁体   中英

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 binomial variables as indicated in the picture below?

在此输入图像描述

What I would like to do is test whether the joint probability is statistically significant compared to 1.

I am not really sure which test to use (binom.pmf, binom.sf, binom.cdf) in order 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 up-trending and down-trending market. The trader can either buy the asset or short-sell the asset. As such, the trader would profit, $\\pi$, if he buys (sells) the asset when the market is in an uptrend (downtrend), and he would make a loss if he buys (sells) the asset when the market is in a downtrend (uptrend). As such, I am interested in calculating the joint probability such that a trader exceeds a random probability of 50% in both an uptrend and downtrend market. In other words:

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

The trader is considered to be skilled if he can profitably trade in both uptrend and downtrend markets such that the sum of the probabilities exceeds 1 in a test of significance.

EDIT 2

Perhaps the first table in a bit confusing. If I were to draw a contingency table of the previous example, it would be as follows:

        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 both an Uptrend and Downtrend market.

The formula you give shows that the joint probability density for any particular y_1 & y_2 is just the product of the probability of y_1 and the probability of y_2 (ie the events are independent). If you want to implement this programmatically to get the 2D matrix of probabilities, you need an outer product of the two vectors that give the probability distributions of 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM