|
96 | 96 | }, |
97 | 97 | { |
98 | 98 | "cell_type": "code", |
99 | | - "execution_count": 3, |
| 99 | + "execution_count": 2, |
100 | 100 | "id": "d7d27532-7995-4d76-b40e-e6ae9e7cc645", |
101 | 101 | "metadata": {}, |
102 | 102 | "outputs": [ |
|
276 | 276 | "[1000 rows x 7 columns]" |
277 | 277 | ] |
278 | 278 | }, |
279 | | - "execution_count": 3, |
| 279 | + "execution_count": 2, |
280 | 280 | "metadata": {}, |
281 | 281 | "output_type": "execute_result" |
282 | 282 | } |
|
299 | 299 | }, |
300 | 300 | { |
301 | 301 | "cell_type": "code", |
302 | | - "execution_count": 4, |
| 302 | + "execution_count": 3, |
303 | 303 | "id": "ac297d2d-5a2f-4c33-bbdc-967d54e24e3f", |
304 | 304 | "metadata": {}, |
305 | 305 | "outputs": [], |
|
309 | 309 | "from causal_testing.specification.variable import Input, Output\n", |
310 | 310 | "from causal_testing.specification.causal_dag import CausalDAG\n", |
311 | 311 | "from causal_testing.specification.scenario import Scenario\n", |
312 | | - "from causal_testing.specification.causal_specification import CausalSpecification\n", |
313 | 312 | "\n", |
314 | 313 | "# Define the input variables \n", |
315 | 314 | "\n", |
|
340 | 339 | " num_shapes_abs,\n", |
341 | 340 | " num_shapes_unit})\n", |
342 | 341 | "\n", |
343 | | - "causal_dag = CausalDAG(dag_file) # Secondly, create the Causal DAG \n", |
344 | | - "\n", |
345 | | - "# Finally, we instantiate the CausalSpecification and pass in the scenario and Causal DAG\n", |
346 | | - "\n", |
347 | | - "causal_specification = CausalSpecification(scenario, causal_dag) " |
| 342 | + "causal_dag = CausalDAG(dag_file) # Secondly, create the Causal DAG " |
348 | 343 | ] |
349 | 344 | }, |
350 | 345 | { |
|
380 | 375 | }, |
381 | 376 | { |
382 | 377 | "cell_type": "code", |
383 | | - "execution_count": 5, |
| 378 | + "execution_count": 4, |
384 | 379 | "id": "9b8491ab-0a90-4061-baee-8e1ecef7371d", |
385 | 380 | "metadata": {}, |
386 | 381 | "outputs": [], |
|
393 | 388 | "base_test_case = BaseTestCase(treatment_variable=intensity, outcome_variable=num_shapes_unit) # Create the base test case\n", |
394 | 389 | "\n", |
395 | 390 | "# Perform identification on the DAG using the base test case\n", |
396 | | - "adjustment_set = causal_specification.causal_dag.identification(base_test_case) # Note: an empty adjustment set means there are no confounding variables that need to be controlled for" |
| 391 | + "adjustment_set = causal_dag.identification(base_test_case) # Note: an empty adjustment set means there are no confounding variables that need to be controlled for" |
397 | 392 | ] |
398 | 393 | }, |
399 | 394 | { |
|
406 | 401 | }, |
407 | 402 | { |
408 | 403 | "cell_type": "code", |
409 | | - "execution_count": 6, |
| 404 | + "execution_count": 5, |
410 | 405 | "id": "fa53a888-68e1-4f6f-babf-16d3a206ea49", |
411 | 406 | "metadata": {}, |
412 | 407 | "outputs": [], |
|
445 | 440 | " \"height\": test_results.estimator.treatment_value,\n", |
446 | 441 | " \"control\": test_results.estimator.control_value,\n", |
447 | 442 | " \"treatment\": test_results.estimator.treatment_value,\n", |
448 | | - " \"risk_ratio\": test_results.test_value.value[0],\n", |
| 443 | + " \"risk_ratio\": test_results.effect_estimate.value[0],\n", |
449 | 444 | " }]" |
450 | 445 | ] |
451 | 446 | }, |
|
459 | 454 | }, |
460 | 455 | { |
461 | 456 | "cell_type": "code", |
462 | | - "execution_count": 7, |
| 457 | + "execution_count": 6, |
463 | 458 | "id": "6bc8be40-bc95-4187-8771-4ce096acc7b5", |
464 | 459 | "metadata": {}, |
465 | 460 | "outputs": [ |
|
536 | 531 | "3 8 16 8 16 3.699311" |
537 | 532 | ] |
538 | 533 | }, |
539 | | - "execution_count": 7, |
| 534 | + "execution_count": 6, |
540 | 535 | "metadata": {}, |
541 | 536 | "output_type": "execute_result" |
542 | 537 | } |
|
561 | 556 | "cell_type": "markdown", |
562 | 557 | "id": "e62216b2-60ed-49b7-a2eb-0ad755bd91fc", |
563 | 558 | "metadata": {}, |
564 | | - "source": "From the above causal test results and the risk ratios, we can conclude that doubling the intensity does not cause the number of polygons per unit area to increase by a factor of 4 as we expected. Instead, it increases by factors ranging from 2.8 to 3.7, meaning that the metamorphic relation is violated at a 95% confidence level." |
| 559 | + "source": [ |
| 560 | + "From the above causal test results and the risk ratios, we can conclude that doubling the intensity does not cause the number of polygons per unit area to increase by a factor of 4 as we expected. Instead, it increases by factors ranging from 2.8 to 3.7, meaning that the metamorphic relation is violated at a 95% confidence level." |
| 561 | + ] |
565 | 562 | }, |
566 | 563 | { |
567 | 564 | "cell_type": "markdown", |
|
583 | 580 | }, |
584 | 581 | { |
585 | 582 | "cell_type": "code", |
586 | | - "execution_count": 8, |
| 583 | + "execution_count": 7, |
587 | 584 | "id": "67bf5061-720f-4b3a-a371-3ff3092e81e1", |
588 | 585 | "metadata": {}, |
589 | 586 | "outputs": [], |
|
594 | 591 | "\n", |
595 | 592 | "base_test_case = BaseTestCase(treatment_variable=width, outcome_variable=num_shapes_unit) # Create the base test case\n", |
596 | 593 | "\n", |
597 | | - "adjustment_set = causal_specification.causal_dag.identification(base_test_case) # Calculate the adjustment set again (if it exists)\n", |
| 594 | + "adjustment_set = causal_dag.identification(base_test_case) # Calculate the adjustment set again (if it exists)\n", |
598 | 595 | "\n", |
599 | 596 | "for intensity in treatment_values:\n", |
600 | 597 | " \n", |
601 | | - " for width in control_values:\n", |
| 598 | + " for width_value in control_values:\n", |
602 | 599 | " \n", |
603 | 600 | " estimator = LinearRegressionEstimator(\n", |
604 | 601 | " df=df, # Pass in the dataframe\n", |
605 | 602 | " base_test_case = base_test_case, # Base test case we created above\n", |
606 | | - " treatment_value = width + 1.0, # Changing the width\n", |
607 | | - " control_value=float(width), # Baseline width values\n", |
| 603 | + " treatment_value = width_value + 1.0, # Changing the width\n", |
| 604 | + " control_value=float(width_value), # Baseline width values\n", |
608 | 605 | " adjustment_set=adjustment_set, # Use the same adjustment set as list comprehension\n", |
609 | 606 | " effect_modifiers={\"intensity\": intensity},\n", |
610 | 607 | " formula=\"num_shapes_unit ~ width + I(intensity ** 2)+I(width ** -1)+intensity-1\", # Patsy formula describing a linear regression model\n", |
|
614 | 611 | " base_test_case = base_test_case, # Pass in the base test case\n", |
615 | 612 | " expected_causal_effect = Positive(), # We expect a positive increase\n", |
616 | 613 | " estimate_type = \"ate_calculated\", # Calls the ate_calculated method in the linear regression estimator\n", |
617 | | - " effect_modifier_configuration = {\"intensity\": intensity}, # Condition on (hold constant) the intensity value when calculating width\n", |
618 | 614 | " estimator=estimator) # Pass in the estimator we created above\n", |
619 | 615 | " \n", |
620 | 616 | " test_results = causal_test_case.execute_test() # Execute the tests\n", |
|
624 | 620 | " {\n", |
625 | 621 | " \"control\": test_results.estimator.control_value,\n", |
626 | 622 | " \"treatment\": test_results.estimator.treatment_value,\n", |
627 | | - " \"intensity\": test_results.effect_modifier_configuration[\"intensity\"],\n", |
628 | | - " \"ate\": test_results.test_value.value[0],\n", |
629 | | - " \"ci_low\": test_results.confidence_intervals[0][0],\n", |
630 | | - " \"ci_high\": test_results.confidence_intervals[1][0],\n", |
| 623 | + " \"intensity\": estimator.effect_modifiers[\"intensity\"],\n", |
| 624 | + " \"ate\": test_results.effect_estimate.value[0],\n", |
| 625 | + " \"ci_low\": test_results.effect_estimate.ci_low[0],\n", |
| 626 | + " \"ci_high\": test_results.effect_estimate.ci_high[0],\n", |
631 | 627 | " }]\n" |
632 | 628 | ] |
633 | 629 | }, |
634 | 630 | { |
635 | 631 | "cell_type": "code", |
636 | | - "execution_count": 9, |
| 632 | + "execution_count": 8, |
637 | 633 | "id": "6c54392c-4e6b-42b3-b39a-e0d1d0ab25b7", |
638 | 634 | "metadata": {}, |
639 | 635 | "outputs": [ |
|
775 | 771 | "9 1.0 2.0 2 -7.378642 -16.381136 1.623851" |
776 | 772 | ] |
777 | 773 | }, |
778 | | - "execution_count": 9, |
| 774 | + "execution_count": 8, |
779 | 775 | "metadata": {}, |
780 | 776 | "output_type": "execute_result" |
781 | 777 | } |
|
827 | 823 | ], |
828 | 824 | "metadata": { |
829 | 825 | "kernelspec": { |
830 | | - "display_name": "Python 3 (ipykernel)", |
| 826 | + "display_name": "Causal Testing Dev Env", |
831 | 827 | "language": "python", |
832 | | - "name": "python3" |
| 828 | + "name": "causal_testing_dev" |
833 | 829 | }, |
834 | 830 | "language_info": { |
835 | 831 | "codemirror_mode": { |
|
841 | 837 | "name": "python", |
842 | 838 | "nbconvert_exporter": "python", |
843 | 839 | "pygments_lexer": "ipython3", |
844 | | - "version": "3.10.12" |
| 840 | + "version": "3.11.14" |
845 | 841 | } |
846 | 842 | }, |
847 | 843 | "nbformat": 4, |
|
0 commit comments