Example #1
0
 def test_canonical_frontdoor(self):
     model_str = SAMPLE_DAGS["canonical_frontdoor"]
     model = parse_model_string(model_str)
     is_valid = check_backdoor_criterion(model,
                                         treatment="X",
                                         outcome="Y",
                                         conditioning_set={"Z"})
     assert not is_valid
Example #2
0
 def test_simple_collider(self):
     model_str = SAMPLE_DAGS["Collider"]
     model = parse_model_string(model_str)
     is_valid = check_backdoor_criterion(model,
                                         treatment="X",
                                         outcome="Y",
                                         conditioning_set={"Z"})
     assert is_valid
Example #3
0
 def test_m_bias(self):
     model = parse_model_string([
         "U₁[unobserved] -> Z",
         "U₁[unobserved] -> Y[outcome]",
         "U₂[unobserved] -> A[treatment]",
         "U₂[unobserved] -> Z",
         "A -> Y"
     ])
     path = utils.node_path_to_edge_path(["A", "U₂", "Z", "U₁", "Y"], model.graph)
     is_blocked = model.is_path_blocked(path, conditioning_set=None)
     assert is_blocked
Example #4
0
 def test_shries_platt_coach_fitness(self):
     model = parse_model_string(sample_dags.SHRIER_PLATT_2008)
     model.update_node("Coach", NodeAttribute.ADJUSTED)
     model.update_node("Fitness Level", NodeAttribute.ADJUSTED)
     biasing_paths = model.get_biasing_paths(as_edge_list=True)
     assert len(biasing_paths) == 0
Example #5
0
 def test_simple_chain(self):
     model = parse_model_string(["x->b", "b->y"])
     path = utils.node_path_to_edge_path(["x", "b", "y"], model.graph)
     is_blocked = model.is_path_blocked(path)
     assert not is_blocked
Example #6
0
 def test_shries_platt_no_adjustment(self):
     model = parse_model_string(sample_dags.SHRIER_PLATT_2008)
     biasing_paths = model.get_biasing_paths()
     assert len(biasing_paths) == 3
Example #7
0
    def test_collider_descendant(self):
        model = parse_model_string(["x->b", "y->b", "b->c", "b->d"])
        path = [('x', 'b'), ('y', 'b')]

        is_blocked = model.is_path_blocked(path, conditioning_set={'c'})
        assert not is_blocked
Example #8
0
 def test_simple_collider(self):
     model = parse_model_string(["x->b", "y->b"])
     path = utils.node_path_to_edge_path(['x', 'b', 'y'], model.graph)
     is_blocked = model.is_path_blocked(path)
     assert is_blocked
Example #9
0
 def test_fork_chain_mix(self):
     model = parse_model_string(["x<-a", "a<-b", "c->b", "c->d", "d->y"])
     path = utils.node_path_to_edge_path(["x", "a", "b", "c", "d", "y"], model.graph)
     is_blocked = model.is_path_blocked(path)
     assert not is_blocked
Example #10
0
 def test_simple_fork(self):
     model = parse_model_string(["b->x", "b->y"])
     path = utils.node_path_to_edge_path(['x', 'b', 'y'], model.graph)
     is_blocked = model.is_path_blocked(path)
     assert not is_blocked
Example #11
0
 def test_long_chain(self):
     model = parse_model_string(["x->a", "a->b", "b->c", "c->d", "d->y"])
     path = utils.node_path_to_edge_path(["x", "a", "b", "c", "d", "y"], model.graph)
     is_blocked = model.is_path_blocked(path)
     assert not is_blocked
Example #12
0
 def test_canonical_frontdoor(self):
     model_str = SAMPLE_DAGS["canonical_frontdoor"]
     model = parse_model_string(model_str)
     adj_sets = get_adjustment_sets(model)
     # front door can't be identified using backdoor adjustment
     assert len(adj_sets) == 0
Example #13
0
 def test_schrier_and_platt_2008(self):
     model_str = SAMPLE_DAGS["Shrier&Platt, 2008"]
     model = parse_model_string(model_str)
     adj_sets = get_adjustment_sets(model)
     assert len(adj_sets) == 7
Example #14
0
 def test_big_m(self):
     model_str = SAMPLE_DAGS["big-M"]
     model = parse_model_string(model_str)
     adj_sets = get_adjustment_sets(model)
     assert len(adj_sets) == 4
     assert all("Z₁" in s for s in adj_sets)
Example #15
0
 def test_m_bias(self):
     model_str = SAMPLE_DAGS["M-bias"]
     model = parse_model_string(model_str)
     adj_sets = get_adjustment_sets(model)
     assert len(adj_sets) == 1
     assert adj_sets[0] == set()  # no adjustment must be performed
Example #16
0
 def test_simple_collider_backdoor(self):
     model = parse_model_string(["x[T]->y[O]", "w->x", "w->y"])
     adj_sets = get_adjustment_sets(model, treatment="x", outcome="y")
     assert adj_sets == [set("w")]