Skip to content

Instantly share code, notes, and snippets.

@myazdani
Created March 24, 2020 18:55
Show Gist options
  • Save myazdani/25c7166e4726ef3c5f50386f450c0ed4 to your computer and use it in GitHub Desktop.
Save myazdani/25c7166e4726ef3c5f50386f450c0ed4 to your computer and use it in GitHub Desktop.
Working out a toy example on do-calculus for smoking causing cancer from Pearl's book "Book of Why"
p(c = True | tar = True, smoking = True) = 0.99
p(c = True | tar = False, smoking = True) = 0.2
p(c = True | tar = False, smoking = False) = 0.01
p(c = True | tar = True, smoking = False) = 0.99
p(smoking = True) = 0.1
p(smoking = False) = 0.9
p(tar = True | smoking = True) = 0.99
p(tar = False | smoking = True) = 0.01
p(c = True | tar = True, smoking = True) * p(smoking = True) * p(tar = True | smoking = True)
+
p(c = True | tar = False, smoking = True) * p(smoking = True) * p(tar = False | smoking = True)
+
p(c = True | tar = False, smoking = False) * p(smoking = False) * p(tar = False | smoking = True)
+
p(c = True | tar = True, smoking = False) * p(smoking = False) * p(tar = True | smoking = True)
0.99*0.1*0.99 + 0.2*0.1*0.01 + 0.01*0.9*0.01 + 0.99*0.9*0.99
0.09801 + 0.0002 + 0.00009 + 0.88209
Exercise -> eating more -> weight gain
p(weight_gain = True | eating_more = True, exercise_increase = True) = 0.99
p(weight_gain = True | eating_more = False, exercise_increase = True) = 0.2
p(weight_gain = True | eating_more = False, exercise_increase = False) = 0.01
p(weight_gain = True | eating_more = True, exercise_increase = False) = 0.99
p(exercise_increase = True) = 0.1
p(exercise_increase = False) = 0.9
p(eating_more = True | exercise_increase = True) = 0.99 ******
p(eating_more = False | exercise_increase = True) = 0.01
p(weight_gain = True | eating_more = True, exercise_increase = True) * p(exercise_increase = True) * p(eating_more = True | exercise_increase = True)
+
p(weight_gain = True | eating_more = False, exercise_increase = True) * p(exercise_increase = True) * p(eating_more = False | exercise_increase = True)
+
p(weight_gain = True | eating_more = False, exercise_increase = False) * p(exercise_increase = False) * p(eating_more = False | exercise_increase = True)
+
p(weight_gain = True | eating_more = True, exercise_increase = False) * p(exercise_increase = False) * p(eating_more = True | exercise_increase = True)
0.99*0.1*0.99 + 0.2*0.1*0.01 + 0.01*0.9*0.01 + 0.99*0.9*0.99
0.09801 + 0.0002 + 0.00009 + 0.88209
0.99*0.1*0.99 + 0.2*0.1*0.01 + 0.01*0.9*(1 - x) + 0.99*0.9*x
.891 - 0.009
0.10721 + 0.882*x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment