Example #1
0
 def test_pdf_no_adjustment(self):
     causes = ['c']
     effects = ['d']
     admissable_set = []
     variable_types={'a': 'u','b': 'u','c': 'u','d' : 'u'}
     effect = CausalEffect(self.discrete,causes,effects,admissable_set,variable_types)
     # p(d=1|do(c=0) = 0.45, p(d=1|b=0) = 0.40
     p = effect.pdf(pd.DataFrame({ 'd' : [1], 'c' : [0]}))
     print p
     assert( abs( 0.40 - p ) < 0.02 ) 
Example #2
0
 def test_pdf_no_adjustment(self):
     causes = ['c']
     effects = ['d']
     admissable_set = []
     variable_types = {'a': 'u', 'b': 'u', 'c': 'u', 'd': 'u'}
     effect = CausalEffect(self.discrete, causes, effects, admissable_set,
                           variable_types)
     # p(d=1|do(c=0) = 0.45, p(d=1|b=0) = 0.40
     p = effect.pdf(pd.DataFrame({'d': [1], 'c': [0]}))
     print p
     assert (abs(0.40 - p) < 0.02)
Example #3
0
 def test_pdf_continuous(self):
     causes = ['c']
     effects = ['d']
     admissable_set = ['a']
     variable_types={'a': 'c','b': 'c','c': 'c','d' : 'c'}
     effect = CausalEffect(self.X,causes,effects,admissable_set,variable_types)
     c = np.mean(effect.support['c'])
     d = np.mean(effect.support['d'])
     e1 =  effect.pdf(pd.DataFrame({ 'd' : [d], 'c' : [ 0.9 * c]}))
     e2 =  effect.pdf(pd.DataFrame({ 'd' : [d], 'c' : [ 1.1 * c]}))
     print e2, e1, e2 - e1, (e2 - e1) / e2
     assert( abs(e2 - e1) / e2 < 0.05 )
Example #4
0
 def test_pdf_continuous(self):
     causes = ['c']
     effects = ['d']
     admissable_set = ['a']
     variable_types = {'a': 'c', 'b': 'c', 'c': 'c', 'd': 'c'}
     effect = CausalEffect(self.X, causes, effects, admissable_set,
                           variable_types)
     c = np.mean(effect.support['c'])
     d = np.mean(effect.support['d'])
     e1 = effect.pdf(pd.DataFrame({'d': [d], 'c': [0.9 * c]}))
     e2 = effect.pdf(pd.DataFrame({'d': [d], 'c': [1.1 * c]}))
     print e2, e1, e2 - e1, (e2 - e1) / e2
     assert (abs(e2 - e1) / e2 < 0.05)