Say I have a table of data with four columns labelled A, B, C, D, where each entry is either a 0 or 1, how do I calculate P(D=1|A=1,B=1,C=1) directly from the data? Here, event D has a causal link with events A, B, C. Can I apply the conditional probability formula P(D|A,B,C)=P(A,B,C,D)/P(A,B,C)? Also, to calculate the joint probability P(A=1,B=1,C=1) directly from the data, do I just count number of rows with A=1, B=1and C=1, divided by total number of rows? Here, events A, B, C, D are not independent. Thanks, any help is greatly appreciated!
In R conditioning can be done by use of
[ ]-notation (say, "such that").
Example 1: Here, all columns are independent, so conditioning D on A, B, and C, has no effect on the probability, but it does decrease the sample size, so there is a slight difference in the simulated proportion. [With 100,000 realizations, one can expect 2 or 3 place accuracy.]
set.seed(1234) # for reproducibility m = 10^5 a = rbinom(m, 1, .7) mean(a)  0.69942 # aprx P(A=1) = 0.7 b = rbinom(m, 1, .8) mean(b)  0.80134 # aprx P(B=1) = 0.8 c = rbinom(m, 1, .9) mean(c)  0.90018 # aprx P(C=1) = 0.7 d = rbinom(m, 1, .4) mean(d)  0.39876 # aprx P(D=1) = 0.4 mean(d[a==1 & b==1 & c==1])  0.3970629 # aprx P(D=1 | A=1, B=1, C= 1) = 0.4
Example 2: Here is a situation where the result of conditioning is not completely trivial: Roll two fair dice. The if $T = X_1 + X_2$ is the total on the two dice, then $P(T = 4) = 3/36 = 1/12 = 0.0833,$ but $P(T=4 | X_1 < 3, X_2 < 4) = 2/6 = 1/3 = 0.333.$
set.seed(618) m = 10^6 x1 = sample(1:6, m, rep=T) x2 = sample(1:6, m, rep=T) t = x1 + x2 mean(t) # Mean of a sample of one million  6.997249 # aprx E(T) = 7 mean(t==4) # Proportion of `TRUE`s in logical vector  0.083411 # aprx P(T = 4) = 0.0833 mean(t[x1<3 & x2<4] == 4)  0.3335913 # aprx P(T=4 | X1<3, X2<4) = 0.3333. mean(t[x1<3 & x2<4])  3.501377 # can you verify the exact answer?