{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Zijing Zhu, PhD",
  "title_listed": "You Can't Step in the Same River Twice",
  "keywords": "",
  "domain": "机器学习",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/you-cant-step-in-the-same-river-twice-cfacf7cee305/",
  "publish_date": "2023-12-20",
  "corpus_stage": "",
  "notes": "",
  "id": "2016d10fb36b",
  "collected_at": "2026-10-02T08:28:21",
  "title": "You Can't Step in the Same River Twice | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# You Can't Step in the Same River Twice\n\"The Book of Why\" Chapters 7&8, a Read with Me series\n[Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\nDecember 20, 202318 min read\n![](../images/000.jpg)\nIn my [previous articles](https://zzhu17.medium.com/list/causality-book-club-def5f1fd00fe), we learned about confounders and colliders in observational data that hinder establishing reliable causal relationships. The solution Pearl provided is to draw causal diagrams and use [the backdoor criterion](https://medium.com/towards-data-science/causal-diagram-confronting-the-achilles-heel-in-observational-data-a69cdb1c4818) to find the sets of confounders to block and leave the colliders and mediators along.\nHowever, when dealing with confounding variables that cannot be observed or measured, it becomes difficult to estimate causality from the observational data. Coping with this issue, in Chapter 7 of \"The Book of Why,\" Judea Pearl introduced the **do-calculus rules**. These rules are particularly useful for the **front-door criterion** and **instrumental variables**. They can be used to establish causality even when unobservable confounding variables are present.\nIn Chapter 8, we will explore the amazing world of **counterfactuals**. Opening with Poet Robert Frost's famous lines:\n> \"And sorry I could not travel both\n> And be one traveler, long I stood...\"\nPearl states although it's impossible to travel both paths or step into the same rivers twice, our brains can imagine what would have happened if we had taken the other path. In order to specify and pass down the wisdom to robots, Pearl introduces the distinctions between **necessary cause** and **sufficient cause** and how to utilize **Structure Causal Models** to conduct counterfactual analysis systematically.\nAs we pass the midpoint, the chapters are getting more technical and information-intensive. In the following section, I will first discuss how to deal with unobserved confounders, unfortunately, with some math, for Rung 2 interventions. Then, I will discuss counterfactuals, a Rung 3 application.\n* * *\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) roadmap.\n### The front-door criterion\nStarting with a causal diagram that we use to understand the causal impact of X on Y:\nHere, X is impacting Y through a mediator, M. However, we cannot estimate causality directly from data without controlling the confounder U. The backdoor path from **\"U - > X\"** generates a spurious correlation between X and Y. The backdoor criterion tells us to control U, but what if U is unobservable?\nFor example, in analyzing the causal relationship between smoke (X) and cancer (Y), we might see this causal diagram:\nHere, smoking causes cancer through the accumulation of tar deposits, and there is a confounder, the smoking gene, which, as argued by some researchers, can influence both one's smoking behaviors and the chances of getting lung cancer. We couldn't collect data on such genes because we don't know whether they exist. Thus, back-door adjustments cannot work in this case.\nTo get the causal impact, we can use the **front-door criterion** instead. The front door here is the mediating process, where smoking increases tar deposits and increases the chances of getting cancer. If we cannot estimate smoke to cancer directly, can we estimate how smoke causally impacts tar with how tar causally impacts cancer instead? Here are the steps:\n**Step 1: Smoking - > Tar**\nThere is only one back door path from smoking to tar:\n> Smoking <- Smoking Gene -> Cancer <- Tar\nAnd it's blocked by the Collider cancer. So, we can estimate the causal impact of smoking to tar directly from data by calculating the conditional probabilities:\ntext\n\n```\nThe causal impact of smoking on tar is:\nP(tar|smoking) - P(tar|no smoking)\n```\n\n**Step 2: Tar - > Cancer**\nThere is one back door path from tar to cancer:\n> Tar <- Smoking <- Smoking Gene -> Cancer\nHere, both smoking and the smoking gene are the confounders, but we can control one of them to block the path. Since we don't have data about the smoking gene, we can control smoking instead:\ntext\n\n```\nThe causal impact of tar on cancer is:\nP(cancer|do(tar)) - P(cancer|do(no tar))\n\nwhere,\n\nP(cancer|do(tar)) = P(cancer|tar,smoking) * P(smoking) + \n                    P(cancer|tar,no smoking) * P(no smoking)\n\nP(cancer|do(no tar)) = P(cancer|no tar,smoking) * P(smoking) + \n                       P(cancer|no tar,no smoking) * P(no smoking)\n```\n\nTo estimate how tar impacts cancer causally, we measure the following four probabilities from the data:\n  * The probability of getting cancer through accumulated tar in the smoking population:\n\n\n> P(cancer|tar, smoking) * P(smoking)\n  * The probability of getting cancer through accumulating tar in the non-smoking population:\n\n\n> P(cancer|tar, no smoking) * P(no smoking)\n  * The probability of getting cancer without enough tar in the smoking population:\n\n\n> P(cancer|no tar, smoking) * P(smoking)\n  * The probability of getting cancer without enough tar in the non-smoking population:\n\n\n> P(cancer|no tar, no smoking) * P(no smoking)\n**Step 3: Smoking - > Tar -> Cancer**\nOnce we know the causal impact of smoking on tar and the causal impact of tar on cancer, we can derive the unbiased causal impact of smoking on cancer through the front door adjustment:\ntext\n\n```\nThe causal impact of smoking on cancer is:\nP(cancer|do(smoking)) = P(cancer|do(tar)) * P(tar|do(smoking)) +\n                        P(cancer|do(no tar)) * P(no tar|do(smoking))\n\n######Math Alert########################\nSince no backdoor between smoking and tar:\n\nP(tar|do(smoking)) = P(tar|smoking) \n&amp; \nP(no tar|do(smoking)) = P(no Tar|smoking)\n\nAnd from back door adjustment for tar and cancer:\n\nP(cancer|do(tar)) = P(cancer|tar,smoking) * P(smoking) + \n                    P(cancer|tar,no smoking) * P(no smoking) \n&amp;\nP(cancer|do(no tar)) = P(cancer|no tar,smoking) * P(smoking) + \n                       P(cancer|no tar,no smoking) * P(no smoking)\n\nFinally,\nP(cancer|do(smoking)) = (P(cancer|tar,smoking) * P(smoking) + \n                        P(cancer|tar,no smoking) * P(no smoking))\n                        * P(tar|smoking) \n                        +\n                        (P(cancer|no tar,smoking) * P(smoking) + \n                        P(cancer|no tar,no smoking) * P(no smoking))\n                        * P(no tar|smoking)\n```\n\nOr, in more general terms, for any causal diagram that resembles the previous one in these ways:\n  * X affects Y through only a mediator M, which is also the front door;\n  * There is an unobservable confounder U, correlated with X and Y but not with the mediator M;\n\n\nThe following formula using the front door adjustment works:\nCompared to the back door adjustment:\nBoth formulas estimate the causal impact of X on Y, and they all remove the _**do**_ operator successfully. This means we can estimate the causal impact from data, i.e., **drawing Rung 2 &3 conclusions from Rung 1 data**. In the front door adjustment formula, we also removed the unobserved confounders U successfully. In the smoking to cancer case, we can estimate the impact of smoking without including the smoking gene.\nThe front door criterion opens the door for squeezing a bit more juice out of observational data, even facing unmeasurable confounders. However, there are challenges regarding its applications since the real world usually functions messier and more complicated than the textbook causal diagrams. For example, the unobserved confounder could also impact the mediator:\nEven with this complication, as long as the relationship between U and M is weak, using the \"gold standard\" randomized control trial (RCT) estimation of P(Y|do(X)) as a benchmark, the empirical research shows that using the front door adjustment provides a better estimation than the back door adjustment without blocking all necessary back doors due to unobserved confounders.\n* * *\n### Do-calculus rules\nUsing the example above that illustrates the front door adjustment, Pearl also summaries three rules that provide general guidance in the process of removing _**do** _s :\n  * Rule 1 shows if variable W is irrelevant to Y, or its direct path to Y is blocked by variable Z, then removing or adding W will not change the following probabilities:\n\n\n  * Rule 2 shows if a variable set Z blocks all back-door paths from X to Y, then conditional on Z will remove the _**do**_ operation:\n\n\n  * Rule 3 shows if there are no causal paths from X to Y, then we can remove the _**do**_ operation entirely:\n\n\nThe above three rules set the foundation for _**do-** _calculus that allows us to derive Rung 2 and 3 causal impacts out of observational data. Rule 1 shows what variables are useful to collect from the data; Rule 2 shows how to derive intervention, a Rung 2 conclusion, out of observational data; Rule 3 shows whether an intervention will be effective.\n### More math alert: skip if math gives you a headache\nUsing the three rules, we can revisit the smoking-to-cancer causal diagram:\nAnd see how we utilize Rules 2 and 3 even in more general cases. Here are the steps:\nHere, to understand how smoking causally impacts cancer, we are using the front door path smoking -> tar -> cancer in 7 steps:\n  * Step 1 is based on probability theories where we introduce the mediator t, tar, to estimate the causal impact;\n  * Step 2 is based on Rule 2. Since tar -> cancer's back door is blocked by s, smoking, we can replace (do(s), t) with (do(s), do(t));\n  * Step 3 is based on Rule 2 again. Since smoking -> tar doesn't have back doors, we can replace do(s) with s;\n  * Step 4 is based on Rule 3. Since smoking is only causally impacting cancer through tar, we can replace P(c|do(s), do(t)) with P(c|do(t));\n  * Step 5 is based on probability theories, where we introduce different spectra of S into the equation. In this case, we have smoking vs non-smoking;\n  * Step 6 is based on Rule 2. Again, tar -> cancer's back door is blocked by s, so we replace (do(t), s') with (t, s');\n  * Step 7 is based on Rule 3. Since tar doesn't have a causal impact on smoking, we replace P(s'|do(t)) with P(s').\n\n\nIn the last equation, we can see that we have removed the do operation completely, and there are no unobservable variables. The next step will be using data to calculate the causal impact.\n* * *\n### Instrument variable\nAnother way to deal with the unobserved confounder is to find instrument variables. The definition of instrument variables is better illustrated in a causal diagram:\nSupposedly, when estimating the causal impact of X on Y, there is an unobservable confounder U that prevents us from getting the correct estimation. If there exists a variable Z that satisfies:\n  * Z and U are not correlated. In the diagram, there is no arrow between Z and U;\n  * Z is the direct cause of X;\n  * Z only affects Y through X. In other words, there is no direct or indirect arrow from Z to Y except Z->X->Y.\n\n\nZ will be a very good instrument variable if all conditions are satisfied. Instrument variables are very useful in many scientific fields. In the book, Pearl provides an example of using instrument variables to study a medicine's treatment effect during clinical trials.\nThe medicine was invented to lower patients' cholesterol levels. Although clinical trials are usually randomized, they still face the challenge of noncompliance, where subjects receive the medicine but choose not to take it.\nTheir decisions on not taking the medicine can depend on multiple factors, like how sick they are, and are usually unobservable or hard to measure. The existence of noncompliances will reduce the estimation of drug effectiveness, and we don't really have a good way to predict how many noncompliances there will be in a clinical trial.\nIn this case, researchers introduce an instrument variable, \"Assigned,\" into the RCT design. \"Assigned\" takes the value one if the patient is randomly assigned to receive the drug and zero if they receive a placebo. We will have the following causal diagram:\n\"Assigned\" is an instrument variable because:\n  * The assignment of receiving pills is randomized among patients. Thus, it is not correlated with any confounders U;\n  * Which groups patients are assigned to will determine which treatment they receive, either a drug or a placebo. Thus, \"Assigned\" is the direct cause of \"Received\";\n  * Whether a patient is put into a placebo group or not doesn't affect his or her cholesterol level directly. Thus, \"Assigned\" only affects Cholesterol through Received.\n\n\nWhen we find or establish an instrument variable, we can estimate three relationships in the observational data:\n  * The causal impact of Assigned -> Received;\n  * The causal impact of Assigned -> Cholesterol;\n  * The causal impact of Received -> Cholesterol by removing the \"Assigned -> Received\" impact from \"Assigned -> Cholesterol\".\n\n\nThat's the definition of an instrument variable, along with an example. Pearl's book contains more examples of how instrument variables can be used to solve the unobserved confounders' problems.\n* * *\n### Counterfactuals: What could have been?\nMoving from Rung 2 to Rung 3 of the causality ladder, we are now facing the problem of finding what could have been the outcome without the treatment. This is different from Rung 2 interventions in two aspects:\n  1. **From average causal effect to individual causal effect:**\n\n\nSo far, the causal impact we have discussed is focused on a population or subpopulation. For example, does smoke cause cancer or not for everyone? However, the more applicable question, especially in solving real-world problems, is the **individual causal effect**. For example, if I start smoking, does it cause me to have cancer? If I give this customer a discount, will he or she buy more products? The personalized causation can be inferred through counterfactual analysis.\n**2. There are two types of counterfactuals:**\nIn binary settings, the outcome and potential outcome have two options. In the example of smoke vs cancer, the outcome is either getting cancer or no cancer. Correspondingly, there would be two types of potential outcomes and two sets of causal factors:\n  * **Necessary causation:** If one person gets cancer, the potential outcome is no cancer, and we determine whether smoking is what the lawyers called \"_**but-for causation**_ \": the cancer would not have developed _**but for**_ the smoking behavior.\n  * **Sufficient causation:** If one person does not get cancer, the potential outcome is cancer, and we determine whether having a smoking behavior would have developed cancer for this person.\n\n\nDistinguishing necessary causation and sufficient causation not only helps robot think more like a human in determining causality but us find better action points given different goals and scenarios—more on this in the next section.\n* * *\n### Matching vs Structure Causal Models (SCM)\nWhen posed with the question of what could have been, we may approach it as a missing data problem. Take the example of figuring out how increasing education can improve income for different people. Here is the data summarized in a table:\nHere, we have various data entries from different employees and their current experience level (EX) and their highest education level (ED). To simplify, we assume three levels of education: 0 = high school degree, 1 = college degree, and 2 = graduate degree.\nTheir salaries are also reported as S0, S1, S2. Note that since each employee can only have one highest-level education degree at a given time point, we will have two missing entries for S0, S1, and S2 for all employees.\nIf we approach filling the question marks in the above table as a missing data problem, we have two ways:\n  1. **Matching:**\n\n\nWe find similar employees and match salary levels at different education levels. For example, in the table, we only have one extra feature - Experience, and we see Bert and Caroline both have nine years of experience, then we can have S2(Bert) = S2(Caroline) = $97,000, and S1(Caroline) = S1(Bert) = $92,500. Two missing data filled!\n**2. Linear Regression or more complicated models**\nUnder the strong assumption that all data came from some unknown random sources, standard statistical models find models that best fit the data. In a linear regression model, we might find an equation like this for this particular problem:\nS = $65,000 + 2,500 _EX + 5,000_ ED\nLooking at the coefficients, the equation tells us on average, one level increase in education increases salary by $5,000. We can use more complicated models when feature space increases.\nWhat's wrong with these methods? Fundamentally, they are both approaches that are data-driven rather than model-driven. We are still trying to solve a Rung 3 problem with Rung 1 approaches. Thus, no matter how complicated our models get and how many more features we gain to predict the outcome variable, we still face the fundamental flaw of missing the causal mechanisms.\nIn this simple example, one problem we have is Experience and Education are not independent of each other. Generally, more education may reduce the years of experience for an individual. If Bert were to have a graduate degree rather than the college degree he has right now, his experience level would be lower than nine years. Thus, he would not be a good match with the nine-year experienced graduate degree holder Caroline anymore. In summarize, we will have a causal graph that looks like this:\nThe causal diagram indicates that Education not only has a direct causal impact on Salary, but it also affects Salary through the mediator Experience. Thus, we will need two equations:\ntext\n\n```\nS = f_s(EX, ED, U_s)\nwhere\nEX = f_ex(ED,U_ex)\n```\n\nThere are several points to make regarding these equations, which constitute the Structure Causal Models (SCM) for this problem:\n  * Salary is a function of Experience, Education, and some unobservable variable that affects Salary U_s. Note the unobservable variable is exogenous, meaning they are not correlated with Education and Experience;\n  * Experience is a function of Education and some unobservable variables that affect Experience U_ex.\n  * The fact that there is no function shows Education as a function of Experience means that there are no causal effects from Experience to Education. This is the assumption we make.\n  * These two equations assume causalities between the right-hand side (the outcome) and the left-hand side(the treatment).\n  * The unobservable variables U_s and U_ex quantify the uncertainties at the individual level, which differs from Bayesian networks that use probabilities at causal links to quantify uncertainties. They are independent of Experience or Education and can be customized by individuals.\n  * Function f represents the relationship between the features and the outcome variable. It can be both linear and non-linear, depending on the assumptions.\n\n\nIf we still assume a linear relationship, we will have the following equations based on the data and our understanding of how education affects experience:\ntext\n\n```\nS = $65,000 + 2,500*EX + 5,000*ED + U_s\nand\nEX= 10 – 4*ED + U_ex\n```\n\nWith these equations, we can calculate every one's idiosyncratic factors U_s and U_ex to predict counterfactuals. Take Alice as an example. We know S(Alice) is 81000, EX(Alice) is six, and ED(Alice) is 0. First, plug these into the second equation to get U_ex. We want to plug in the second equation because it only contains ED, the only causal factor of our interest:\ntext\n\n```\n6 = 10–4*0 + U_ex(Alice)\n-> U_ex(Alice) = -4\nThus,\nEX(Alice) = 10 – 4*ED(Alice) - 4\n```\n\nHere, rather than simply plugging EX(Alice) into the equations, we are using this value indirectly. Knowing EX(Alice) equals six helps us calculate U_ex(Alice). Then we plug S(Alice), ED(Alice) and U_ex(Alice) into the first equation to get U_s(Alice):\ntext\n\n```\n\n81000 = 65000 + 2500*(10 – 4*ED + U_ex) + 5000*ED +  U_s(Alice) \n-> U_s(Alice) = -5000*ED - 2500*U_ex(Alice) -9000\n-> U_s(Alice) = 0 - 2500*(-4) - 9000 = 1000\n\n#Note DO NOT calculate by plug EX=6 directly:\n81000 = 65000 + 2500*6 + 5000*0 +  U_s(Alice)\n```\n\nHere we have the functions for Alice:\ntext\n\n```\nS(Alice) = $65,000 + 2,500*EX + 5,000*ED + U_s(Alice)\nand\nEX= 10 – 4*ED + U_ex(Alice)\n```\n\nOnce the SCMs are ready, we can do a counterfactual analysis for Alice. We can calculate what would be her salary had she attended college. If ED(Alice) is 1 instead of 0, we will first calculate:\ntext\n\n```\nEX(Alice) = 10–4+(-4) = 2\n```\n\nThen calculate S_1(Alice):\ntext\n\n```\nS_1(Alice) = $65,000 + 2,500*2 + 5,000*1 + 1000 = $76,000\n```\n\nNote the difference we might get from the regression model where we plug in ED(Alice) = 1 and EX(Alice)=6:\ntext\n\n```\nS = 65000 + 2500*6 + 5000*1 = $85,000 -> Biased estimation \n\n# If Alice has six years of experience and a high school degree now,\n# She couldn't get six years of experience if she goes to college.\n```\n\nThis is a simple example of utilizing SCMs to understand the causal impact and calculate the counterfactuals at the individual level. In summary, Pearl calls \"the first law of causal inference\":\nThe equation shows the potential outcome Y_x(u) can be imputed by Model M_x if we can remove all back-door paths to X. Here, the model takes much more flexibility than linear regression models as long as the causality is embedded based on the causal diagram.\n* * *\n### Necessary Cause (PN) vs. Sufficient Cause (PS)\nTo understand counterfactuals, we have two different measurements: the probability of necessity (PN) and the probability of sufficiency (PS). To see the difference, let's use an example: the house is set on fire because someone struck the match, and there is oxygen in the air:\nBoth match and oxygen are causal factors in a house on fire. However, they differ in PN and PS. The probability of necessity is:\ntext\n\n```\nPN = P(Y_x=0 = 0|x=1, Y=1) \n```\n\nIn this case, the house was on fire, and a match had struck (Y=1, x=1). This probability asks if the house would not have been on fire had the match not struck (Y_(x=0) = 0). This probability is very high because even though we have enough oxygen, with fire from the match, the house will not be on fire.\nThe same logic applies when we calculate the PN for x=oxygen. The fire would not occur if there were not enough oxygen in the house, even if we struck the match.\nThe probability of necessity shows what would happen to the outcome variable if the treatment _**hadn't**_ happened. If the probability is high, it means this treatment is a necessary cause. In a court setting, proving the victim wouldn't have died if the accused hadn't done something is enough to convict.\nOn the other hand, the probability of sufficient is:\ntext\n\n```\nPS = P(Y_x=1 = 1|x=0, Y=0)\n```\n\nIn this case, the house was not on fire, and a match hadn't struck (Y=0, x=0). This probability asks if the house would have been on fire had the match struck (Y_(x=0) = 0). This probability is also very high because usually, oxygen is everywhere, and the house is very likely to be on fire with oxygen and fire from striking the match.\nThe PS for oxygen, however, is very low. The fire would not likely occur just because the house has oxygen. Oxygen is not sufficient to set the house on fire. We need the action of bringing other fire sources like striking the match.\nThus, the probability of sufficient tells us what would happen to the outcome variable if the treatment _**had**_ happened. If the probability is high, it means this treatment is a sufficient cause. In this case, striking the match qualifies as a sufficient cause for a house fire, but oxygen doesn't.\n### Why distinguish PS and PN\n_**Why bother making these distinctions?**_ In a nutshell, although multiple variables can be the causal factors for an outcome, human brains automatically \"rank\" these factors based on some conditions. Psychologists found that humans imagining actions could have been done to turn around an undesired outcome. They are more likely to:\n  * Imagine undoing a rare event than a common one. For example, striking a match is a more rare event compared to having oxygen in the house. (Hopefully!)\n  * Human is more likely to blame their own actions, i.e., striking a match, than events not under their control.\n\n\nAs Pearl emphasizes, embedding both PN and PS into models would suggest a systematic way for teaching robots to produce meaningful explanations of the observed outcomes.\nIn addition, understanding the distinctions between PS and PN guides us to the action points. Climate scientists who study and find the cause of the extreme heat waves may have two different statements:\n  * PN: There is a 90% probability that man-made climate change was a necessary cause of a heat wave;\n  * PS: There is an 80% probability that climate change will be sufficient to produce a heat wave this strong at least once every 50 years.\n\n\nThe PN statement tells us about attribution: who was responsible for the heat wave - man-made climate change. It finds the cause. The PS statement tells us about policy. It says we are better prepared for the heat waves because more is happening. Who caused it? Not specified. Both statements are informative, just in different ways.\n* * *\n**What a long read!** This completes the 5th article in this \"Read with Me\" series for Judea Pearl's \"The Book of Why.\" Thanks for hanging to the end. Chapters 7 and 8 are definitely information-dense. I hope this article is helpful to you. If you haven't read the first four articles, check them out here:\n  * [**Kick-off: Start with A Cat Story**](https://medium.com/towards-data-science/read-with-me-a-causality-book-club-edd7085d6ae6)\n  * [**Chapter1 &2: Data Tells Us 'What\" and We Always Seek for \"Why\"**](https://medium.com/towards-data-science/data-tells-us-what-and-we-always-seek-for-why-66da7dc3f24d)\n  * [**Chapter3 &4: Causal Diagram: Confronting the Achilles' Heel in Observational Data**](https://medium.com/towards-data-science/causal-diagram-confronting-the-achilles-heel-in-observational-data-a69cdb1c4818)\n  * [**Chapter5 &6:Why Understanding the Data-Generation Process Is More Important Than the Data Itself**](https://zzhu17.medium.com/towards-data-science/why-understanding-the-data-generation-process-is-more-important-than-the-data-itself-f1b3b847e662)\n\n\nIf interested, [subscribe to my email list](https://zzhu17.medium.com/subscribe) to join the currently ongoing biweekly discussions. We will have one more article to come that will focus on mediators and conclude the series:\n> [**What Makes A Strong AI?**](https://towardsdatascience.com/what-makes-a-strong-ai-012315722793)\nAnd a bonus article:\n> [**How is Causal Inference Different in Academia and Industry?**](https://towardsdatascience.com/how-is-causal-inference-different-in-academia-and-industry-fb5afd12e2e7)\nAs always, I highly encourage you to read, think, and share your main takeaways here or on [your own blog](https://youtu.be/oFDl0-SKAL8?si=r1QiRIizhDBdvX-A).\nThanks for reading. If you like this article, don't forget to:\n  * _**Check my recent articles about**_[ _**the 4Ds in data storytelling: making art out of science**_](https://medium.com/towards-data-science/the-4ds-in-data-storytelling-making-art-out-of-science-c4998ed7875e); [_**continuous learning in data science**_](https://towardsdatascience.com/continuous-learning-a-data-scientists-odyssey-8d3006c2ce01) _**;**_[_**how I become a data scientist**_](https://towardsdatascience.com/how-i-became-a-data-scientist-7f5b10606612) _**;**_\n  * _**Check my**_[ _**other articles**_](https://zzhu17.medium.com/my-blog-posts-gallery-ac6e01fe5cc3) _**on different topics like**_[ _**data science interview preparation**_](https://zzhu17.medium.com/list/data-science-interview-preparation-bfb0986a61a3) _**;**_[_**causal inference**_](https://towardsdatascience.com/causal-inference-what-why-and-how-d7336b0081ec) _**;**_\n  * [_**Subscribe**_](https://zzhu17.medium.com/subscribe) _**to my email list;**_\n  * [_**Sign up for medium membership**_](https://zzhu17.medium.com/membership) _**;**_\n  * _**Or follow me on**_[ _**YouTube**_](https://youtube.com/channel/UCMs6go1pvY5OOy1DXVtMo5A) _**and watch my most recent YouTube videos:**_\n\n\nPlease accept cookies to access this content\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](../images/body-6091039d5533a6240825.png)\nWritten By\n## [Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\n[See all from Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\n[Deep Dives](https://towardsdatascience.com/tag/deep-dives/)[Causal Inference](https://towardsdatascience.com/tag/causal-inference/)[Causality](https://towardsdatascience.com/tag/causality/)[Counterfactual](https://towardsdatascience.com/tag/counterfactual/)[Data Science](https://towardsdatascience.com/tag/data-science/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F&title=You%20Can't%20Step%20in%20the%20Same%20River%20Twice)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F&title=You%20Can't%20Step%20in%20the%20Same%20River%20Twice)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F&text=You%20Can't%20Step%20in%20the%20Same%20River%20Twice)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/001.jpeg)](https://towardsdatascience.com/introduction-to-sports-analytics-with-pandas-ad6303db9e11/)\n## [Introduction to Sports Analytics with Pandas](https://towardsdatascience.com/introduction-to-sports-analytics-with-pandas-ad6303db9e11/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAnalysis of German Bundesliga football matches.\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nSeptember 26, 20205 min read\n  * [![](../images/002.jpg)](https://towardsdatascience.com/the-last-matplotlib-tweaking-guide-youll-ever-need-dbd4374a1c1e/)\n## [The Last Matplotlib Tweaking Guide You'll Ever Need](https://towardsdatascience.com/the-last-matplotlib-tweaking-guide-youll-ever-need-dbd4374a1c1e/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nThe default Matplotlib stylings are out of style - but here's what to do about it\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nDecember 17, 20194 min read\n  * [![](../images/003.png)](https://towardsdatascience.com/understanding-point-process-model-with-r-983553ca2a86/)\n## [Understanding Point Process Model with R](https://towardsdatascience.com/understanding-point-process-model-with-r-983553ca2a86/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nI have recently been playing with spatial data as a learning exercise and I have been particularly interested in point pattern analysis...\n[Benjamin Cretois](https://towardsdatascience.com/author/bencretois/)\nJanuary 26, 20218 min read\n  * [![](../images/004.jpg)](https://towardsdatascience.com/ive-tried-r-for-the-first-time-how-bad-was-it-ba344f22e90b/)\n## [I've Tried R for the First Time - How Bad Was It?](https://towardsdatascience.com/ive-tried-r-for-the-first-time-how-bad-was-it-ba344f22e90b/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAll-time Pythonista tries out R - comparisons with Python included.\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nSeptember 10, 20206 min read\n  * [![](../images/005.png)](https://towardsdatascience.com/do-not-over-think-about-outliers-use-a-student-t-distribution-instead-b6c584b91d5c/)\n## [Do not over-think about 'outliers', use a student-t distribution instead](https://towardsdatascience.com/do-not-over-think-about-outliers-use-a-student-t-distribution-instead-b6c584b91d5c/)\n[Data Visualization](https://towardsdatascience.com/category/data-science/data-visualization/)\nThe Student's t-distribution provides a robust alternative to acknowledge that our data may be populated by extreme observations...\n[Daniel Manrique Castano](https://towardsdatascience.com/author/damanrique/)\nMarch 30, 202415 min read\n  * [![](../images/006.png)](https://towardsdatascience.com/mastering-websockets-with-go-c30d0ac48081/)\n## [Mastering WebSockets With Go](https://towardsdatascience.com/mastering-websockets-with-go-c30d0ac48081/)\n[Programming](https://towardsdatascience.com/category/programming/)\nTutorial on how to use WebSockets to build real-time APIs in Go\n[Percy Bolmér](https://towardsdatascience.com/author/programmingpercy/)\nNovember 22, 202227 min read\n  * [![](../images/007.jpg)](https://towardsdatascience.com/how-to-become-a-kaggle-competitions-grandmaster-9d77431c5b7d/)\n## [How to become a Kaggle Competitions Grandmaster](https://towardsdatascience.com/how-to-become-a-kaggle-competitions-grandmaster-9d77431c5b7d/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nIt won't be easy, but you can do it and it's worth it\n[Agnis Liukis](https://towardsdatascience.com/author/agnis-liukis/)\nSeptember 1, 20218 min read\n  * [![](../images/008.jpeg)](https://towardsdatascience.com/anticipating-wildfires-with-machine-learning-tools-5eb43b450d36/)\n## [Anticipating Wildfires with Machine Learning Tools](https://towardsdatascience.com/anticipating-wildfires-with-machine-learning-tools-5eb43b450d36/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nUsing data to uncover ideal wildfire suppression resource placement\n[Patrick Norman](https://towardsdatascience.com/author/patrickisnorman/)\nJune 9, 20215 min read\n  * [![](../images/009.jpeg)](https://towardsdatascience.com/unlock-the-power-of-causal-inference-front-door-adjustment-an-in-depth-guide-for-data-scientists-8e7b8ba33421/)\n## [Unlock the Power of Causal Inference & Front-door Adjustment: An In-depth Guide for Data Scientists](https://towardsdatascience.com/unlock-the-power-of-causal-inference-front-door-adjustment-an-in-depth-guide-for-data-scientists-8e7b8ba33421/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA full explanation of causal inference front-door adjustment with examples including all the Python source code\n[Graham Harrison](https://towardsdatascience.com/author/grahamharrison-86487/)\nFebruary 14, 202310 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n",
  "metadata": {
    "title": "You Can't Step in the Same River Twice | Towards Data Science",
    "description": "\"The Book of Why\" Chapters 7&8, a Read with Me series",
    "keywords": null,
    "author": "Zijing Zhu, PhD",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "You Can't Step in the Same River Twice",
    "og:description": "\"The Book of Why\" Chapters 7&8, a Read with Me series",
    "og:url": "https://towardsdatascience.com/you-cant-step-in-the-same-river-twice-cfacf7cee305/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/12/0xmiWVua7aM8Ie-ch-scaled.jpg",
    "og:image:width": "2048",
    "og:image:height": "2560",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Zijing Zhu, PhD",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "18 min read",
    "article:published_time": "2023-12-20T06:53:25.000Z",
    "article:modified_time": "2023-12-20T06:53:25.000Z",
    "article:author": "https://towardsdatascience.com/author/zzhu17/"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 202,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_000.txt",
      "chars": 75
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_001.txt",
      "chars": 340
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_002.txt",
      "chars": 1044
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_003.txt",
      "chars": 46
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_004.txt",
      "chars": 65
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_005.txt",
      "chars": 84
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_006.txt",
      "chars": 253
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_007.txt",
      "chars": 86
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_008.txt",
      "chars": 26
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_009.txt",
      "chars": 58
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_010.txt",
      "chars": 197
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_011.txt",
      "chars": 28
    },
    {
      "language": "txt",
      "file": "attachments/2016d10fb36b/code/block_012.txt",
      "chars": 27
    }
  ],
  "images": [
    {
      "status": "ok",
      "url": "https://cdn-cookieyes.com/assets/images/revisit.svg",
      "bytes": 2339,
      "reused": false,
      "content_type": "image/svg+xml",
      "local_path": "attachments/2016d10fb36b/images/body-df29beacd7496220cc94.svg",
      "src": "https://cdn-cookieyes.com/assets/images/revisit.svg",
      "alt": "Revisit consent button",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://cdn-cookieyes.com/assets/images/close.svg",
      "bytes": 1345,
      "reused": false,
      "content_type": "image/svg+xml",
      "local_path": "attachments/2016d10fb36b/images/body-2159bb67f3de8ad870eb.svg",
      "src": "https://cdn-cookieyes.com/assets/images/close.svg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/12/0xmiWVua7aM8Ie-ch-scaled.jpg",
      "bytes": 1707638,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/000.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/12/0xmiWVua7aM8Ie-ch-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/1787657091723_tdcxmv.png",
      "bytes": 845013,
      "reused": false,
      "content_type": "image/png",
      "local_path": "attachments/2016d10fb36b/images/body-6091039d5533a6240825.png",
      "src": "https://assets.insightmediagroup.io/media/1787657091723_tdcxmv.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1pJVIcenlSUOyRcPKGscg4Q-scaled.jpeg",
      "bytes": 842286,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/001.jpeg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1pJVIcenlSUOyRcPKGscg4Q-scaled.jpeg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2019/12/0pyfzYr_5Z59f7-s7-scaled.jpg",
      "bytes": 666458,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/002.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2019/12/0pyfzYr_5Z59f7-s7-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/01/0ktkM33Qbqa2xetGW.png",
      "bytes": 16905,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/003.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/01/0ktkM33Qbqa2xetGW.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0IUizcREnB4lXD12S-scaled.jpg",
      "bytes": 208799,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/004.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0IUizcREnB4lXD12S-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/03/11ZU56ZN4nOFslrj5xgkatA.png",
      "bytes": 6121,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/005.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/03/11ZU56ZN4nOFslrj5xgkatA.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/11/1CxShwNiSFSsqBaXhIPUVtQ.png",
      "bytes": 136435,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/006.png",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/11/1CxShwNiSFSsqBaXhIPUVtQ.png",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/0ga8IrufIAoyLVX6i-scaled.jpg",
      "bytes": 432609,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/007.jpg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/0ga8IrufIAoyLVX6i-scaled.jpg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/1ArtYxGFlH3V4gis2MEXJCg.jpeg",
      "bytes": 160964,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/008.jpeg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/1ArtYxGFlH3V4gis2MEXJCg.jpeg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    },
    {
      "status": "ok",
      "url": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/1VLJEnWb6CpAjJgdpLhonSQ-scaled.jpeg",
      "bytes": 777088,
      "reused": true,
      "local_path": "attachments/2016d10fb36b/images/009.jpeg",
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/1VLJEnWb6CpAjJgdpLhonSQ-scaled.jpeg",
      "alt": "",
      "downloaded": true,
      "discovery": "saved_markdown"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/watch?v=oFDl0-SKAL8",
      "status": "ok",
      "local_path": "attachments/2016d10fb36b/videos/repair-oFDl0-SKAL8.mp4",
      "bytes": 352331571,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1437.941000"
    },
    {
      "url": "https://youtube.com/channel/UCMs6go1pvY5OOy1DXVtMo5A",
      "kind": "channel_reference",
      "status": "reference_only"
    },
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/zzhu17/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/what-makes-a-strong-ai-012315722793"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/how-is-causal-inference-different-in-academia-and-industry-fb5afd12e2e7"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/continuous-learning-a-data-scientists-odyssey-8d3006c2ce01"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/how-i-became-a-data-scientist-7f5b10606612"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/causal-inference-what-why-and-how-d7336b0081ec"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/deep-dives/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/causal-inference/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/causality/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/counterfactual/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/introduction-to-sports-analytics-with-pandas-ad6303db9e11/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://zzhu17.medium.com/list/causality-book-club-def5f1fd00fe"
    },
    {
      "type": "external",
      "href": "https://medium.com/towards-data-science/causal-diagram-confronting-the-achilles-heel-in-observational-data-a69cdb1c4818"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-data-scientist"
    },
    {
      "type": "external",
      "href": "https://medium.com/towards-data-science/read-with-me-a-causality-book-club-edd7085d6ae6"
    },
    {
      "type": "external",
      "href": "https://medium.com/towards-data-science/data-tells-us-what-and-we-always-seek-for-why-66da7dc3f24d"
    },
    {
      "type": "external",
      "href": "https://zzhu17.medium.com/towards-data-science/why-understanding-the-data-generation-process-is-more-important-than-the-data-itself-f1b3b847e662"
    },
    {
      "type": "external",
      "href": "https://zzhu17.medium.com/subscribe"
    },
    {
      "type": "external",
      "href": "https://youtu.be/oFDl0-SKAL8?si=r1QiRIizhDBdvX-A"
    },
    {
      "type": "external",
      "href": "https://medium.com/towards-data-science/the-4ds-in-data-storytelling-making-art-out-of-science-c4998ed7875e"
    },
    {
      "type": "external",
      "href": "https://zzhu17.medium.com/my-blog-posts-gallery-ac6e01fe5cc3"
    },
    {
      "type": "external",
      "href": "https://zzhu17.medium.com/list/data-science-interview-preparation-bfb0986a61a3"
    },
    {
      "type": "external",
      "href": "https://zzhu17.medium.com/membership"
    },
    {
      "type": "external",
      "href": "https://youtube.com/channel/UCMs6go1pvY5OOy1DXVtMo5A"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=You+Can%27t+Step+in+the+Same+River+Twice&u=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=You+Can%27t+Step+in+the+Same+River+Twice&url=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=You+Can%27t+Step+in+the+Same+River+Twice&url=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:27:48Z",
  "source_url": "https://towardsdatascience.com/you-cant-step-in-the-same-river-twice-cfacf7cee305/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "http_403",
  "repair_error": "",
  "actual_video_files": [
    {
      "local_path": "attachments/2016d10fb36b/videos/repair-oFDl0-SKAL8.mp4",
      "bytes": 352331571,
      "valid": true,
      "height": 1080,
      "width": 1920,
      "duration": "1437.941000",
      "status": "ok"
    }
  ],
  "expected_saved_body_images": 13,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# You Can't Step in the Same River Twice\n\"The Book of Why\" Chapters 7&8, a Read with Me series\n[Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\nDecember 20, 202318 min read\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/12/0xmiWVua7aM8Ie-ch-scaled.jpg)\nIn my [previous articles](https://zzhu17.medium.com/list/causality-book-club-def5f1fd00fe), we learned about confounders and colliders in observational data that hinder establishing reliable causal relationships. The solution Pearl provided is to draw causal diagrams and use [the backdoor criterion](https://medium.com/towards-data-science/causal-diagram-confronting-the-achilles-heel-in-observational-data-a69cdb1c4818) to find the sets of confounders to block and leave the colliders and mediators along.\nHowever, when dealing with confounding variables that cannot be observed or measured, it becomes difficult to estimate causality from the observational data. Coping with this issue, in Chapter 7 of \"The Book of Why,\" Judea Pearl introduced the **do-calculus rules**. These rules are particularly useful for the **front-door criterion** and **instrumental variables**. They can be used to establish causality even when unobservable confounding variables are present.\nIn Chapter 8, we will explore the amazing world of **counterfactuals**. Opening with Poet Robert Frost's famous lines:\n> \"And sorry I could not travel both\n> And be one traveler, long I stood...\"\nPearl states although it's impossible to travel both paths or step into the same rivers twice, our brains can imagine what would have happened if we had taken the other path. In order to specify and pass down the wisdom to robots, Pearl introduces the distinctions between **necessary cause** and **sufficient cause** and how to utilize **Structure Causal Models** to conduct counterfactual analysis systematically.\nAs we pass the midpoint, the chapters are getting more technical and information-intensive. In the following section, I will first discuss how to deal with unobserved confounders, unfortunately, with some math, for Rung 2 interventions. Then, I will discuss counterfactuals, a Rung 3 application.\n* * *\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) roadmap.\n### The front-door criterion\nStarting with a causal diagram that we use to understand the causal impact of X on Y:\nHere, X is impacting Y through a mediator, M. However, we cannot estimate causality directly from data without controlling the confounder U. The backdoor path from **\"U - > X\"** generates a spurious correlation between X and Y. The backdoor criterion tells us to control U, but what if U is unobservable?\nFor example, in analyzing the causal relationship between smoke (X) and cancer (Y), we might see this causal diagram:\nHere, smoking causes cancer through the accumulation of tar deposits, and there is a confounder, the smoking gene, which, as argued by some researchers, can influence both one's smoking behaviors and the chances of getting lung cancer. We couldn't collect data on such genes because we don't know whether they exist. Thus, back-door adjustments cannot work in this case.\nTo get the causal impact, we can use the **front-door criterion** instead. The front door here is the mediating process, where smoking increases tar deposits and increases the chances of getting cancer. If we cannot estimate smoke to cancer directly, can we estimate how smoke causally impacts tar with how tar causally impacts cancer instead? Here are the steps:\n**Step 1: Smoking - > Tar**\nThere is only one back door path from smoking to tar:\n> Smoking <- Smoking Gene -> Cancer <- Tar\nAnd it's blocked by the Collider cancer. So, we can estimate the causal impact of smoking to tar directly from data by calculating the conditional probabilities:\ntext\n\n```\nThe causal impact of smoking on tar is:\nP(tar|smoking) - P(tar|no smoking)\n```\n\n**Step 2: Tar - > Cancer**\nThere is one back door path from tar to cancer:\n> Tar <- Smoking <- Smoking Gene -> Cancer\nHere, both smoking and the smoking gene are the confounders, but we can control one of them to block the path. Since we don't have data about the smoking gene, we can control smoking instead:\ntext\n\n```\nThe causal impact of tar on cancer is:\nP(cancer|do(tar)) - P(cancer|do(no tar))\n\nwhere,\n\nP(cancer|do(tar)) = P(cancer|tar,smoking) * P(smoking) + \n                    P(cancer|tar,no smoking) * P(no smoking)\n\nP(cancer|do(no tar)) = P(cancer|no tar,smoking) * P(smoking) + \n                       P(cancer|no tar,no smoking) * P(no smoking)\n```\n\nTo estimate how tar impacts cancer causally, we measure the following four probabilities from the data:\n  * The probability of getting cancer through accumulated tar in the smoking population:\n\n\n> P(cancer|tar, smoking) * P(smoking)\n  * The probability of getting cancer through accumulating tar in the non-smoking population:\n\n\n> P(cancer|tar, no smoking) * P(no smoking)\n  * The probability of getting cancer without enough tar in the smoking population:\n\n\n> P(cancer|no tar, smoking) * P(smoking)\n  * The probability of getting cancer without enough tar in the non-smoking population:\n\n\n> P(cancer|no tar, no smoking) * P(no smoking)\n**Step 3: Smoking - > Tar -> Cancer**\nOnce we know the causal impact of smoking on tar and the causal impact of tar on cancer, we can derive the unbiased causal impact of smoking on cancer through the front door adjustment:\ntext\n\n```\nThe causal impact of smoking on cancer is:\nP(cancer|do(smoking)) = P(cancer|do(tar)) * P(tar|do(smoking)) +\n                        P(cancer|do(no tar)) * P(no tar|do(smoking))\n\n######Math Alert########################\nSince no backdoor between smoking and tar:\n\nP(tar|do(smoking)) = P(tar|smoking) \n&amp; \nP(no tar|do(smoking)) = P(no Tar|smoking)\n\nAnd from back door adjustment for tar and cancer:\n\nP(cancer|do(tar)) = P(cancer|tar,smoking) * P(smoking) + \n                    P(cancer|tar,no smoking) * P(no smoking) \n&amp;\nP(cancer|do(no tar)) = P(cancer|no tar,smoking) * P(smoking) + \n                       P(cancer|no tar,no smoking) * P(no smoking)\n\nFinally,\nP(cancer|do(smoking)) = (P(cancer|tar,smoking) * P(smoking) + \n                        P(cancer|tar,no smoking) * P(no smoking))\n                        * P(tar|smoking) \n                        +\n                        (P(cancer|no tar,smoking) * P(smoking) + \n                        P(cancer|no tar,no smoking) * P(no smoking))\n                        * P(no tar|smoking)\n```\n\nOr, in more general terms, for any causal diagram that resembles the previous one in these ways:\n  * X affects Y through only a mediator M, which is also the front door;\n  * There is an unobservable confounder U, correlated with X and Y but not with the mediator M;\n\n\nThe following formula using the front door adjustment works:\nCompared to the back door adjustment:\nBoth formulas estimate the causal impact of X on Y, and they all remove the _**do**_ operator successfully. This means we can estimate the causal impact from data, i.e., **drawing Rung 2 &3 conclusions from Rung 1 data**. In the front door adjustment formula, we also removed the unobserved confounders U successfully. In the smoking to cancer case, we can estimate the impact of smoking without including the smoking gene.\nThe front door criterion opens the door for squeezing a bit more juice out of observational data, even facing unmeasurable confounders. However, there are challenges regarding its applications since the real world usually functions messier and more complicated than the textbook causal diagrams. For example, the unobserved confounder could also impact the mediator:\nEven with this complication, as long as the relationship between U and M is weak, using the \"gold standard\" randomized control trial (RCT) estimation of P(Y|do(X)) as a benchmark, the empirical research shows that using the front door adjustment provides a better estimation than the back door adjustment without blocking all necessary back doors due to unobserved confounders.\n* * *\n### Do-calculus rules\nUsing the example above that illustrates the front door adjustment, Pearl also summaries three rules that provide general guidance in the process of removing _**do** _s :\n  * Rule 1 shows if variable W is irrelevant to Y, or its direct path to Y is blocked by variable Z, then removing or adding W will not change the following probabilities:\n\n\n  * Rule 2 shows if a variable set Z blocks all back-door paths from X to Y, then conditional on Z will remove the _**do**_ operation:\n\n\n  * Rule 3 shows if there are no causal paths from X to Y, then we can remove the _**do**_ operation entirely:\n\n\nThe above three rules set the foundation for _**do-** _calculus that allows us to derive Rung 2 and 3 causal impacts out of observational data. Rule 1 shows what variables are useful to collect from the data; Rule 2 shows how to derive intervention, a Rung 2 conclusion, out of observational data; Rule 3 shows whether an intervention will be effective.\n### More math alert: skip if math gives you a headache\nUsing the three rules, we can revisit the smoking-to-cancer causal diagram:\nAnd see how we utilize Rules 2 and 3 even in more general cases. Here are the steps:\nHere, to understand how smoking causally impacts cancer, we are using the front door path smoking -> tar -> cancer in 7 steps:\n  * Step 1 is based on probability theories where we introduce the mediator t, tar, to estimate the causal impact;\n  * Step 2 is based on Rule 2. Since tar -> cancer's back door is blocked by s, smoking, we can replace (do(s), t) with (do(s), do(t));\n  * Step 3 is based on Rule 2 again. Since smoking -> tar doesn't have back doors, we can replace do(s) with s;\n  * Step 4 is based on Rule 3. Since smoking is only causally impacting cancer through tar, we can replace P(c|do(s), do(t)) with P(c|do(t));\n  * Step 5 is based on probability theories, where we introduce different spectra of S into the equation. In this case, we have smoking vs non-smoking;\n  * Step 6 is based on Rule 2. Again, tar -> cancer's back door is blocked by s, so we replace (do(t), s') with (t, s');\n  * Step 7 is based on Rule 3. Since tar doesn't have a causal impact on smoking, we replace P(s'|do(t)) with P(s').\n\n\nIn the last equation, we can see that we have removed the do operation completely, and there are no unobservable variables. The next step will be using data to calculate the causal impact.\n* * *\n### Instrument variable\nAnother way to deal with the unobserved confounder is to find instrument variables. The definition of instrument variables is better illustrated in a causal diagram:\nSupposedly, when estimating the causal impact of X on Y, there is an unobservable confounder U that prevents us from getting the correct estimation. If there exists a variable Z that satisfies:\n  * Z and U are not correlated. In the diagram, there is no arrow between Z and U;\n  * Z is the direct cause of X;\n  * Z only affects Y through X. In other words, there is no direct or indirect arrow from Z to Y except Z->X->Y.\n\n\nZ will be a very good instrument variable if all conditions are satisfied. Instrument variables are very useful in many scientific fields. In the book, Pearl provides an example of using instrument variables to study a medicine's treatment effect during clinical trials.\nThe medicine was invented to lower patients' cholesterol levels. Although clinical trials are usually randomized, they still face the challenge of noncompliance, where subjects receive the medicine but choose not to take it.\nTheir decisions on not taking the medicine can depend on multiple factors, like how sick they are, and are usually unobservable or hard to measure. The existence of noncompliances will reduce the estimation of drug effectiveness, and we don't really have a good way to predict how many noncompliances there will be in a clinical trial.\nIn this case, researchers introduce an instrument variable, \"Assigned,\" into the RCT design. \"Assigned\" takes the value one if the patient is randomly assigned to receive the drug and zero if they receive a placebo. We will have the following causal diagram:\n\"Assigned\" is an instrument variable because:\n  * The assignment of receiving pills is randomized among patients. Thus, it is not correlated with any confounders U;\n  * Which groups patients are assigned to will determine which treatment they receive, either a drug or a placebo. Thus, \"Assigned\" is the direct cause of \"Received\";\n  * Whether a patient is put into a placebo group or not doesn't affect his or her cholesterol level directly. Thus, \"Assigned\" only affects Cholesterol through Received.\n\n\nWhen we find or establish an instrument variable, we can estimate three relationships in the observational data:\n  * The causal impact of Assigned -> Received;\n  * The causal impact of Assigned -> Cholesterol;\n  * The causal impact of Received -> Cholesterol by removing the \"Assigned -> Received\" impact from \"Assigned -> Cholesterol\".\n\n\nThat's the definition of an instrument variable, along with an example. Pearl's book contains more examples of how instrument variables can be used to solve the unobserved confounders' problems.\n* * *\n### Counterfactuals: What could have been?\nMoving from Rung 2 to Rung 3 of the causality ladder, we are now facing the problem of finding what could have been the outcome without the treatment. This is different from Rung 2 interventions in two aspects:\n  1. **From average causal effect to individual causal effect:**\n\n\nSo far, the causal impact we have discussed is focused on a population or subpopulation. For example, does smoke cause cancer or not for everyone? However, the more applicable question, especially in solving real-world problems, is the **individual causal effect**. For example, if I start smoking, does it cause me to have cancer? If I give this customer a discount, will he or she buy more products? The personalized causation can be inferred through counterfactual analysis.\n**2. There are two types of counterfactuals:**\nIn binary settings, the outcome and potential outcome have two options. In the example of smoke vs cancer, the outcome is either getting cancer or no cancer. Correspondingly, there would be two types of potential outcomes and two sets of causal factors:\n  * **Necessary causation:** If one person gets cancer, the potential outcome is no cancer, and we determine whether smoking is what the lawyers called \"_**but-for causation**_ \": the cancer would not have developed _**but for**_ the smoking behavior.\n  * **Sufficient causation:** If one person does not get cancer, the potential outcome is cancer, and we determine whether having a smoking behavior would have developed cancer for this person.\n\n\nDistinguishing necessary causation and sufficient causation not only helps robot think more like a human in determining causality but us find better action points given different goals and scenarios—more on this in the next section.\n* * *\n### Matching vs Structure Causal Models (SCM)\nWhen posed with the question of what could have been, we may approach it as a missing data problem. Take the example of figuring out how increasing education can improve income for different people. Here is the data summarized in a table:\nHere, we have various data entries from different employees and their current experience level (EX) and their highest education level (ED). To simplify, we assume three levels of education: 0 = high school degree, 1 = college degree, and 2 = graduate degree.\nTheir salaries are also reported as S0, S1, S2. Note that since each employee can only have one highest-level education degree at a given time point, we will have two missing entries for S0, S1, and S2 for all employees.\nIf we approach filling the question marks in the above table as a missing data problem, we have two ways:\n  1. **Matching:**\n\n\nWe find similar employees and match salary levels at different education levels. For example, in the table, we only have one extra feature - Experience, and we see Bert and Caroline both have nine years of experience, then we can have S2(Bert) = S2(Caroline) = $97,000, and S1(Caroline) = S1(Bert) = $92,500. Two missing data filled!\n**2. Linear Regression or more complicated models**\nUnder the strong assumption that all data came from some unknown random sources, standard statistical models find models that best fit the data. In a linear regression model, we might find an equation like this for this particular problem:\nS = $65,000 + 2,500 _EX + 5,000_ ED\nLooking at the coefficients, the equation tells us on average, one level increase in education increases salary by $5,000. We can use more complicated models when feature space increases.\nWhat's wrong with these methods? Fundamentally, they are both approaches that are data-driven rather than model-driven. We are still trying to solve a Rung 3 problem with Rung 1 approaches. Thus, no matter how complicated our models get and how many more features we gain to predict the outcome variable, we still face the fundamental flaw of missing the causal mechanisms.\nIn this simple example, one problem we have is Experience and Education are not independent of each other. Generally, more education may reduce the years of experience for an individual. If Bert were to have a graduate degree rather than the college degree he has right now, his experience level would be lower than nine years. Thus, he would not be a good match with the nine-year experienced graduate degree holder Caroline anymore. In summarize, we will have a causal graph that looks like this:\nThe causal diagram indicates that Education not only has a direct causal impact on Salary, but it also affects Salary through the mediator Experience. Thus, we will need two equations:\ntext\n\n```\nS = f_s(EX, ED, U_s)\nwhere\nEX = f_ex(ED,U_ex)\n```\n\nThere are several points to make regarding these equations, which constitute the Structure Causal Models (SCM) for this problem:\n  * Salary is a function of Experience, Education, and some unobservable variable that affects Salary U_s. Note the unobservable variable is exogenous, meaning they are not correlated with Education and Experience;\n  * Experience is a function of Education and some unobservable variables that affect Experience U_ex.\n  * The fact that there is no function shows Education as a function of Experience means that there are no causal effects from Experience to Education. This is the assumption we make.\n  * These two equations assume causalities between the right-hand side (the outcome) and the left-hand side(the treatment).\n  * The unobservable variables U_s and U_ex quantify the uncertainties at the individual level, which differs from Bayesian networks that use probabilities at causal links to quantify uncertainties. They are independent of Experience or Education and can be customized by individuals.\n  * Function f represents the relationship between the features and the outcome variable. It can be both linear and non-linear, depending on the assumptions.\n\n\nIf we still assume a linear relationship, we will have the following equations based on the data and our understanding of how education affects experience:\ntext\n\n```\nS = $65,000 + 2,500*EX + 5,000*ED + U_s\nand\nEX= 10 – 4*ED + U_ex\n```\n\nWith these equations, we can calculate every one's idiosyncratic factors U_s and U_ex to predict counterfactuals. Take Alice as an example. We know S(Alice) is 81000, EX(Alice) is six, and ED(Alice) is 0. First, plug these into the second equation to get U_ex. We want to plug in the second equation because it only contains ED, the only causal factor of our interest:\ntext\n\n```\n6 = 10–4*0 + U_ex(Alice)\n-> U_ex(Alice) = -4\nThus,\nEX(Alice) = 10 – 4*ED(Alice) - 4\n```\n\nHere, rather than simply plugging EX(Alice) into the equations, we are using this value indirectly. Knowing EX(Alice) equals six helps us calculate U_ex(Alice). Then we plug S(Alice), ED(Alice) and U_ex(Alice) into the first equation to get U_s(Alice):\ntext\n\n```\n\n81000 = 65000 + 2500*(10 – 4*ED + U_ex) + 5000*ED +  U_s(Alice) \n-> U_s(Alice) = -5000*ED - 2500*U_ex(Alice) -9000\n-> U_s(Alice) = 0 - 2500*(-4) - 9000 = 1000\n\n#Note DO NOT calculate by plug EX=6 directly:\n81000 = 65000 + 2500*6 + 5000*0 +  U_s(Alice)\n```\n\nHere we have the functions for Alice:\ntext\n\n```\nS(Alice) = $65,000 + 2,500*EX + 5,000*ED + U_s(Alice)\nand\nEX= 10 – 4*ED + U_ex(Alice)\n```\n\nOnce the SCMs are ready, we can do a counterfactual analysis for Alice. We can calculate what would be her salary had she attended college. If ED(Alice) is 1 instead of 0, we will first calculate:\ntext\n\n```\nEX(Alice) = 10–4+(-4) = 2\n```\n\nThen calculate S_1(Alice):\ntext\n\n```\nS_1(Alice) = $65,000 + 2,500*2 + 5,000*1 + 1000 = $76,000\n```\n\nNote the difference we might get from the regression model where we plug in ED(Alice) = 1 and EX(Alice)=6:\ntext\n\n```\nS = 65000 + 2500*6 + 5000*1 = $85,000 -> Biased estimation \n\n# If Alice has six years of experience and a high school degree now,\n# She couldn't get six years of experience if she goes to college.\n```\n\nThis is a simple example of utilizing SCMs to understand the causal impact and calculate the counterfactuals at the individual level. In summary, Pearl calls \"the first law of causal inference\":\nThe equation shows the potential outcome Y_x(u) can be imputed by Model M_x if we can remove all back-door paths to X. Here, the model takes much more flexibility than linear regression models as long as the causality is embedded based on the causal diagram.\n* * *\n### Necessary Cause (PN) vs. Sufficient Cause (PS)\nTo understand counterfactuals, we have two different measurements: the probability of necessity (PN) and the probability of sufficiency (PS). To see the difference, let's use an example: the house is set on fire because someone struck the match, and there is oxygen in the air:\nBoth match and oxygen are causal factors in a house on fire. However, they differ in PN and PS. The probability of necessity is:\ntext\n\n```\nPN = P(Y_x=0 = 0|x=1, Y=1) \n```\n\nIn this case, the house was on fire, and a match had struck (Y=1, x=1). This probability asks if the house would not have been on fire had the match not struck (Y_(x=0) = 0). This probability is very high because even though we have enough oxygen, with fire from the match, the house will not be on fire.\nThe same logic applies when we calculate the PN for x=oxygen. The fire would not occur if there were not enough oxygen in the house, even if we struck the match.\nThe probability of necessity shows what would happen to the outcome variable if the treatment _**hadn't**_ happened. If the probability is high, it means this treatment is a necessary cause. In a court setting, proving the victim wouldn't have died if the accused hadn't done something is enough to convict.\nOn the other hand, the probability of sufficient is:\ntext\n\n```\nPS = P(Y_x=1 = 1|x=0, Y=0)\n```\n\nIn this case, the house was not on fire, and a match hadn't struck (Y=0, x=0). This probability asks if the house would have been on fire had the match struck (Y_(x=0) = 0). This probability is also very high because usually, oxygen is everywhere, and the house is very likely to be on fire with oxygen and fire from striking the match.\nThe PS for oxygen, however, is very low. The fire would not likely occur just because the house has oxygen. Oxygen is not sufficient to set the house on fire. We need the action of bringing other fire sources like striking the match.\nThus, the probability of sufficient tells us what would happen to the outcome variable if the treatment _**had**_ happened. If the probability is high, it means this treatment is a sufficient cause. In this case, striking the match qualifies as a sufficient cause for a house fire, but oxygen doesn't.\n### Why distinguish PS and PN\n_**Why bother making these distinctions?**_ In a nutshell, although multiple variables can be the causal factors for an outcome, human brains automatically \"rank\" these factors based on some conditions. Psychologists found that humans imagining actions could have been done to turn around an undesired outcome. They are more likely to:\n  * Imagine undoing a rare event than a common one. For example, striking a match is a more rare event compared to having oxygen in the house. (Hopefully!)\n  * Human is more likely to blame their own actions, i.e., striking a match, than events not under their control.\n\n\nAs Pearl emphasizes, embedding both PN and PS into models would suggest a systematic way for teaching robots to produce meaningful explanations of the observed outcomes.\nIn addition, understanding the distinctions between PS and PN guides us to the action points. Climate scientists who study and find the cause of the extreme heat waves may have two different statements:\n  * PN: There is a 90% probability that man-made climate change was a necessary cause of a heat wave;\n  * PS: There is an 80% probability that climate change will be sufficient to produce a heat wave this strong at least once every 50 years.\n\n\nThe PN statement tells us about attribution: who was responsible for the heat wave - man-made climate change. It finds the cause. The PS statement tells us about policy. It says we are better prepared for the heat waves because more is happening. Who caused it? Not specified. Both statements are informative, just in different ways.\n* * *\n**What a long read!** This completes the 5th article in this \"Read with Me\" series for Judea Pearl's \"The Book of Why.\" Thanks for hanging to the end. Chapters 7 and 8 are definitely information-dense. I hope this article is helpful to you. If you haven't read the first four articles, check them out here:\n  * [**Kick-off: Start with A Cat Story**](https://medium.com/towards-data-science/read-with-me-a-causality-book-club-edd7085d6ae6)\n  * [**Chapter1 &2: Data Tells Us 'What\" and We Always Seek for \"Why\"**](https://medium.com/towards-data-science/data-tells-us-what-and-we-always-seek-for-why-66da7dc3f24d)\n  * [**Chapter3 &4: Causal Diagram: Confronting the Achilles' Heel in Observational Data**](https://medium.com/towards-data-science/causal-diagram-confronting-the-achilles-heel-in-observational-data-a69cdb1c4818)\n  * [**Chapter5 &6:Why Understanding the Data-Generation Process Is More Important Than the Data Itself**](https://zzhu17.medium.com/towards-data-science/why-understanding-the-data-generation-process-is-more-important-than-the-data-itself-f1b3b847e662)\n\n\nIf interested, [subscribe to my email list](https://zzhu17.medium.com/subscribe) to join the currently ongoing biweekly discussions. We will have one more article to come that will focus on mediators and conclude the series:\n> [**What Makes A Strong AI?**](https://towardsdatascience.com/what-makes-a-strong-ai-012315722793)\nAnd a bonus article:\n> [**How is Causal Inference Different in Academia and Industry?**](https://towardsdatascience.com/how-is-causal-inference-different-in-academia-and-industry-fb5afd12e2e7)\nAs always, I highly encourage you to read, think, and share your main takeaways here or on [your own blog](https://youtu.be/oFDl0-SKAL8?si=r1QiRIizhDBdvX-A).\nThanks for reading. If you like this article, don't forget to:\n  * _**Check my recent articles about**_[ _**the 4Ds in data storytelling: making art out of science**_](https://medium.com/towards-data-science/the-4ds-in-data-storytelling-making-art-out-of-science-c4998ed7875e); [_**continuous learning in data science**_](https://towardsdatascience.com/continuous-learning-a-data-scientists-odyssey-8d3006c2ce01) _**;**_[_**how I become a data scientist**_](https://towardsdatascience.com/how-i-became-a-data-scientist-7f5b10606612) _**;**_\n  * _**Check my**_[ _**other articles**_](https://zzhu17.medium.com/my-blog-posts-gallery-ac6e01fe5cc3) _**on different topics like**_[ _**data science interview preparation**_](https://zzhu17.medium.com/list/data-science-interview-preparation-bfb0986a61a3) _**;**_[_**causal inference**_](https://towardsdatascience.com/causal-inference-what-why-and-how-d7336b0081ec) _**;**_\n  * [_**Subscribe**_](https://zzhu17.medium.com/subscribe) _**to my email list;**_\n  * [_**Sign up for medium membership**_](https://zzhu17.medium.com/membership) _**;**_\n  * _**Or follow me on**_[ _**YouTube**_](https://youtube.com/channel/UCMs6go1pvY5OOy1DXVtMo5A) _**and watch my most recent YouTube videos:**_\n\n\nPlease accept cookies to access this content\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657091723_tdcxmv.png)\nWritten By\n## [Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\n[See all from Zijing Zhu, PhD](https://towardsdatascience.com/author/zzhu17/)\n[Deep Dives](https://towardsdatascience.com/tag/deep-dives/)[Causal Inference](https://towardsdatascience.com/tag/causal-inference/)[Causality](https://towardsdatascience.com/tag/causality/)[Counterfactual](https://towardsdatascience.com/tag/counterfactual/)[Data Science](https://towardsdatascience.com/tag/data-science/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F&title=You%20Can't%20Step%20in%20the%20Same%20River%20Twice)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F&title=You%20Can't%20Step%20in%20the%20Same%20River%20Twice)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fyou-cant-step-in-the-same-river-twice-cfacf7cee305%2F&text=You%20Can't%20Step%20in%20the%20Same%20River%20Twice)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1pJVIcenlSUOyRcPKGscg4Q-scaled.jpeg)](https://towardsdatascience.com/introduction-to-sports-analytics-with-pandas-ad6303db9e11/)\n## [Introduction to Sports Analytics with Pandas](https://towardsdatascience.com/introduction-to-sports-analytics-with-pandas-ad6303db9e11/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAnalysis of German Bundesliga football matches.\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nSeptember 26, 20205 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/12/0pyfzYr_5Z59f7-s7-scaled.jpg)](https://towardsdatascience.com/the-last-matplotlib-tweaking-guide-youll-ever-need-dbd4374a1c1e/)\n## [The Last Matplotlib Tweaking Guide You'll Ever Need](https://towardsdatascience.com/the-last-matplotlib-tweaking-guide-youll-ever-need-dbd4374a1c1e/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nThe default Matplotlib stylings are out of style - but here's what to do about it\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nDecember 17, 20194 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/01/0ktkM33Qbqa2xetGW.png)](https://towardsdatascience.com/understanding-point-process-model-with-r-983553ca2a86/)\n## [Understanding Point Process Model with R](https://towardsdatascience.com/understanding-point-process-model-with-r-983553ca2a86/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nI have recently been playing with spatial data as a learning exercise and I have been particularly interested in point pattern analysis...\n[Benjamin Cretois](https://towardsdatascience.com/author/bencretois/)\nJanuary 26, 20218 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/0IUizcREnB4lXD12S-scaled.jpg)](https://towardsdatascience.com/ive-tried-r-for-the-first-time-how-bad-was-it-ba344f22e90b/)\n## [I've Tried R for the First Time - How Bad Was It?](https://towardsdatascience.com/ive-tried-r-for-the-first-time-how-bad-was-it-ba344f22e90b/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAll-time Pythonista tries out R - comparisons with Python included.\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nSeptember 10, 20206 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/03/11ZU56ZN4nOFslrj5xgkatA.png)](https://towardsdatascience.com/do-not-over-think-about-outliers-use-a-student-t-distribution-instead-b6c584b91d5c/)\n## [Do not over-think about 'outliers', use a student-t distribution instead](https://towardsdatascience.com/do-not-over-think-about-outliers-use-a-student-t-distribution-instead-b6c584b91d5c/)\n[Data Visualization](https://towardsdatascience.com/category/data-science/data-visualization/)\nThe Student's t-distribution provides a robust alternative to acknowledge that our data may be populated by extreme observations...\n[Daniel Manrique Castano](https://towardsdatascience.com/author/damanrique/)\nMarch 30, 202415 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/11/1CxShwNiSFSsqBaXhIPUVtQ.png)](https://towardsdatascience.com/mastering-websockets-with-go-c30d0ac48081/)\n## [Mastering WebSockets With Go](https://towardsdatascience.com/mastering-websockets-with-go-c30d0ac48081/)\n[Programming](https://towardsdatascience.com/category/programming/)\nTutorial on how to use WebSockets to build real-time APIs in Go\n[Percy Bolmér](https://towardsdatascience.com/author/programmingpercy/)\nNovember 22, 202227 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/0ga8IrufIAoyLVX6i-scaled.jpg)](https://towardsdatascience.com/how-to-become-a-kaggle-competitions-grandmaster-9d77431c5b7d/)\n## [How to become a Kaggle Competitions Grandmaster](https://towardsdatascience.com/how-to-become-a-kaggle-competitions-grandmaster-9d77431c5b7d/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nIt won't be easy, but you can do it and it's worth it\n[Agnis Liukis](https://towardsdatascience.com/author/agnis-liukis/)\nSeptember 1, 20218 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/1ArtYxGFlH3V4gis2MEXJCg.jpeg)](https://towardsdatascience.com/anticipating-wildfires-with-machine-learning-tools-5eb43b450d36/)\n## [Anticipating Wildfires with Machine Learning Tools](https://towardsdatascience.com/anticipating-wildfires-with-machine-learning-tools-5eb43b450d36/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nUsing data to uncover ideal wildfire suppression resource placement\n[Patrick Norman](https://towardsdatascience.com/author/patrickisnorman/)\nJune 9, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/1VLJEnWb6CpAjJgdpLhonSQ-scaled.jpeg)](https://towardsdatascience.com/unlock-the-power-of-causal-inference-front-door-adjustment-an-in-depth-guide-for-data-scientists-8e7b8ba33421/)\n## [Unlock the Power of Causal Inference & Front-door Adjustment: An In-depth Guide for Data Scientists](https://towardsdatascience.com/unlock-the-power-of-causal-inference-front-door-adjustment-an-in-depth-guide-for-data-scientists-8e7b8ba33421/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA full explanation of causal inference front-door adjustment with examples including all the Python source code\n[Graham Harrison](https://towardsdatascience.com/author/grahamharrison-86487/)\nFebruary 14, 202310 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n",
  "body_base_path": "attachments/2016d10fb36b/pages/",
  "body_markdown_path": "attachments/2016d10fb36b/pages/archived-body.md",
  "local_html": "attachments/2016d10fb36b/pages/archived-body.html",
  "body_source": "prior_capture"
}