SciPy

Joint Distributions (prob140.JointDistribution)

See the Joint Distribution tutorial for more information

Constucting

In [1]: from prob140 import *

In [2]: dist1_table = Table().domain([0,1],[2,3]).probability([0.1, 0.2, 0.3, 0.4])

In [3]: print(dist1_table)
X    | Y    | Probability
0    | 2    | 0.1
0    | 3    | 0.2
1    | 2    | 0.3
1    | 3    | 0.4

In [4]: dist1 = dist1_table.to_joint()

In [5]: print(dist1)
     X=0  X=1
Y=3  0.2  0.4
Y=2  0.1  0.3

In [6]: dist2_table = Table().domain("Coin1",['H','T'],"Coin2", ['H','T']).probability(np.array([0.24, 0.36, 0.16, 0.24]))

In [7]: print(dist2_table)
Coin1 | Coin2 | Probability
H     | H     | 0.24
H     | T     | 0.36
T     | H     | 0.16
T     | T     | 0.24

In [8]: dist2 = dist2_table.to_joint()

In [9]: print(dist2)
         Coin1=H  Coin1=T
Coin2=T     0.36     0.24
Coin2=H     0.24     0.16
Table.to_joint([X_column_label, …]) Converts a table of probabilities associated with two variables into a JointDistribution object

Marginal Distributions

JointDistribution.marginal(label) Returns the marginal distribution of label.
JointDistribution.both_marginals() Finds the marginal distribution of both variables.

Conditional Distributions

JointDistribution.conditional_dist(label[, …]) Given the random variable label, finds the conditional distribution of the other variable.