<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Benjamin T. Vincent</title>
<link>https://drbenvincent.github.io/posts.html</link>
<atom:link href="https://drbenvincent.github.io/posts.xml" rel="self" type="application/rss+xml"/>
<description>Bayesian data scientist and causal inference specialist. Co-author of Bayesian Causal Inference, with Nathaniel Forde.</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Thu, 05 Nov 2026 00:00:00 GMT</lastBuildDate>
<item>
  <title>Dead Labour, Reanimated: LLMs and Marx</title>
  <dc:creator>Benjamin Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/dead-labour-reanimated.html</link>
  <description><![CDATA[ 





<p>Large language models (LLMs) come wrapped in an old promise: the machine will take the toil away. The awkward fact is what the machine is made of. It is built from other people’s writing, code, and commentary, then rented out as a product. Debates about sentience, cyber threats and jobs all matter. But there is a question about ownership running through them: how does the accumulated work of millions become a machine controlled by a few? Marx gives us a way to think about that transformation.</p>
<p><img src="https://drbenvincent.github.io/img/dead-labor.png" class="img-fluid" alt="An engraving of a giant mechanical hand built from gears, pages, and smaller hands. Red strings bind the hand to five workers walking uphill beside a smoking factory, under a red sun."></p>
<section id="the-oldest-story-in-capitalism" class="level2">
<h2 class="anchored" data-anchor-id="the-oldest-story-in-capitalism">The oldest story in capitalism</h2>
<p>Marx’s central claim in <em>Capital</em> is that capitalists profit through <a href="https://en.wikipedia.org/wiki/Surplus_value">surplus value</a>: the gap between the value workers create and the wages they receive <span class="citation" data-cites="marx1867capital">(Marx 1867)</span>. Machinery raises productivity. Ownership gives capitalists a claim on the profits it helps generate, and power over how the gains are shared. He called capital dead labour: past work put to use in the production process by living workers. Machinery gives that past work a physical form. When someone else owns it, it stands over the people using it.</p>
<p>Now look at a large language model. It is trained on billions of pages of text and code, the products of countless writers, programmers, artists and forum commenters. In Marx’s terms, it’s dead labour on a scale he could scarcely have imagined: the cognitive output of a civilisation, compressed into weights and sold back as a subscription.</p>
</section>
<section id="enclosing-the-commons-of-the-mind" class="level2">
<h2 class="anchored" data-anchor-id="enclosing-the-commons-of-the-mind">Enclosing the commons of the mind</h2>
<p>Marx described the enclosure of common land as part of <a href="https://www.marxists.org/archive/marx/works/1867-c1/ch26.htm">primitive accumulation</a>: the process that separated people from the means of making a living and forced them into wage work. Land they had used in common became someone else’s property.</p>
<p>Much of the internet grew through people sharing knowledge, writing code and answering one another’s questions. AI firms have harvested that shared work, along with copyrighted books that were never freely offered to the public <span class="citation" data-cites="usco2025training">(U.S. Copyright Office 2025)</span>. They have used it to build proprietary models, then charged for access.</p>
<p>The analogy with enclosure has a limit. Training a model does not, by itself, fence readers out of the original texts. The fence surrounds the productive capacity built from them: the model that can turn this accumulated knowledge into answers, drafts and code. Its owners decide who can use it, on what terms, and at what price. Customers pay the company; after wages and other costs, any profit belongs to its owners. The people whose shared work helped build the model have no automatic claim on that income.</p>
<p>Marx had a phrase for society’s accumulated knowledge once it becomes a force of production: the <a href="https://www.marxists.org/archive/marx/works/1857/grundrisse/ch14.htm">general intellect</a>. LLMs give that idea a striking contemporary form. The knowledge is social, while control over the machine is private.</p>
<p>That ownership can reach back into the lives of the people whose work made the model possible. A writer or programmer may find their accumulated craft turned into a tool an employer can use to bargain down the price of their next piece of work. Dead labour returns as leverage over the living.</p>
</section>
<section id="the-counterarguments" class="level2">
<h2 class="anchored" data-anchor-id="the-counterarguments">The counterarguments</h2>
<p>Developing, training and serving a model takes real research, engineering and investment. The companies have added something valuable. But that does not settle the terms on which everyone else’s work was taken, or who should control what was built from it. The engineering can be real and the appropriation real too.</p>
<p>Open-weight models complicate the picture. Releasing the trained weights lets others run and adapt a model, subject to its licence, and falling costs broaden access <span class="citation" data-cites="stanford2025aiindex">(Stanford Institute for Human-Centered Artificial Intelligence 2025)</span>. Some smaller models can run on <a href="https://deepmind.google/models/gemma/gemma-3n/">phones and laptops</a>. The largest demand costly hardware, and releasing weights does not distribute the infrastructure needed to train their successors. These are real openings in the fence, but access to a model and control over its future are different things.</p>
</section>
<section id="who-should-own-the-machine" class="level2">
<h2 class="anchored" data-anchor-id="who-should-own-the-machine">Who should own the machine?</h2>
<p>Marx distinguished machinery from its capitalist use. He saw technology that reduces necessary labour as a precondition for a better society: it could shrink the working day and free time for human development. Whether it does so depends on the social relations around it, including who owns it and whose interests govern its use.</p>
<p>A Marxian response today could mean public or cooperative control of models, compute and data, a democratic say over deployment, and gains coming back as shorter hours and higher living standards. LLMs could make us more productive and still leave those questions unresolved. A machine built from our collective work gives us reason to ask for a collective say in its use and a collective share in the wealth it produces.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-marx1867capital" class="csl-entry">
Marx, Karl. 1867. <em>Capital: A Critique of Political Economy, Volume 1</em>. Translated by Ben Fowkes. London: Penguin (1976).
</div>
<div id="ref-stanford2025aiindex" class="csl-entry">
Stanford Institute for Human-Centered Artificial Intelligence. 2025. <em>Artificial Intelligence Index Report 2025</em>. Stanford University. <a href="https://hai.stanford.edu/assets/files/hai_ai_index_report_2025.pdf">https://hai.stanford.edu/assets/files/hai_ai_index_report_2025.pdf</a>.
</div>
<div id="ref-usco2025training" class="csl-entry">
U.S. Copyright Office. 2025. <em>Copyright and Artificial Intelligence, Part 3: Generative AI Training (Pre-Publication Version)</em>. U.S. Copyright Office. <a href="https://www.copyright.gov/ai/Copyright-and-Artificial-Intelligence-Part-3-Generative-AI-Training-Report-Pre-Publication-Version.pdf">https://www.copyright.gov/ai/Copyright-and-Artificial-Intelligence-Part-3-Generative-AI-Training-Report-Pre-Publication-Version.pdf</a>.
</div>
</div>


</section>

 ]]></description>
  <category>ai</category>
  <category>economics</category>
  <guid>https://drbenvincent.github.io/posts/dead-labour-reanimated.html</guid>
  <pubDate>Thu, 05 Nov 2026 00:00:00 GMT</pubDate>
  <media:content url="https://drbenvincent.github.io/img/dead-labor.png" medium="image" type="image/png" height="81" width="144"/>
</item>
<item>
  <title>Shipping a major feature in pathmc in a day: a case study in agentic engineering</title>
  <dc:creator>Benjamin Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/pathmc-agentic-feature-delivery.html</link>
  <description><![CDATA[ 





<section id="one-day-ten-pull-requests-one-release" class="level2">
<h2 class="anchored" data-anchor-id="one-day-ten-pull-requests-one-release">One day, ten pull requests, one release</h2>
<p>At 08:45, <code>pathmc</code> had one way to answer a causal question. By 15:00, it had a second estimator, a shared interpretation layer, four documentation pages, a threefold CI speedup, and a new release. Nine pull requests had landed, and the whole thing cost $32.44 in model inference.</p>
<p>The agents kept working while I reviewed their output, handled the decisions that required domain expertise, and even had lunch cooked for me. The result is now available in the <a href="https://pathmc.pymc-labs.com"><code>pathmc</code> documentation</a>. This is the story of how that day unfolded, and what I learned about making AI-assisted engineering move quickly without handing over the important decisions.</p>
</section>
<section id="the-feature" class="level2">
<h2 class="anchored" data-anchor-id="the-feature">The feature</h2>
<p><a href="https://pathmc.pymc-labs.com"><code>pathmc</code></a> is a Bayesian causal inference library. Until this morning it had exactly one way of answering a causal question: build a structural causal model, encode the full data-generating process as a system of equations, and reason about interventions by surgically replacing nodes in that system with <code>do()</code>. That approach is powerful and principled. It is also a big ask. You have to be willing to write down the whole mechanism.</p>
<p>Most people doing applied causal work don’t start there. They start from a DAG, identify a backdoor adjustment set, fit an outcome regression conditioning on that set, and read off the effect by contrasting predictions under different treatment values. That is the language of the potential outcomes literature, of <code>dowhy</code>, of <code>marginaleffects</code>. It is what a large fraction of practitioners already know.</p>
<p>Today <code>pathmc</code> grew that second estimation approach natively: an <code>AdjustmentModel</code> that takes a DAG and an adjustment set, fits a Bayesian outcome regression, and exposes backdoor-identified estimands. Alongside it, a shared interpret layer containing <code>predictions</code>, <code>comparisons</code>, and <code>slopes</code> works identically whether you came in through the SCM door or the adjustment door, so the two estimators produce comparable output on the same problem.</p>
<p>That is not a feature. That’s a second front door to the library, plus the plumbing that makes both doors lead to the same room. The estimand semantics have to be right, the identification has to be enforced rather than assumed, and the docs have to teach a user which door to walk through and why. Getting all of that from an idea to a merged, documented, released state between breakfast and the school run is the thing this post is about.</p>
</section>
<section id="the-process" class="level2">
<h2 class="anchored" data-anchor-id="the-process">The process</h2>
<section id="starting-from-a-plan-not-a-prompt" class="level3">
<h3 class="anchored" data-anchor-id="starting-from-a-plan-not-a-prompt">Starting from a plan, not a prompt</h3>
<p>The day did not begin with “implement regression adjustment.” It began with about an hour of hard conversation with what I came to think of as the <strong>orchestrator agent</strong>, Grok 4.6 High Fast, held in one long-lived session, given the birds-eye view and never asked to write production code.</p>
<p>The output of that hour was a real design, decomposed into six child issues: construction and fit, the interpret API, a docs retcon, two new concept pages, and a figure-first gallery.</p>
<p>That hour was mostly Q&amp;A. What is the public API? Does <code>AdjustmentModel</code> share a base class with <code>PathModel</code> or just an interface? What exactly does <code>comparisons</code> mean when the estimator is an outcome regression rather than an SCM? Which of these can proceed in parallel and which are genuinely blocked?</p>
<p>I want to be blunt about why this worked, because it is the load-bearing part of the whole day: <strong>I already understood the causal concepts.</strong> I was not learning backdoor adjustment from an agent. I was making API and scope decisions in a domain I know well, at the speed I can make them, which is fast. Every one of those decisions became a constraint that the worker agents could not get wrong, because it was written down in an issue before any of them started.</p>
<p>The decomposition mattered as much as the design. Six issues with explicit dependency structure meant that at any moment I could see which work was unblocked, and unblocked work mapped one-to-one onto an agent I could launch.</p>
</section>
<section id="worker-agents-in-parallel-worktrees" class="level3">
<h3 class="anchored" data-anchor-id="worker-agents-in-parallel-worktrees">Worker agents in parallel worktrees</h3>
<p>Implementation went to a different model, Composer 2.5, with one agent per issue, each in its own git worktree, running locally and in parallel.</p>
<p>The loop each agent ran was fixed:</p>
<ol type="1">
<li>Implement the issue.</li>
<li>Open a PR.</li>
<li>A <strong>sub-agent reviews the PR and comments on it.</strong></li>
<li>The original agent addresses the review comments and reports what it changed.</li>
<li>Repeat from step 3 until the reviewer is satisfied, capped at three rounds.</li>
</ol>
<p>The first wave produced an <code>AdjustmentModel</code> for backdoor outcome regression and a shared interpret query layer on <code>PathModel</code>. Both converged after a handful of review rounds.</p>
<p>The self-review loop is the part I would recommend to anyone without reservation. It is fully automated, it needs no supervision, and it works. The code that arrived at my review gate had already been through two or three rounds of adversarial critique by an agent with no ego investment in the original implementation. I was reviewing second or third drafts, not first drafts. The quality difference is not subtle, and the cost of those extra rounds is rounding error against the cost of me reading a bad diff.</p>
<p>Once the first wave landed, three more agents went out in parallel, followed by a final agent handling the remaining documentation work.</p>
</section>
<section id="the-side-quest-that-paid-for-itself" class="level3">
<h3 class="anchored" data-anchor-id="the-side-quest-that-paid-for-itself">The side quest that paid for itself</h3>
<p>Somewhere in the first wave, CI became the bottleneck. Recent successful runs were taking 32 to 34 minutes, so I put one agent on diagnosis while the feature work continued. PyTensor compile time pointed to parallelizing the suite with <code>pytest-xdist</code>, cutting the full job to 11.7 minutes.</p>
<p>That detour bought back time on every subsequent pull request. <strong>Fixing your own tooling mid-task stops being a distraction when the main work continues in parallel.</strong></p>
</section>
<section id="docs-as-a-first-class-deliverable" class="level3">
<h3 class="anchored" data-anchor-id="docs-as-a-first-class-deliverable">Docs as a first-class deliverable</h3>
<p>Four of the six child issues were docs. That was deliberate. A second estimation approach that nobody can find their way into is not shipped.</p>
<p>The docs work produced:</p>
<ul>
<li>A concepts page comparing SCM and regression adjustment <strong>on one shared problem</strong>, so the reader sees two estimators answer the same question rather than two disconnected tutorials.</li>
<li>A retcon pass updating the existing estimation-approaches and comparison pages, and the internal skill, to acknowledge that adjustment is now native rather than something you hand-roll.</li>
<li>A concepts page for predictions, comparisons and slopes.</li>
<li>A figure-first interpret gallery.</li>
</ul>
<p>This is where my time went, and where the day slowed down. I read every page manually. The SCM-vs-adjustment page (<code>/user-guide/scm-vs-adjustment.html</code>) was very good on the first pass, and I suspect a private skill encoding how I want causal material explained deserves much of the credit there. The estimation-approaches page was good but not right, so I had the orchestrator introduce one DAG with a graphviz figure, then illustrate both estimators on it.</p>
<p>The predictions/comparisons/slopes page I was not happy with. It did not match my vision. So another agent produced a figure-first gallery. Much better.</p>
<p>Note the pattern. I did not open an editor and fix the docs. I read them, articulated <em>what was wrong relative to a vision I hold</em>, and let the orchestrator turn that into a scoped issue that a worker agent could close. My contribution was taste, expressed as an issue.</p>
<p>Velocity in this phase was visibly lower than in the implementation phase, and that is not a failure. Manual docs review and housekeeping are the steps where a human is actually required, and they are the steps that cannot be parallelized away. By the last docs review my brain was flagging and I got myself a coffee, which is roughly the honest signal that you have hit the end of a productive day.</p>
</section>
<section id="wrapping-up" class="level3">
<h3 class="anchored" data-anchor-id="wrapping-up">Wrapping up</h3>
<p>Final checks, including every new public method and function present in the API reference, the version bump, and the changelog, went to the orchestrator, because after seven hours it is the only participant with the whole picture in one context. That became the release wrap-up.</p>
<p>The docs go live on merge. The functionality does not reach users until a release, so 0.3.0 gets cut and the day is done.</p>
</section>
</section>
<section id="what-it-cost" class="level2">
<h2 class="anchored" data-anchor-id="what-it-cost">What it cost</h2>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th>tokens</th>
<th>spend</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>composer-2.5</code> (workers)</td>
<td>49.1M</td>
<td>$11.56</td>
</tr>
<tr class="even">
<td><code>cursor-grok-4.6-high-fast</code> (orchestrator)</td>
<td>35.9M</td>
<td>$20.88</td>
</tr>
<tr class="odd">
<td><strong>total</strong></td>
<td><strong>85.0M</strong></td>
<td><strong>$32.44</strong></td>
</tr>
</tbody>
</table>
<p>Caveat on the orchestrator line: Grok 4.6 High Fast shipped yesterday and is currently at 50% off, so the real-world number is roughly double.</p>
<p>Call it $32 of inference and six and a quarter hours of my attention for a second estimation approach, a shared interpret layer, four documentation pages, a 3× CI speedup and a release.</p>
<p>The token split is the interesting number. The orchestrator burned 42% of the tokens without writing production code. Planning, decomposition, scope arbitration and final housekeeping are not overhead you optimize away; they are where the leverage is. The workers were cheap precisely because the thinking had already been done.</p>
</section>
<section id="lessons" class="level2">
<h2 class="anchored" data-anchor-id="lessons">Lessons</h2>
<p><strong>Domain expertise is the multiplier, not the model.</strong> I moved fast because I know causal inference. Every scope question, every API judgement, every “no, that’s not what a comparison means here” landed in seconds rather than in a research detour. Agents make an expert dramatically faster. I have no evidence they make a novice into an expert, and today is not that experiment.</p>
<p><strong>Plan in one long-lived context, implement in many short ones.</strong> The orchestrator held the design and dependency graph all day. The workers each held exactly one issue. Neither could have done the other’s job: a worker with the whole picture loses focus, an orchestrator that writes code loses the plot.</p>
<p><strong>The idea existed; the morning turned it into work packages.</strong> The core concept was already developed before today. What the first hour actually produced was the translation from concept to six independently-executable issues with an explicit dependency order. That translation is the skill. Handing an agent “add regression adjustment” would have produced a mess.</p>
<p><strong>Automated review is free quality, adopt it immediately.</strong> A reviewer sub-agent commenting on the PR, the implementer addressing the comments, capped at three rounds, no human in the loop. Fully automated, and it worked every time. Everything reaching my review gate was a second or third draft.</p>
<p><strong>Fix your tooling mid-flight.</strong> A 32-minute CI cycle would have capped the whole day. Fixing it cost one parallel agent and bought back time on every subsequent PR. Because the fix ran in parallel with the feature work, it cost almost nothing in wall clock.</p>
<p><strong>Taste is expressed as issues, not as edits.</strong> Three separate times I read generated docs, disliked something specific, and converted that into a filed issue instead of a manual edit. That kept me operating at the level where I add value and kept the agents doing the typing.</p>
<p><strong>The manual bits were exactly the bits I’d automate next.</strong> Two things ate my day and neither was interesting: waiting for CI to finish, and resolving merge conflicts. Both are highly automatable and I would structure them differently next time: a proper merge queue, agents that rebase and resolve their own conflicts without me shuttling worktrees around. This bit me repeatedly, since a workflow built on many parallel branches merged in sequence generates conflicts by construction.</p>
<p><strong>But I’m not handing over the merge button yet.</strong> Review is automated, implementation is automated, conflict resolution should be automated. Merging to <code>main</code> stays mine. That is not a technical limitation, it is where I currently want the human gate to sit, and the honest version of an agentic workflow post says which gates you kept, not just which ones you removed.</p>


</section>

 ]]></description>
  <category>software</category>
  <category>ai</category>
  <category>engineering</category>
  <guid>https://drbenvincent.github.io/posts/pathmc-agentic-feature-delivery.html</guid>
  <pubDate>Wed, 12 Aug 2026 23:00:00 GMT</pubDate>
  <media:content url="https://drbenvincent.github.io/img/pathmc-agent-faces.png" medium="image" type="image/png" height="81" width="144"/>
</item>
<item>
  <title>You Don’t Understand the ‘Chart of the Century’</title>
  <dc:creator>Ben Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/baumol-cost-disease.html</link>
  <description><![CDATA[ 





<section id="the-puzzle" class="level2">
<h2 class="anchored" data-anchor-id="the-puzzle">The puzzle</h2>
<p>Mark Perry’s so-called “chart of the century” <span class="citation" data-cites="perry2020chart">(2020)</span> shows a striking divergence in US prices since 2000. Televisions, clothing, software, and toys have all fallen sharply in real terms. Hospital stays, college tuition, and childcare have risen significantly.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://drbenvincent.github.io/img/chart-of-the-century.jpg" class="img-fluid figure-img" alt="A line chart showing US price changes since 2000. Hospital services, college tuition, and childcare have risen sharply. Televisions, software, and clothing have fallen. The CPI sits in between."></p>
<figcaption>Mark Perry’s “chart of the century”: the empirical pattern that Baumol’s cost disease explains from first principles. Source: <span class="citation" data-cites="perry2020chart">Perry (2020)</span>.</figcaption>
</figure>
</div>
<p>One popular explanation runs along supply-side lines and has been formalised as “cost disease socialism” <span class="citation" data-cites="hammond2021costdisease">(Hammond et al. 2021)</span>. On this view, the expensive sectors share a common feature: heavy government involvement. Subsidies – insurance mandates, Medicare and Medicaid, federally backed student loans – boost demand, while licensing restrictions, worker-to-child ratio regulations, and other supply-side constraints prevent quantity from expanding to meet it. When demand rises but supply cannot, prices rise instead. The diagnosis: government simultaneously inflates demand and suppresses supply. Remove the distortions, and prices would fall.</p>
<p>This account is not entirely wrong; regulatory constraints and subsidies do amplify costs. But it runs into a serious problem: the <em>pattern</em> of divergence precedes many of these policies and appears across countries with radically different healthcare and education systems. It does not explain why this same fan-shape emerges in Canada, Germany, and the UK, where the mechanisms of government involvement are entirely different.<sup>1</sup> A structural explanation is needed, one that operates below the level of any particular policy regime <span class="citation" data-cites="helland2019prices">(Helland and Tabarrok 2019)</span>.</p>
<p>Baumol’s cost disease is that explanation. It requires no market failure, regulatory capture, or administrative bloat to produce the divergence. It needs only three ingredients, each of which is uncontroversially present in any modern economy. Understanding this <em>should</em> radically change your views on why some sectors get more expensive, and therefore how and if you think it can be fixed.</p>
</section>
<section id="baumols-cost-disease" class="level2">
<h2 class="anchored" data-anchor-id="baumols-cost-disease">Baumol’s cost disease</h2>
<p>William Baumol and William Bowen identified the mechanism in the 1960s while studying something apparently unrelated: the economics of the performing arts <span class="citation" data-cites="baumol1966performing baumol_video_yt">(Baumol and Bowen 1966; Sharpe 2026)</span>.</p>
<p>A string quartet performing Beethoven requires the same four musicians and the same amount of time to perform as it did in 1800. There is no way to automate it without profoundly changing the nature of the performance. But despite zero room for productivity gains, musicians’ wages must rise over time. Why?</p>
<p>If wages in manufacturing increase because automation makes factory workers more productive, wages in <em>all</em> sectors must eventually follow; otherwise the musicians quit and go work elsewhere. The cost of a concert ticket therefore rises relentlessly, even though nothing about the performance has become less efficient.</p>
<p>Baumol called this <strong>cost disease</strong>. Three ingredients produce it:</p>
<ol type="1">
<li><strong>Uneven productivity growth.</strong> Some sectors achieve large annual gains through automation and scale. Others, such as those focussing on human services, are much less ammenable to productivity improvements.</li>
<li><strong>Competitive labour markets.</strong> Workers migrate toward higher-paying sectors, which are typically the higher-productivity sectors, so wages rise economy-wide.<sup>2</sup></li>
<li><strong>Unit cost divergence.</strong> Higher wages with stagnant productivity means higher cost per unit of output. Higher wages with rising productivity holds cost down.<sup>3</sup></li>
</ol>
<p>The Perry chart is what this looks like after decades of compounding.</p>
</section>
<section id="a-minimal-model" class="level2">
<h2 class="anchored" data-anchor-id="a-minimal-model">A minimal model</h2>
<p>The formalization below follows <span class="citation" data-cites="baumol1967macroeconomics">Baumol (1967)</span>, adapted here to discrete time – Baumol’s original uses continuous-time exponentials <img src="https://latex.codecogs.com/png.latex?e%5E%7Brt%7D">, while the discrete form <img src="https://latex.codecogs.com/png.latex?(1%20+%20g)%5Et"> is algebraically equivalent for the small annual rates typical in practice. Extending from two sectors to <img src="https://latex.codecogs.com/png.latex?N"> is a natural pedagogical step: the logic is identical, and any sector with <img src="https://latex.codecogs.com/png.latex?g_i"> below the progressive benchmark experiences rising unit costs.</p>
<p>The core idea is simple: <strong>unit cost = wage ÷ productivity</strong> (notice this ignores material and energy costs). Here the units are: wage <img src="https://latex.codecogs.com/png.latex?w"> in currency per worker-hour (for example, £/worker-hour), productivity <img src="https://latex.codecogs.com/png.latex?A"> in output units per worker-hour (for example, consultations/worker-hour), and unit cost <img src="https://latex.codecogs.com/png.latex?c"> in currency per output unit (for example, £/consultation).<sup>4</sup> If a worker earns £30 per hour and produces 10 units per hour, each unit costs £3 in labour. If productivity doubles but the wage holds steady, the unit cost halves to £1.50. If the wage doubles but productivity holds steady, the unit cost doubles to £6. Three equations make this precise: 1) productivity , 2) wages, and 3) unit costs, over time.</p>
<p>Baumol’s original model <span class="citation" data-cites="baumol1967macroeconomics">(1967)</span> has just two sectors: one <em>stagnant</em> (zero productivity growth) and one <em>progressive</em> (constant positive growth rate). Here that structure is extended to <img src="https://latex.codecogs.com/png.latex?N"> sectors – classified as progressive or stagnant – so that the simulation can compare multiple real-world sectors simultaneously. Each sector has an annual <strong>productivity growth rate</strong> <img src="https://latex.codecogs.com/png.latex?g_i">: the percentage by which output per worker grows each year.</p>
<p><strong>Productivity</strong> at time <img src="https://latex.codecogs.com/png.latex?t"> is:</p>
<p><img src="https://latex.codecogs.com/png.latex?A_i(t)%20=%20A_i(0)%20%5Ccdot%20(1%20+%20g_i)%5Et"></p>
<p><img src="https://latex.codecogs.com/png.latex?A_i(0)"> is the starting output per worker in sector <img src="https://latex.codecogs.com/png.latex?i">. The factor <img src="https://latex.codecogs.com/png.latex?(1%20+%20g_i)%5Et"> is compound growth, the same arithmetic as interest on a savings account, applied year after year. A sector with <img src="https://latex.codecogs.com/png.latex?g_i%20=%200.05"> doubles its output per worker roughly every 14 years; a sector with <img src="https://latex.codecogs.com/png.latex?g_i%20=%200"> never improves at all.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>A note on sector productivity rates
</div>
</div>
<div class="callout-body-container callout-body">
<p>The productivity rates used in the simulation below are illustrative, not formally estimated from data. Televisions and other consumer electronics are assigned high <img src="https://latex.codecogs.com/png.latex?g"> values reflecting quality-adjusted price declines broadly consistent with Moore’s law, while toys are assigned more moderate but still clearly positive productivity growth. Healthcare is assigned <img src="https://latex.codecogs.com/png.latex?g%20%5Capprox%200.1%5C%25">/yr – one of the most contested parameters in the Baumol literature. Imaging technology, minimally invasive surgery, genomics, and pharmaceutical innovation have driven large improvements in clinical outcomes, but outcome quality is notoriously hard to measure, so official productivity statistics look flat even when patients benefit more per visit.</p>
</div>
</div>
<p><strong>The economy-wide wage</strong> <img src="https://latex.codecogs.com/png.latex?w(t)"> is anchored to productivity growth in the <em>progressive</em> sectors. In Baumol’s original two-sector model, the progressive sector’s wages rise with its productivity, and the stagnant sector must match that wage or lose its workforce to better-paying employers. The common wage is therefore:</p>
<p><img src="https://latex.codecogs.com/png.latex?w(t)%20=%20w(0)%20%5Ccdot%20(1%20+%20g_p)%5Et"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?g_p"> is the growth rate of the single progressive sector. In the <img src="https://latex.codecogs.com/png.latex?N">-sector simulation here there is no single progressive sector, so <img src="https://latex.codecogs.com/png.latex?g_p"> is replaced by <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p">, a weighted average productivity growth rate across a small set of sectors used to approximate Baumol’s progressive frontier:</p>
<p><img src="https://latex.codecogs.com/png.latex?w(t)%20=%20w(0)%20%5Ccdot%20(1%20+%20%5Cbar%7Bg%7D_p)%5Et%20%5Cqquad%20%5Ctext%7Bwhere%7D%20%5Cquad%0A%5Cbar%7Bg%7D_p%20=%20%5Csum_%7Bi%20%5Cin%20%5Cmathcal%7BP%7D%7D%20%5Comega_i%20g_i%20%5Cqquad%20%5Ctext%7Bwith%7D%20%5Cquad%20%5Csum_%7Bi%20%5Cin%20%5Cmathcal%7BP%7D%7D%20%5Comega_i%20=%201"></p>
<p>Here the explorer uses illustrative employment-style weights so that tiny frontier sectors do not mechanically over-determine the economy-wide wage path.</p>
<p>The outside-option mechanism is the same: workers in stagnant sectors can, in principle, migrate to progressive ones, so stagnant-sector employers must pay whatever workers could earn there.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>On terminology: progressive vs stagnant
</div>
</div>
<div class="callout-body-container callout-body">
<p>Baumol’s original model uses the labels <em>progressive</em> and <em>stagnant</em>. In this multi-sector version, it is clearer to separate three ideas that can otherwise get conflated.</p>
<ul>
<li><strong>Productivity growth</strong>: each sector has its own <img src="https://latex.codecogs.com/png.latex?g_i">.</li>
<li><strong>Wage benchmark</strong>: <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p"> is a stand-in for Baumol’s progressive sector, proxied here by a weighted average growth rate over a small set of frontier sectors rather than inferred mechanically from every plotted sector.</li>
<li><strong>Cost direction</strong>: whether a sector’s unit cost rises or falls is an outcome, determined by comparing <img src="https://latex.codecogs.com/png.latex?g_i"> to the wage benchmark.</li>
</ul>
<p>In the baseline equations the benchmark is <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p">, and cost direction follows a threshold rule:</p>
<ul>
<li>If <img src="https://latex.codecogs.com/png.latex?g_i%20%3E%20%5Cbar%7Bg%7D_p">, costs fall.</li>
<li>If <img src="https://latex.codecogs.com/png.latex?g_i%20=%20%5Cbar%7Bg%7D_p">, costs are flat.</li>
<li>If <img src="https://latex.codecogs.com/png.latex?g_i%20%3C%20%5Cbar%7Bg%7D_p">, costs rise.</li>
</ul>
<p>So a sector can have positive productivity growth and still see rising relative costs if its growth rate is below the wage-growth benchmark. In the chart below, colours simply distinguish sectors; they do not encode economic categories.</p>
</div>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Assumptions behind the common wage
</div>
</div>
<div class="callout-body-container callout-body">
<p>Treating <img src="https://latex.codecogs.com/png.latex?w(t)"> as a single economy-wide number is a deliberate simplification. It rests on three assumptions that hold approximately but not perfectly in the real world:</p>
<ol type="1">
<li><strong>Perfect labour mobility.</strong> Workers can move freely between sectors without retraining costs, geographical barriers, or skill mismatches. In practice, a nurse cannot become a software engineer overnight. Wage equalisation happens gradually, over years or decades, not instantaneously.</li>
<li><strong>No labour market segmentation.</strong> The model treats all workers as interchangeable. In reality, care workers, teachers, and musicians occupy distinct labour markets with limited overlap with high-productivity sectors. This partly explains why care workers have historically been paid <em>below</em> economy-wide average wages; the equalisation mechanism is weaker for them.</li>
<li><strong>Wages equal marginal productivity.</strong> Competitive pressure is assumed to keep wages anchored to worker output. Unions, monopsony employers, and licensing boards all disturb this.</li>
<li><strong>Progressive-sector anchoring.</strong> Wages are anchored to a weighted average growth rate of a small set of sectors chosen to play Baumol’s progressive-sector role. Using weights is a pragmatic way to stop very small frontier sectors from over-setting the wage benchmark. However, the choice of which sectors are used in that benchmark, their assigned <img src="https://latex.codecogs.com/png.latex?g"> values, and their weights still shifts every cost curve. Treat absolute cost levels as illustrative rather than precise.</li>
</ol>
<p>To stay close to Baumol’s baseline model, the scenario explorer keeps a common wage benchmark rather than adding a separate labour-market segmentation parameter.</p>
</div>
</div>
<p><strong>Unit cost</strong> in sector <img src="https://latex.codecogs.com/png.latex?i"> (wage per worker divided by output per worker) is:</p>
<p><img src="https://latex.codecogs.com/png.latex?c_i(t)%20=%20%5Cfrac%7Bw(t)%7D%7BA_i(t)%7D%20=%20%5Cfrac%7B(1+%5Cbar%7Bg%7D_p)%5Et%7D%7B(1+g_i)%5Et%7D"></p>
<p>Normalising so that <img src="https://latex.codecogs.com/png.latex?c_i(0)%20=%201"> (which sets <img src="https://latex.codecogs.com/png.latex?w(0)%20=%20A_i(0)%20=%201"> without loss of generality), this ratio measures how expensive sector <img src="https://latex.codecogs.com/png.latex?i"> has become relative to its own starting point. The logic is transparent:</p>
<ul>
<li>If <img src="https://latex.codecogs.com/png.latex?g_i%20%3E%20%5Cbar%7Bg%7D_p">: the denominator grows faster than the numerator, so <strong>costs fall</strong> relative to baseline.</li>
<li>If <img src="https://latex.codecogs.com/png.latex?g_i%20%3C%20%5Cbar%7Bg%7D_p">: the numerator grows faster, so <strong>costs rise</strong>.</li>
<li>If <img src="https://latex.codecogs.com/png.latex?g_i%20=%20%5Cbar%7Bg%7D_p">: unit cost stays flat.</li>
</ul>
<p>The speed of divergence is governed entirely by the gap <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p%20-%20g_i">. Nothing else: no subsidies, no regulatory capture, no administrative bloat. Just the arithmetic of differential productivity growth running forward in time.</p>
<p>The diagram below shows the causal chain. Two things happen simultaneously: fast sectors get more productive, pulling up economy-wide wages; slow sectors cannot match that productivity gain, so their unit costs rise.</p>
</section>
<section id="the-simulation" class="level2">
<h2 class="anchored" data-anchor-id="the-simulation">The simulation</h2>
<p>Below is the Perry chart, generated from scratch using only the model above. Each sector is assigned a plausible illustrative productivity growth rate broadly consistent with empirical orders of magnitude. The chart models only the structural Baumol component – no subsidies, insurance distortions, or regulatory effects are included. The divergence emerges entirely from <img src="https://latex.codecogs.com/png.latex?c_i(t)">, displayed as percent change since 2000 so the visual framing is closer to the original Perry chart.</p>
<p>All sector productivity rates are fixed at their baseline values except computer software, which can be raised to simulate a period of exceptional technological progress (such as the AI productivity gains now being claimed). Raising software productivity raises the progressive-sector average wage rate <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p">, tightening the cost squeeze on slower sectors. In this baseline, <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p"> is proxied by a small basket of faster goods sectors: televisions, clothing, computer software, toys, and food &amp; beverages. The benchmark uses illustrative employment-style weights, so sectors such as food and clothing count more for wage setting than frontier sectors such as televisions. Cost direction is then straightforward: costs rise when sector productivity growth is below <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p">, and fall when it is above. The line colours simply help distinguish sectors visually. Adjust the software control and the chart updates immediately.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="133" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 132;"><span id="cb1-133">viewof g_software_exp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.17</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb1-134">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.090</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.002</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-135">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Computer software g"</span></span>
<span id="cb1-136">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="145" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 144;"><span id="cb2-145">startYear <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2000</span></span>
<span id="cb2-146">T <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">22</span></span>
<span id="cb2-147">years <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> T <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> startYear <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> i)</span>
<span id="cb2-148"></span>
<span id="cb2-149">explorerSectors <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb2-150">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Televisions"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>          <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.180</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-151">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Clothing"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>             <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.040</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-152">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Computer software"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> g_software_exp }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-153">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toys"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>                 <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.100</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-154">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Food &amp; beverages"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>     <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.010</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-155">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Medical care services"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.006</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-156">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"College tuition &amp; fees"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.002</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-157">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Hospital services"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.000</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-158">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Childcare &amp; nursery school"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.004</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-159">]</span>
<span id="cb2-160"></span>
<span id="cb2-161">benchmarkWeights <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>([</span>
<span id="cb2-162">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Televisions"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>          <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.02</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-163">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Clothing"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>             <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.38</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-164">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Computer software"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>    <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.10</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-165">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Toys"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>                 <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-166">  [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Food &amp; beverages"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>     <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.45</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-167">])</span>
<span id="cb2-168">gBarE <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> explorerSectors</span>
<span id="cb2-169">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(s <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> benchmarkWeights<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span>))</span>
<span id="cb2-170">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((sum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> s) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> sum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> benchmarkWeights<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb2-171"></span>
<span id="cb2-172">explorerData <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> explorerSectors<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(s <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span></span>
<span id="cb2-173">  years<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-174">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> elapsedYears <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> startYear</span>
<span id="cb2-175">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Productivity: compound growth</span></span>
<span id="cb2-176">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> A <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pow</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> elapsedYears)</span>
<span id="cb2-177">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Wage: common economy-wide benchmark in the baseline Baumol model</span></span>
<span id="cb2-178">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> effectiveWageGrowth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gBarE</span>
<span id="cb2-179">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb2-180">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>  t<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-181">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">cost</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pow</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> effectiveWageGrowth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> elapsedYears) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> A<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-182">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">pctChange</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pow</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> effectiveWageGrowth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> elapsedYears) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> A <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-183">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>  s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-184">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span>     s<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-185">    }</span>
<span id="cb2-186">  })</span>
<span id="cb2-187">)</span>
<span id="cb2-188"></span>
<span id="cb2-189">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb2-190">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-191">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">height</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">420</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-192">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marginRight</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">160</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-193">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [startYear<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> startYear <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> T] }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-194">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Percent change in unit cost since 2000"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">220</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-195">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb2-196">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-197">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-198">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb2-199">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#aaa"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeDasharray</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"4,3"</span> })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-200">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(explorerData<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-201">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-202">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pctChange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-203">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-204">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-205">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-206">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeOpacity</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-207">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-208">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(explorerData<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectLast</span>({</span>
<span id="cb2-209">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"year"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-210">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"pctChange"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-211">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">z</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-212">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%)`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-213">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-214">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dx</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-215">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-216">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"name"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-217">    }))</span>
<span id="cb2-218">  ]</span>
<span id="cb2-219">})</span></code></pre></div></div>
<div id="fig-ojs-cell-2" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-ojs-cell-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-3" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(c)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-4" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-4-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(d)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-5" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-5-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(e)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-6" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-6-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-6-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(f)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-7" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-7-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-7" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-7-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(g)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-ojs-cell-2-8" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-ojs-cell-2-8-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-8" data-nodetype="expression">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-ojs-cell-2-8-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(h)
</figcaption>
</figure>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-ojs-cell-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Simulated percent change in unit costs since 2000 under Baumol’s cost disease model. Faster-productivity goods sectors raise the common wage benchmark, while slower-productivity service sectors experience rising relative costs. The baseline <img src="https://latex.codecogs.com/png.latex?g"> values used below are: televisions 18.0%, clothing 4.0%, computer software 9.0% by default, toys 10.0%, food &amp; beverages 1.0%, medical care services 0.6%, college tuition &amp; fees 0.2%, hospital services 0.0%, and childcare &amp; nursery school 0.4%. These values are not fitted from data and should not be taken too literally. They are illustrative calibration choices designed to make one core point visible: productivity growth varies a great deal across sectors, and that variation is enough to generate persistent divergence in relative costs.
</figcaption>
</figure>
</div>
</div>
<p>A few things to try:</p>
<ul>
<li>Raise <strong>computer software <img src="https://latex.codecogs.com/png.latex?g"></strong> from 9% toward 10–12%, simulating a period of AI-driven productivity gains. Notice that this <em>widens</em> the divergence: a faster progressive sector pulls <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p"> up, raising the wage floor that all stagnant sectors must meet. More technology in the fast sectors makes healthcare and education relatively <em>more</em> expensive, not less.</li>
<li>Watch <strong>clothing and food</strong> separately. Clothing sits close to the progressive benchmark and therefore stays near flat; food has a much lower <img src="https://latex.codecogs.com/png.latex?g"> and drifts upward more clearly.</li>
</ul>
</section>
<section id="limitations-and-open-questions" class="level2">
<h2 class="anchored" data-anchor-id="limitations-and-open-questions">Limitations and open questions</h2>
<p>This post presents Baumol’s baseline model largely as-is. That keeps the core logic transparent, but also bakes in assumptions worth interrogating.</p>
<p><strong>Labour is the only input.</strong> Unit cost is defined as wage divided by output per worker. Energy, raw materials, capital depreciation, and land are absent. For sectors with high material intensity (pharmaceuticals, hospital equipment, construction) input-cost inflation driven by commodity prices or supply-chain disruptions can dominate the labour-cost channel entirely. The 2020s spike in hospital costs had a significant energy and supply-chain component that the Baumol model simply cannot see. A fuller treatment would express unit cost as a weighted sum over all factor inputs, each with its own productivity trajectory and its own price. That extension would be worth working through; it is not obvious that the divergence result survives unchanged when energy costs are themselves subject to large exogenous shocks.</p>
<p><strong>The wage is a single number.</strong> The model pools all workers into one labour market with one wage. In practice, care workers, surgeons, and software engineers occupy largely segmented markets; the equalisation mechanism operates slowly and incompletely. This post keeps Baumol’s common-wage assumption rather than modelling segmentation dynamics explicitly.</p>
<p><strong>Productivity growth rates are fixed and exogenous.</strong> <img src="https://latex.codecogs.com/png.latex?g_i"> is treated as a constant, but in reality it responds to investment, policy, and technological opportunity. Some sectors speed up, plateau, or slow down as technologies mature and bottlenecks shift. A fuller model would allow <img src="https://latex.codecogs.com/png.latex?g_i"> to vary over time rather than treating each sector’s productivity path as a fixed compound-growth process.</p>
<p><strong>Productivity gains are unlikely to compound forever.</strong> The baseline equations use constant growth rates, which mechanically produce exponential trajectories. That is useful for isolating Baumol’s mechanism, but probably unrealistic in the very long run. If progressive sectors approach near-full automation, labour input per unit can move toward zero, so labour cost no longer falls through wage-productivity dynamics. Unit cost is then bounded below by non-labour inputs: energy, raw materials, and capital maintenance. A natural next modelling step is a multi-input version in which labour shares decline over time and costs converge toward an energy-material floor rather than diverging exponentially forever.</p>
<p><strong>Sectors are treated as independent production units.</strong> The model has no input-output linkages: healthcare does not buy software, education does not consume energy. In a real economy, productivity gains in progressive sectors reduce the cost of inputs to stagnant ones, partially offsetting the wage-floor effect. How large this offset is empirically is an open question.</p>
<p><strong>The demand side is absent.</strong> Nothing in the model determines how much of each sector society actually buys. Cost disease raises relative prices, but whether quantity demanded falls, stays flat, or rises depends on income and price elasticities that the model ignores. As aggregate income rises alongside productivity, the income effect can sustain or even increase demand for expensive stagnant services. Baumol acknowledged this but the basic model does not formalise it.</p>
</section>
<section id="key-takeaways" class="level2">
<h2 class="anchored" data-anchor-id="key-takeaways">Key takeaways</h2>
<ol type="1">
<li><p><strong>The Perry chart shape is predictable from first principles.</strong> Differential productivity growth, combined with competitive labour markets, mechanically produces the fan-shaped divergence we observe. This is the necessary baseline any other explanation must beat.</p></li>
<li><p><strong>Rising costs are not the same as inefficiency.</strong> In stagnant sectors, Baumol’s mechanism represents no decline in productive efficiency. Demanding that a hospital ward achieve the same cost reductions as a semiconductor fab is a category error: one sector can substitute capital for labour at scale, while the other often delivers value through skilled human time itself. Policy responses that treat structural cost growth as waste will therefore be persistently frustrated.</p></li>
<li><p><strong>Faster progressive sectors can widen divergence.</strong> When productivity accelerates in already progressive sectors, <img src="https://latex.codecogs.com/png.latex?%5Cbar%7Bg%7D_p"> rises and pushes up the wage floor for stagnant sectors. The model therefore predicts that some kinds of technological progress can increase relative cost pressure in care-intensive services.</p></li>
<li><p><strong>The political economy layer sits on top.</strong> Subsidies, licensing restrictions, and market power can amplify costs beyond the Baumol floor <span class="citation" data-cites="helland2019prices">(Helland and Tabarrok 2019)</span>. But they cannot explain the <em>shape</em> of the divergence. Baumol is the skeleton; political economy is the flesh.</p></li>
<li><p><strong>Affordability is a distributional question, not a structural one.</strong> The economy can afford stagnant-sector services even as they consume a rising GDP share, if productivity gains from progressive sectors are distributed broadly enough.</p></li>
</ol>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-baumol1967macroeconomics" class="csl-entry">
Baumol, William J. 1967. <span>“Macroeconomics of Unbalanced Growth: The Anatomy of Urban Crisis.”</span> <em>The American Economic Review</em> 57 (3): 415–26.
</div>
<div id="ref-baumol2012cost" class="csl-entry">
Baumol, William J. 2012. <em>The Cost Disease: Why Computers Get Cheaper and Health Care Doesn’t</em>. Yale University Press.
</div>
<div id="ref-baumol1966performing" class="csl-entry">
Baumol, William J., and William G. Bowen. 1966. <em>Performing Arts: The Economic Dilemma</em>. Twentieth Century Fund.
</div>
<div id="ref-hammond2021costdisease" class="csl-entry">
Hammond, Samuel, Daniel Takash, and Steven M. Teles. 2021. <em>Cost Disease Socialism: How Subsidizing Costs While Restricting Supply Drives <span>America</span>’s Fiscal Imbalance</em>. Niskanen Center. <a href="https://www.niskanencenter.org/cost-disease-socialism-how-subsidizing-costs-while-restricting-supply-drives-americas-fiscal-imbalance/">https://www.niskanencenter.org/cost-disease-socialism-how-subsidizing-costs-while-restricting-supply-drives-americas-fiscal-imbalance/</a>.
</div>
<div id="ref-hartwig2008baumol" class="csl-entry">
Hartwig, Jochen. 2008. <span>“What Drives Health Care Expenditure? <span>B</span>aumol’s Model of <span>‘Unbalanced Growth’</span> Revisited.”</span> <em>Journal of Health Economics</em> 27 (3): 603–23. <a href="https://doi.org/10.1016/j.jhealeco.2007.05.006">https://doi.org/10.1016/j.jhealeco.2007.05.006</a>.
</div>
<div id="ref-helland2019prices" class="csl-entry">
Helland, Eric, and Alexander Tabarrok. 2019. <em>Why Are the Prices so Damn High?</em> Mercatus Center at George Mason University. <a href="https://www.mercatus.org/publications/healthcare/why-are-prices-so-damn-high">https://www.mercatus.org/publications/healthcare/why-are-prices-so-damn-high</a>.
</div>
<div id="ref-perry2020chart" class="csl-entry">
Perry, Mark J. 2020. <em>Chart of the Century</em>. <a href="https://www.aei.org/carpe-diem/chart-of-the-century-updated/">https://www.aei.org/carpe-diem/chart-of-the-century-updated/</a>.
</div>
<div id="ref-baumol_video_yt" class="csl-entry">
Sharpe, Oli. 2026. <em>Baumol’s Cost Disease</em>. Video, Go Meta with Oli Sharpe, YouTube. <a href="https://www.youtube.com/watch?v=AwWKvtjQME4">https://www.youtube.com/watch?v=AwWKvtjQME4</a>.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>The temporal-precedence claim is partly logical: Baumol and Bowen identified the mechanism in 1966, and the structural divergence in healthcare and education costs is visible in OECD data from the 1960s and 1970s, before the modern US regulatory architecture (notably the ACA, 2010) was in place. The cross-country claim rests on firmer empirical ground. <span class="citation" data-cites="baumol2012cost">Baumol (2012)</span> presents OECD comparisons showing the same cost pattern in countries with single-payer systems, social insurance systems, and mixed systems. <span class="citation" data-cites="hartwig2008baumol">Hartwig (2008)</span> tests Baumol’s model econometrically across 19 OECD countries from 1970 to 2002 and finds support for the mechanism as a driver of healthcare expenditure growth independent of country-specific policy regimes. The claim is not that policy is irrelevant – it clearly amplifies or dampens costs at the margin – but that policy alone cannot explain a pattern this consistent across such different institutional settings.↩︎</p></li>
<li id="fn2"><p>When a factory installs better machinery, each worker produces more output per shift. Two forces push wages up: firms share productivity surplus to retain workers, and the economy-wide going wage rises as technology spreads across an industry. Economists call the connection between productivity and pay the <a href="https://en.wikipedia.org/wiki/Marginal_product_of_labor"><em>marginal product of labour</em></a>. Competitive pressure keeps wages anchored near this value – firms cannot persistently pay much less (workers leave) or much more (product-market rivals with lower unit costs undercut them). Over the medium run, productivity growth and wage growth track each other closely.↩︎</p></li>
<li id="fn3"><p>If a sector cannot become more productive, why must it raise wages at all? The answer is <em>outside options</em>. A nurse, a teacher, or a concert cellist can, in principle, retrain and take a job in a factory, a logistics firm, or a technology company. These transitions are not frictionless, but they are real. If wages in stagnant sectors stagnated while wages elsewhere rose, a growing share of workers would gradually leave. Employers in stagnant sectors therefore face a floor: pay close to what workers could earn elsewhere, or lose them. Society still needs these services regardless of cost – demand for healthcare and education is relatively <em>inelastic</em> – so providers pass rising labour costs onto consumers, insurers, or government budgets.↩︎</p></li>
<li id="fn4"><p>Dimensional check: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Ctext%7Bcurrency%7D/%5Ctext%7Bworker-hour%7D%7D%7B%5Ctext%7Boutput%7D/%5Ctext%7Bworker-hour%7D%7D%20=%20%5Cfrac%7B%5Ctext%7Bcurrency%7D%7D%7B%5Ctext%7Boutput%7D%7D%0A"> so the expression is dimensionally correct.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>economics</category>
  <category>simulation</category>
  <category>interactive</category>
  <guid>https://drbenvincent.github.io/posts/baumol-cost-disease.html</guid>
  <pubDate>Sat, 30 May 2026 23:00:00 GMT</pubDate>
  <media:content url="https://drbenvincent.github.io/img/chart-of-the-century.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>Why you need more than one lift test per channel</title>
  <dc:creator>Benjamin Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/lift_asymptote.html</link>
  <description><![CDATA[ 





<p>Imagine you ran a clean lift test on one of your channels. The experimental estimate is precise, the MMM calibration works, and the obvious stakeholder question arrives:</p>
<blockquote class="blockquote">
<p>Great. So now we know the incremental ROAS and the saturation ceiling for this channel, right?</p>
</blockquote>
<p>That sounds plausible, but it is usually too strong a claim. A lift test gives you <strong>local causal evidence</strong> about the response near the spend level you tested. But recovering both things the practitioner wants — the steepness <img src="https://latex.codecogs.com/png.latex?%5Clambda">, which drives incremental ROAS, and the ceiling <img src="https://latex.codecogs.com/png.latex?%5Cbeta">, which sets the channel’s absolute contribution — requires more than one local measurement. The ceiling only reveals itself far out in the tail of the curve, well beyond the operating point of a typical lift test.</p>
<p>This post is about that distinction. I will use the two-parameter logistic saturation formulation used in <a href="https://www.pymc-marketing.io/">PyMC-Marketing</a> and show why a single lift test is best understood as a <strong>local anchor</strong> rather than a joint estimator of both parameters. If we want to learn about the ceiling, we need a ladder of experiments at different spend levels that probe different parts of the curve.</p>
<section id="a-lift-test-is-a-local-measurement" class="level2">
<h2 class="anchored" data-anchor-id="a-lift-test-is-a-local-measurement">A lift test is a local measurement</h2>
<p>A lift test does not observe the whole curve. It observes a difference between two operating points:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5CDelta%20y%20=%20f(x%20+%20%5CDelta%20x)%20-%20f(x)%0A"></p>
<p>That is easiest to see geometrically: a lift test is a little triangle sitting on the saturation curve. The base is <img src="https://latex.codecogs.com/png.latex?%5CDelta%20x">, the height is <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y">, and the operating point is the baseline spend <img src="https://latex.codecogs.com/png.latex?x">.</p>
<div id="cell-fig-lift-triangle" class="cell" data-execution_count="2">
<div class="cell-output cell-output-display">
<div id="fig-lift-triangle" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-lift-triangle-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/lift_asymptote_files/figure-html/fig-lift-triangle-output-1.png" width="790" height="391" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-lift-triangle-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: A single lift test as a local chord on a logistic saturation curve with asymptote <img src="https://latex.codecogs.com/png.latex?%5Cbeta">. The base is the spend change <img src="https://latex.codecogs.com/png.latex?%5CDelta%20x"> and the vertical rise is the observed lift <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y"> at operating point <img src="https://latex.codecogs.com/png.latex?x">.
</figcaption>
</figure>
</div>
</div>
</div>
<p>In other words, a lift test directly measures the incremental return on ad-spend (iROAS) at the tested operating point — the ratio of the revenue increment to the spend increment:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BiROAS%7D%20=%20%5Cfrac%7B%5CDelta%20y%7D%7B%5CDelta%20x%7D%20=%20%5Cfrac%7Bf(x%20+%20%5CDelta%20x)%20-%20f(x)%7D%7B%5CDelta%20x%7D%0A"></p>
<p>This is an <em>average slope</em> between two spend levels. Its value depends on where on the curve you are (<img src="https://latex.codecogs.com/png.latex?x">) and how large a step you took (<img src="https://latex.codecogs.com/png.latex?%5CDelta%20x">). If you care about <strong>incremental ROAS near the spend level you tested</strong>, a lift test is excellent.</p>
<p>But the asymptote is different: it is a statement about where the curve eventually plateaus, far out in the tail — a region the lift test never touched.</p>
</section>
<section id="one-clean-lift-test-is-consistent-with-many-different-ceilings" class="level2">
<h2 class="anchored" data-anchor-id="one-clean-lift-test-is-consistent-with-many-different-ceilings">One clean lift test is consistent with many different ceilings</h2>
<p>In this parameterization, the same lift can be written as</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5CDelta%20y%20=%20%5Cbeta%20%5Ccdot%20%5Cleft%5Bh(%5Clambda,%20x%20+%20%5CDelta%20x)%20-%20h(%5Clambda,%20x)%5Cright%5D%0A"></p>
<p>where</p>
<p><img src="https://latex.codecogs.com/png.latex?%0Ah(%5Clambda,%20x)%20=%20%5Cfrac%7B1%20-%20e%5E%7B-%5Clambda%20x%7D%7D%7B1%20+%20e%5E%7B-%5Clambda%20x%7D%7D.%0A"></p>
<p>Now hold <img src="https://latex.codecogs.com/png.latex?x">, <img src="https://latex.codecogs.com/png.latex?%5CDelta%20x">, and <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y"> fixed. You still have one equation involving two unknowns: <img src="https://latex.codecogs.com/png.latex?%5Clambda"> and <img src="https://latex.codecogs.com/png.latex?%5Cbeta">. That is the heart of the problem.</p>
<div id="cell-fig-compatible-curves" class="cell" data-execution_count="3">
<div class="cell-output cell-output-display">
<div id="fig-compatible-curves" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-compatible-curves-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/lift_asymptote_files/figure-html/fig-compatible-curves-output-1.png" width="788" height="391" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-compatible-curves-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Four logistic saturation curves with different (<img src="https://latex.codecogs.com/png.latex?%5Clambda">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">) pairs that all reproduce the same observed lift between <img src="https://latex.codecogs.com/png.latex?x"> and <img src="https://latex.codecogs.com/png.latex?x%20+%20%5CDelta%20x">. One local lift does not uniquely determine the global ceiling <img src="https://latex.codecogs.com/png.latex?%5Cbeta">.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;2 is the key intuition. A shallow curve with a larger ceiling can fit the same local rise as a steeper curve with a smaller ceiling. A single lift test rules out a lot of nonsense, but it does <strong>not</strong> usually collapse the problem to one unique ceiling.</p>
</section>
<section id="the-same-story-in-parameter-space" class="level2">
<h2 class="anchored" data-anchor-id="the-same-story-in-parameter-space">The same story in parameter space</h2>
<p>The cleanest way to see this is to move from curve space to parameter space. For a fixed lift test, every compatible pair satisfies</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbeta(%5Clambda)%20=%20%5Cfrac%7B%5CDelta%20y%7D%7Bh(%5Clambda,%20x%20+%20%5CDelta%20x)%20-%20h(%5Clambda,%20x)%7D.%0A"></p>
<p>Here <img src="https://latex.codecogs.com/png.latex?%5Cbeta(%5Clambda)"> is read as <em>the ceiling value implied by a particular choice of <img src="https://latex.codecogs.com/png.latex?%5Clambda"></em>, given the fixed observed lift <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y">. For every value of <img src="https://latex.codecogs.com/png.latex?%5Clambda"> you might consider, this formula tells you the unique <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> that would reproduce that same lift — so together they trace out a curve rather than a single point.</p>
<p>That is not a single point. It is a whole curve in <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> space.</p>
<div id="cell-fig-constraint-curve" class="cell" data-execution_count="4">
<div class="cell-output cell-output-display">
<div id="fig-constraint-curve" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-constraint-curve-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/lift_asymptote_files/figure-html/fig-constraint-curve-output-1.png" width="787" height="388" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-constraint-curve-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Single-test constraint curve in (<img src="https://latex.codecogs.com/png.latex?%5Clambda">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">) space. Each point on the curve reproduces the same <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y"> exactly, so one clean lift still leaves a one-dimensional family of compatible parameter pairs.
</figcaption>
</figure>
</div>
</div>
</div>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>A useful mental model
</div>
</div>
<div class="callout-body-container callout-body">
<p>One lift test gives you a <strong>constraint curve</strong> in <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> space — not a point estimate for either parameter. With realistic measurement noise, that knife-edge curve broadens into a <strong>probability ridge</strong>, as we formalise below. That is why a single clean experiment can still leave substantial uncertainty about both the shape and the ceiling, even when it is highly informative about the local response near the tested spend level.</p>
</div>
</div>
<p>The picture in Figure&nbsp;3 is also a nice antidote to a common misconception. If the posterior asymptote happens to look reasonable after one lift test, that does not mean the lift <strong>by itself</strong> identified the ceiling. More often, the lift has carved out a sensible ridge and the rest of the model – observational likelihood, priors, and functional form – has done the rest.</p>
</section>
<section id="a-second-lift-changes-the-game" class="level2">
<h2 class="anchored" data-anchor-id="a-second-lift-changes-the-game">A second lift changes the game</h2>
<p>Now add a second experiment at a meaningfully different operating point. That gives you a second equation and therefore a second constraint curve.</p>
<div id="cell-fig-two-constraint-curves" class="cell" data-execution_count="5">
<div class="cell-output cell-output-display">
<div id="fig-two-constraint-curves" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-two-constraint-curves-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/lift_asymptote_files/figure-html/fig-two-constraint-curves-output-1.png" width="787" height="388" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-two-constraint-curves-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Two lift tests at different operating points create two constraint curves in (<img src="https://latex.codecogs.com/png.latex?%5Clambda">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">) space. Their intersection recovers the generating pair, showing why a ladder of experiments is much more informative about the asymptote than a single local lift.
</figcaption>
</figure>
</div>
</div>
</div>
<p>This is the real design insight. If your scientific question is about the <strong>asymptote</strong>, then the relevant experimental program is not “run one lift.” It is closer to “run a ladder of lifts that probes different parts of the curve.”</p>
<p>In practice, the most informative pair is often something like:</p>
<ul>
<li>one lift in a steeper region of the curve,</li>
<li>and another at a meaningfully higher spend where diminishing returns are more pronounced.</li>
</ul>
<p>That does not magically solve every identification problem, but it moves you much closer to learning the global shape rather than just the local slope.</p>
</section>
<section id="from-exact-geometry-to-realistic-uncertainty" class="level2">
<h2 class="anchored" data-anchor-id="from-exact-geometry-to-realistic-uncertainty">From exact geometry to realistic uncertainty</h2>
<p>The constraint curves above assume the lift is observed exactly — a clean, noise-free number. In practice, a lift test is an experiment with uncertainty. The exact causal change in our outcome attributable to the lift is not known with certainty, which means <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5CDelta%20y%7D"> carries uncertainty.</p>
<p>Model the observed lift as <img src="https://latex.codecogs.com/png.latex?%5Chat%7B%5CDelta%20y%7D%20%5Csim%20%5Cmathcal%7BN%7D%5C!%5Cleft(%5CDelta%20y(%5Clambda,%20%5Cbeta),%5C;%20%5Csigma%5E2%5Cright)">, where the true increment <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y(%5Clambda,%20%5Cbeta)%20=%20%5Cbeta%20%5Ccdot%20%5Bh(%5Clambda,%20x%20+%20%5CDelta%20x)%20-%20h(%5Clambda,%20x)%5D"> depends on the parameters. For every point on a fine grid over <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> we can evaluate the log-likelihood</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20p(%5Chat%7B%5CDelta%20y%7D%20%5Cmid%20%5Clambda,%20%5Cbeta)%20=%20-%5Cfrac%7B1%7D%7B2%7D%5Cleft(%5Cfrac%7B%5Chat%7B%5CDelta%20y%7D%20-%20%5CDelta%20y(%5Clambda,%20%5Cbeta)%7D%7B%5Csigma%7D%5Cright)%5E2%20+%20%5Ctext%7Bconst%7D%0A"></p>
<p>and display the result as a heatmap. The constraint curve from the previous section corresponds to the limiting case <img src="https://latex.codecogs.com/png.latex?%5Csigma%20%5Cto%200">; for a realistic experiment it becomes a <strong>probability ridge</strong> — a band of high relative likelihood aligned along the direction of degeneracy.</p>
<div id="cell-fig-likelihood-single" class="cell" data-execution_count="6">
<div class="cell-output cell-output-display">
<div id="fig-likelihood-single" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-likelihood-single-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/lift_asymptote_files/figure-html/fig-likelihood-single-output-1.png" width="745" height="388" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-likelihood-single-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Log-likelihood surface in (<img src="https://latex.codecogs.com/png.latex?%5Clambda">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">) space for a single noisy lift test (<img src="https://latex.codecogs.com/png.latex?%5Csigma"> = 30% of the observed lift). The knife-edge constraint curve from earlier becomes a broad probability ridge under realistic sampling uncertainty.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The ridge in Figure&nbsp;5 is wide along the <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> degeneracy direction and narrow perpendicular to it. The single test is very informative about one specific combination of the two parameters — essentially the incremental ROAS at the tested spend level — but barely constrains the orthogonal combination, which is closer to the global ceiling.</p>
<p>Adding a second lift at a different operating point gives a second likelihood surface. Summing the log-likelihoods gives the joint surface for both experiments together.</p>
<div id="cell-fig-likelihood-joint" class="cell" data-execution_count="7">
<div class="cell-output cell-output-display">
<div id="fig-likelihood-joint" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-likelihood-joint-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/lift_asymptote_files/figure-html/fig-likelihood-joint-output-1.png" width="745" height="388" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-likelihood-joint-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Joint log-likelihood surface for two noisy lift tests at different operating points (<img src="https://latex.codecogs.com/png.latex?x">=0.35 and <img src="https://latex.codecogs.com/png.latex?x">=0.55). The two probability ridges run in different directions, and their intersection concentrates mass near the true parameter pair.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;6 shows the key result in probabilistic terms: two lifts from well-separated operating points triangulate the true pair far more tightly than either experiment alone. This is the realistic, noisy version of the exact constraint-curve intersection in Figure&nbsp;4.</p>
<div class="callout callout-style-default callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>The ridge direction tells you what is and is not learnable
</div>
</div>
<div class="callout-body-container callout-body">
<p>Each likelihood ridge runs roughly along the direction in <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> space that preserves the incremental ROAS at the tested spend level. That direction is what the experiment cannot distinguish on its own. A second experiment at a different spend level has a ridge running in a different direction, and their intersection is where the real information lies.</p>
</div>
</div>
</section>
<section id="what-the-mmm-adds-and-what-it-does-not" class="level2">
<h2 class="anchored" data-anchor-id="what-the-mmm-adds-and-what-it-does-not">What the MMM adds, and what it does not</h2>
<section id="a-calibrated-mmm-does-add-real-information" class="level3">
<h3 class="anchored" data-anchor-id="a-calibrated-mmm-does-add-real-information">A calibrated MMM does add real information</h3>
<p>The toy geometry above intentionally isolates the experiment. A real MMM does not work that way — it combines the experimental constraint with two other sources of information: a prior over <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> and an observational likelihood from the historical spend-and-revenue time series. Each source carves out its own region of plausible parameter values, and the joint posterior is the overlap of all three.</p>
<p>This means a well-specified MMM can produce a meaningfully tighter posterior for <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> than the lift test alone would suggest. That is not a flaw — it is the point of building a model. The key word is <em>joint</em>: the tightening comes from combining sources, not from the lift test having resolved the ambiguity on its own.</p>
</section>
<section id="but-precision-is-not-the-same-as-experimental-identification" class="level3">
<h3 class="anchored" data-anchor-id="but-precision-is-not-the-same-as-experimental-identification">But precision is not the same as experimental identification</h3>
<p>Imagine you feed one lift test into a full MMM and the posterior for <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> comes back looking tight and plausible — maybe even centred close to the true ceiling. It is tempting to conclude that the lift test identified the ceiling. But this can be misleading, because the posterior’s apparent precision may have come from sources that have nothing to do with the experiment:</p>
<ul>
<li><strong>The prior.</strong> If the prior on <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> is narrow, the posterior will be narrow regardless of what the data say. The lift has not done the work; the prior has.</li>
<li><strong>Observational model structure.</strong> The MMM also fits historical spend-and-revenue time series. Tight correlations in that observational data can sharpen the posterior, but observational co-variation is not the same as causal identification. Spend and revenue move together for many reasons besides the true saturation relationship.</li>
</ul>
<p>The likelihood heatmaps in this post are a useful benchmark precisely because they isolate what the <strong>experiment alone</strong> tells you. A lifted spend was randomly assigned, so the resulting <img src="https://latex.codecogs.com/png.latex?%5CDelta%20y"> is causally clean. The width and orientation of that likelihood ridge is an honest picture of experimental information about <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)">. If the full MMM posterior looks substantially tighter than that ridge, you should ask why — and the answer is almost always prior choice or observational model structure, not the lift test itself.</p>
<p>A confident-looking posterior that happens to be near the truth is not the same as having genuinely learned the answer from data. Getting the right answer for the wrong reason is a fragile state: it will not generalise reliably when the prior is misspecified or when the observational correlations shift.</p>
<p>This is why the parameter-space and likelihood plots in this post are worth examining carefully. They make the residual ambiguity from the experiment visible, and show exactly where the rest of the model — priors and observational structure — is still doing the heavy lifting.</p>
</section>
</section>
<section id="takeaways-for-practitioners" class="level2">
<h2 class="anchored" data-anchor-id="takeaways-for-practitioners">Takeaways for practitioners</h2>
<ul>
<li><strong>Single lift</strong>: great for estimating incremental ROAS at the tested operating point; one equation in two unknowns (<img src="https://latex.codecogs.com/png.latex?%5Clambda">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta">).</li>
<li><strong>Likelihood ridge</strong>: with realistic measurement noise, the constraint curve broadens into a probability band in <img src="https://latex.codecogs.com/png.latex?(%5Clambda,%20%5Cbeta)"> space.</li>
<li><strong>Asymptote <img src="https://latex.codecogs.com/png.latex?%5Cbeta"></strong>: a global property of the curve, not recoverable from a single local measurement alone.</li>
<li><strong>Saturation shape <img src="https://latex.codecogs.com/png.latex?%5Clambda"></strong>: controls the steepness of the saturation curve, and therefore incremental ROAS; not individually pinned by a single lift.</li>
<li><strong>Ladder of lifts</strong>: if you care about either the ceiling or the saturation shape, design experiments spanning different spend levels — joint likelihoods triangulate the pair.</li>
<li><strong>Joint identification</strong>: when a calibrated MMM tightens the asymptote after one lift, the observational model and priors are contributing too.</li>
</ul>
<p>If you had budget for exactly one more experiment, where would you place it: near your current spend, or deliberately at a very different operating point to learn more about the curve’s tail?</p>


</section>

 ]]></description>
  <category>marketing</category>
  <category>bayes</category>
  <category>experimentation</category>
  <guid>https://drbenvincent.github.io/posts/lift_asymptote.html</guid>
  <pubDate>Mon, 30 Mar 2026 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Goodness of fit is not the objective in causal-first projects</title>
  <dc:creator>Benjamin Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/goodness_of_fit_not_objective.html</link>
  <description><![CDATA[ 





<p>Imagine an online shop deciding whether to spend more money showing ads to people who have already visited its website. That practice is often called <strong>retargeting</strong> (also called remarketing): after someone visits your site, you show them follow-up ads on other websites/apps to try to bring them back.</p>
<p>The team compares two statistical models trained on past campaign data. In simple terms, both models use information about users (for example past site visits, ad exposures, and engagement signals) to predict an outcome such as whether a user purchases, or how much they spend.</p>
<p>Here is the conflict. <strong>Model A</strong> has slightly worse fit, but it implies the ads do create meaningful extra purchases, which is broadly in line with the team’s expectation that these ads are doing something useful. <strong>Model B</strong> has better goodness of fit, but it implies the ads add little or no extra value.</p>
<p>So which model should the team trust: the one that fits the historical data better, or the one that seems more plausible for the intervention decision they actually need to make?</p>
<p>Why does this matter? Because if the team trusts the better-fit model for a causal decision, they may conclude “retargeting is not doing much” and cut a campaign that is actually helping.</p>
<p>That is the core mistake this post is about. In causal-first work, the question is not:</p>
<blockquote class="blockquote">
<p>❌ Which model best predicts purchases under the current ad-targeting system?</p>
</blockquote>
<p>It is:</p>
<blockquote class="blockquote">
<p>✅ Which model best estimates what will happen if we change the ad-targeting system?</p>
</blockquote>
<p>This post is about that difference, and I will explain each step in plain language as we go.</p>
<p>The key reason this matters is that models here are being used to inform decisions, and decisions are interventions. Prediction models learn how variables co-vary under the current system, but an intervention changes that system (for example by changing who gets exposed to ads) <span class="citation" data-cites="pearl2009causality">(Pearl 2009)</span>. Once the assignment mechanism changes, even strong out-of-sample predictive performance under the old system is not enough; we need a model that is useful for the interventional question, which is exactly the observational-versus-interventional distribution distinction highlighted in the <a href="https://www.pymc.io/projects/examples/en/latest/causal_inference/interventional_distribution.html">PyMC example</a> by <span class="citation" data-cites="vincent2025-interventional-distribution">Vincent (2023)</span>. This is a causal-decision version of a broader point emphasized in statistical modeling: predictive performance and explanatory/structural adequacy are different objectives <span class="citation" data-cites="breiman2001two-cultures shmueli2010explain-predict">(Breiman 2001; Shmueli 2010)</span>.</p>
<p>This post was inspired by Orduz’s collider example showing that higher Bayesian <img src="https://latex.codecogs.com/png.latex?R%5E2"> can coincide with worse causal effect estimation <span class="citation" data-cites="orduz2026-no-r2">(Orduz 2026)</span>. The specific contribution here is to make that lesson operational for model selection in a decision setting: define the causal estimand first, classify candidate features by causal role (proxy, mediator, collider-like bad control), and compare models on both observational fit and the intervention quantity that drives the decision.</p>
<section id="our-running-example-retargeting-and-purchases" class="level2">
<h2 class="anchored" data-anchor-id="our-running-example-retargeting-and-purchases">Our running example: retargeting and purchases</h2>
<p>To make the rest of the post concrete, I will use one running example: an online shop deciding whether retargeting ads cause extra purchases. The core causal question is “What is the causal effect of retargeting exposure on purchases?” At the highest level, this is the relationship we care about:</p>
<div class="cell" data-fig-height="2" data-layout-align="default">
<div class="cell-output-display">
<div id="fig-retargeting-core-question" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-retargeting-core-question-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="192" viewbox="0.00 0.00 155.52 120.00" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 116)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-116 151.52,-116 151.52,4 -4,4"></polygon>
<!-- RetargetingExposure -->
<g id="node1" class="node">
<title>RetargetingExposure</title>
<path fill="#d7e7f7" stroke="#444444" d="M135.29,-112C135.29,-112 12.24,-112 12.24,-112 6.24,-112 0.24,-106 0.24,-100 0.24,-100 0.24,-88 0.24,-88 0.24,-82 6.24,-76 12.24,-76 12.24,-76 135.29,-76 135.29,-76 141.29,-76 147.29,-82 147.29,-88 147.29,-88 147.29,-100 147.29,-100 147.29,-106 141.29,-112 135.29,-112"></path>
<text text-anchor="middle" x="73.76" y="-89.8" font-family="Helvetica,sans-Serif" font-size="14.00">RetargetingExposure</text>
</g>
<!-- Purchase -->
<g id="node2" class="node">
<title>Purchase</title>
<path fill="#dcefd9" stroke="#444444" d="M99.41,-36C99.41,-36 48.12,-36 48.12,-36 42.12,-36 36.12,-30 36.12,-24 36.12,-24 36.12,-12 36.12,-12 36.12,-6 42.12,0 48.12,0 48.12,0 99.41,0 99.41,0 105.41,0 111.41,-6 111.41,-12 111.41,-12 111.41,-24 111.41,-24 111.41,-30 105.41,-36 99.41,-36"></path>
<text text-anchor="middle" x="73.76" y="-13.8" font-family="Helvetica,sans-Serif" font-size="14.00">Purchase</text>
</g>
<!-- RetargetingExposure&#45;&gt;Purchase -->
<g id="edge1" class="edge">
<title>RetargetingExposure-&gt;Purchase</title>
<path fill="none" stroke="black" d="M73.76,-75.84C73.76,-67.06 73.76,-56.16 73.76,-46.27"></path>
<polygon fill="black" stroke="black" points="77.26,-46.07 73.76,-36.07 70.26,-46.07 77.26,-46.07"></polygon>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-retargeting-core-question-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Core causal question for the running example: what is the effect of retargeting exposure on purchase?
</figcaption>
</figure>
</div>
</div>
</div>
<p>The complication is that real systems contain many other variables (such as browsing behavior, engagement signals, and targeting rules). Adding those variables to a model can improve predictive fit, but some of them can also bias the causal estimate if they are used in the wrong way.</p>
<p>That is the main tension we will unpack in the next sections: a model can become better at predicting observed data while becoming worse for estimating the causal effect we actually care about.</p>
<p>Roadmap for the rest of the post: first I will define the causal target and show the baseline confounding problem, then I will show two common bad-control mistakes (mediator and collider), and finally I will compare two regression strategies in one simulation to show how fit and causal usefulness can diverge.</p>
<p>Before we look at examples of bad controls, we need to make the baseline causal problem explicit: confounding.</p>
<section id="causal-complication-confounding" class="level3">
<h3 class="anchored" data-anchor-id="causal-complication-confounding">Causal complication: confounding</h3>
<p>Suppose we want to estimate the causal effect of showing follow-up ads (retargeting) on purchases. The core problem in this example is <strong>confounding</strong>: <code>Intent</code> is a confounding variable because it affects both who gets shown ads and who purchases.</p>
<p>That is a problem for causal estimation because a simple comparison of users who saw the ad vs users who did not will mix together:</p>
<ul>
<li>the effect of the ad itself, and</li>
<li>pre-existing differences in how likely people were to buy.</li>
</ul>
<p>In this example, that pre-existing difference is <code>Intent</code> (how ready someone already was to buy). The <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">Directed Acyclic Graph</a> (DAG) below makes that problem visible.</p>
<div class="cell" data-fig-height="3.5" data-layout-align="default">
<div class="cell-output-display">
<div id="fig-retargeting-confounding" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-retargeting-confounding-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="336" viewbox="0.00 0.00 310.14 188.00" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 184)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-184 306.14,-184 306.14,4 -4,4"></polygon>
<!-- Intent -->
<g id="node1" class="node">
<title>Intent</title>
<path fill="#e6e6e6" stroke="#444444" stroke-dasharray="5,2" d="M220.57,-180C220.57,-180 190.57,-180 190.57,-180 184.57,-180 178.57,-174 178.57,-168 178.57,-168 178.57,-156 178.57,-156 178.57,-150 184.57,-144 190.57,-144 190.57,-144 220.57,-144 220.57,-144 226.57,-144 232.57,-150 232.57,-156 232.57,-156 232.57,-168 232.57,-168 232.57,-174 226.57,-180 220.57,-180"></path>
<text text-anchor="middle" x="205.57" y="-157.8" font-family="Helvetica,sans-Serif" font-size="14.00">Intent</text>
</g>
<!-- PriorSiteVisits -->
<g id="node2" class="node">
<title>PriorSiteVisits</title>
<path fill="#ffffff" stroke="#444444" d="M91.2,-108C91.2,-108 11.93,-108 11.93,-108 5.93,-108 -0.07,-102 -0.07,-96 -0.07,-96 -0.07,-84 -0.07,-84 -0.07,-78 5.93,-72 11.93,-72 11.93,-72 91.2,-72 91.2,-72 97.2,-72 103.2,-78 103.2,-84 103.2,-84 103.2,-96 103.2,-96 103.2,-102 97.2,-108 91.2,-108"></path>
<text text-anchor="middle" x="51.57" y="-85.8" font-family="Helvetica,sans-Serif" font-size="14.00">PriorSiteVisits</text>
</g>
<!-- Intent&#45;&gt;PriorSiteVisits -->
<g id="edge1" class="edge">
<title>Intent-&gt;PriorSiteVisits</title>
<path fill="none" stroke="black" d="M178.39,-148.65C156.32,-138.61 124.67,-124.23 98.52,-112.34"></path>
<polygon fill="black" stroke="black" points="99.71,-109.04 89.16,-108.09 96.81,-115.41 99.71,-109.04"></polygon>
</g>
<!-- RetargetingExposure -->
<g id="node3" class="node">
<title>RetargetingExposure</title>
<path fill="#d7e7f7" stroke="#444444" d="M267.09,-108C267.09,-108 144.04,-108 144.04,-108 138.04,-108 132.04,-102 132.04,-96 132.04,-96 132.04,-84 132.04,-84 132.04,-78 138.04,-72 144.04,-72 144.04,-72 267.09,-72 267.09,-72 273.09,-72 279.09,-78 279.09,-84 279.09,-84 279.09,-96 279.09,-96 279.09,-102 273.09,-108 267.09,-108"></path>
<text text-anchor="middle" x="205.57" y="-85.8" font-family="Helvetica,sans-Serif" font-size="14.00">RetargetingExposure</text>
</g>
<!-- Intent&#45;&gt;RetargetingExposure -->
<g id="edge2" class="edge">
<title>Intent-&gt;RetargetingExposure</title>
<path fill="none" stroke="black" d="M205.57,-143.7C205.57,-135.98 205.57,-126.71 205.57,-118.11"></path>
<polygon fill="black" stroke="black" points="209.07,-118.1 205.57,-108.1 202.07,-118.1 209.07,-118.1"></polygon>
</g>
<!-- Purchase -->
<g id="node4" class="node">
<title>Purchase</title>
<path fill="#dcefd9" stroke="#444444" d="M290.21,-36C290.21,-36 238.92,-36 238.92,-36 232.92,-36 226.92,-30 226.92,-24 226.92,-24 226.92,-12 226.92,-12 226.92,-6 232.92,0 238.92,0 238.92,0 290.21,0 290.21,0 296.21,0 302.21,-6 302.21,-12 302.21,-12 302.21,-24 302.21,-24 302.21,-30 296.21,-36 290.21,-36"></path>
<text text-anchor="middle" x="264.57" y="-13.8" font-family="Helvetica,sans-Serif" font-size="14.00">Purchase</text>
</g>
<!-- Intent&#45;&gt;Purchase -->
<g id="edge3" class="edge">
<title>Intent-&gt;Purchase</title>
<path fill="none" stroke="black" d="M232.83,-152.77C253.57,-144.91 280.67,-130.82 293.57,-108 304.83,-88.06 294.9,-63.1 283.7,-44.69"></path>
<polygon fill="black" stroke="black" points="286.58,-42.7 278.19,-36.23 280.72,-46.52 286.58,-42.7"></polygon>
</g>
<!-- RetargetingExposure&#45;&gt;Purchase -->
<g id="edge4" class="edge">
<title>RetargetingExposure-&gt;Purchase</title>
<path fill="none" stroke="black" d="M220.15,-71.7C227.22,-63.3 235.85,-53.07 243.61,-43.86"></path>
<polygon fill="black" stroke="black" points="246.38,-46.01 250.15,-36.1 241.03,-41.49 246.38,-46.01"></polygon>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-retargeting-confounding-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Retargeting exposure and purchase are confounded by latent intent. <code>PriorSiteVisits</code> is an observed proxy for intent and may help adjustment by partially accounting for pre-treatment differences in intent. But it does not change the estimand (the target quantity being estimated): we still want the causal effect of retargeting exposure on purchase.
</figcaption>
</figure>
</div>
</div>
</div>
<p>The quantity we want is still the <strong>causal impact of retargeting exposure on purchases</strong>. <code>PriorSiteVisits</code> is included to show an important practical point: we often cannot observe intent directly, but we may observe proxies (such as browsing activity) that contain some information about it. Those proxies can sometimes help us adjust for confounding. In the worked example below, this proxy is represented by <code>prior_site_visits</code>, which is measured <strong>before</strong> retargeting exposure is assigned (so it is pre-treatment, not a mediator). These proxies do not change the target question.</p>
<p>Before we look at two failure-mode DAGs, here is the core distinction in one table. The point is not just “prediction vs causality” in the abstract; it is which target is useful for a decision that changes how the system assigns treatment.</p>
<table class="caption-top table">
<colgroup>
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
</colgroup>
<thead>
<tr class="header">
<th>Goal</th>
<th>Typical target</th>
<th>Useful features</th>
<th>Failure mode</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Prediction</strong></td>
<td>“Who will buy?”</td>
<td>Any stable predictive signal</td>
<td>Mistakes correlation for lever</td>
</tr>
<tr class="even">
<td><strong>Causal decision</strong></td>
<td>“What changes if we show the ad?” (extra purchases caused by the ad; often called uplift)</td>
<td>Causally justified adjustment set</td>
<td>Bias from colliders / mediators / leakage</td>
</tr>
</tbody>
</table>
<p>Fit metrics are still useful diagnostics. They are just not the causal objective <span class="citation" data-cites="shmueli2010explain-predict breiman2001two-cultures">(Shmueli 2010; Breiman 2001)</span>.</p>
</section>
</section>
<section id="dag-walkthrough-two-ways-added-variables-can-hurt-causal-estimation" class="level2">
<h2 class="anchored" data-anchor-id="dag-walkthrough-two-ways-added-variables-can-hurt-causal-estimation">DAG walkthrough: two ways added variables can hurt causal estimation</h2>
<p>Adding variables can improve predictive fit while making the causal estimate worse for the estimand we care about. When model outputs drive interventions, these are not just estimation mistakes; they become decision mistakes. The next two DAGs show two common ways that happens:</p>
<ul>
<li>Figure&nbsp;3: a highly predictive variable is post-treatment (mediator)</li>
<li>Figure&nbsp;4: a highly predictive variable is a collider (bad control)</li>
</ul>
<p>Here, “conditioning on” or “controlling for” means including a variable in the regression model as a predictor (or otherwise holding it fixed during estimation). I start with the broader post-treatment/mediator mistake, then return to the collider pattern. For a concise taxonomy of good and bad controls, see <span class="citation" data-cites="cinelli2022good-bad-controls">Cinelli et al. (2022)</span>.</p>
<section id="a.-conditioning-on-a-mediator" class="level3">
<h3 class="anchored" data-anchor-id="a.-conditioning-on-a-mediator">A. Conditioning on a mediator</h3>
<p>There is a common mistake that often looks sensible from a prediction perspective: controlling for variables that happen <em>after</em> the treatment.</p>
<p>Teams often include downstream engagement features because they are close to the outcome and improve prediction. But if your goal is the <strong>total effect</strong> of the ad, those variables can remove part of the very effect you are trying to measure.</p>
<div class="cell" data-fig-height="4.5" data-layout-align="default">
<div class="cell-output-display">
<div id="fig-retargeting-mediator" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-retargeting-mediator-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="432" viewbox="0.00 0.00 239.51 260.00" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-256 235.51,-256 235.51,4 -4,4"></polygon>
<!-- Intent -->
<g id="node1" class="node">
<title>Intent</title>
<path fill="#e6e6e6" stroke="#444444" stroke-dasharray="5,2" d="M149.76,-252C149.76,-252 119.76,-252 119.76,-252 113.76,-252 107.76,-246 107.76,-240 107.76,-240 107.76,-228 107.76,-228 107.76,-222 113.76,-216 119.76,-216 119.76,-216 149.76,-216 149.76,-216 155.76,-216 161.76,-222 161.76,-228 161.76,-228 161.76,-240 161.76,-240 161.76,-246 155.76,-252 149.76,-252"></path>
<text text-anchor="middle" x="134.76" y="-229.8" font-family="Helvetica,sans-Serif" font-size="14.00">Intent</text>
</g>
<!-- RetargetingExposure -->
<g id="node2" class="node">
<title>RetargetingExposure</title>
<path fill="#d7e7f7" stroke="#444444" d="M196.28,-180C196.28,-180 73.23,-180 73.23,-180 67.23,-180 61.23,-174 61.23,-168 61.23,-168 61.23,-156 61.23,-156 61.23,-150 67.23,-144 73.23,-144 73.23,-144 196.28,-144 196.28,-144 202.28,-144 208.28,-150 208.28,-156 208.28,-156 208.28,-168 208.28,-168 208.28,-174 202.28,-180 196.28,-180"></path>
<text text-anchor="middle" x="134.76" y="-157.8" font-family="Helvetica,sans-Serif" font-size="14.00">RetargetingExposure</text>
</g>
<!-- Intent&#45;&gt;RetargetingExposure -->
<g id="edge1" class="edge">
<title>Intent-&gt;RetargetingExposure</title>
<path fill="none" stroke="black" d="M134.76,-215.7C134.76,-207.98 134.76,-198.71 134.76,-190.11"></path>
<polygon fill="black" stroke="black" points="138.26,-190.1 134.76,-180.1 131.26,-190.1 138.26,-190.1"></polygon>
</g>
<!-- SiteEngagement -->
<g id="node3" class="node">
<title>SiteEngagement</title>
<path fill="#fbe1c3" stroke="#444444" d="M107.28,-108C107.28,-108 12.24,-108 12.24,-108 6.24,-108 0.24,-102 0.24,-96 0.24,-96 0.24,-84 0.24,-84 0.24,-78 6.24,-72 12.24,-72 12.24,-72 107.28,-72 107.28,-72 113.28,-72 119.28,-78 119.28,-84 119.28,-84 119.28,-96 119.28,-96 119.28,-102 113.28,-108 107.28,-108"></path>
<text text-anchor="middle" x="59.76" y="-85.8" font-family="Helvetica,sans-Serif" font-size="14.00">SiteEngagement</text>
</g>
<!-- Intent&#45;&gt;SiteEngagement -->
<g id="edge3" class="edge">
<title>Intent-&gt;SiteEngagement</title>
<path fill="none" stroke="black" d="M107.5,-224.77C86.76,-216.91 59.66,-202.82 46.76,-180 36.01,-160.99 40.89,-136.18 47.53,-117.59"></path>
<polygon fill="black" stroke="black" points="50.8,-118.83 51.19,-108.24 44.28,-116.27 50.8,-118.83"></polygon>
</g>
<!-- Purchase -->
<g id="node4" class="node">
<title>Purchase</title>
<path fill="#dcefd9" stroke="#444444" d="M189.4,-36C189.4,-36 138.11,-36 138.11,-36 132.11,-36 126.11,-30 126.11,-24 126.11,-24 126.11,-12 126.11,-12 126.11,-6 132.11,0 138.11,0 138.11,0 189.4,0 189.4,0 195.4,0 201.4,-6 201.4,-12 201.4,-12 201.4,-24 201.4,-24 201.4,-30 195.4,-36 189.4,-36"></path>
<text text-anchor="middle" x="163.76" y="-13.8" font-family="Helvetica,sans-Serif" font-size="14.00">Purchase</text>
</g>
<!-- Intent&#45;&gt;Purchase -->
<g id="edge2" class="edge">
<title>Intent-&gt;Purchase</title>
<path fill="none" stroke="black" d="M162.02,-224.77C182.76,-216.91 209.86,-202.82 222.76,-180 248.17,-135.03 212.04,-77.07 186.11,-44.38"></path>
<polygon fill="black" stroke="black" points="188.5,-41.77 179.45,-36.25 183.08,-46.2 188.5,-41.77"></polygon>
</g>
<!-- RetargetingExposure&#45;&gt;SiteEngagement -->
<g id="edge5" class="edge">
<title>RetargetingExposure-&gt;SiteEngagement</title>
<path fill="none" stroke="black" d="M116.22,-143.7C106.96,-135.05 95.6,-124.45 85.5,-115.03"></path>
<polygon fill="black" stroke="black" points="87.78,-112.37 78.08,-108.1 83.01,-117.49 87.78,-112.37"></polygon>
</g>
<!-- RetargetingExposure&#45;&gt;Purchase -->
<g id="edge4" class="edge">
<title>RetargetingExposure-&gt;Purchase</title>
<path fill="none" stroke="black" d="M138.26,-143.87C143.22,-119.56 152.36,-74.82 158.24,-46.01"></path>
<polygon fill="black" stroke="black" points="161.68,-46.69 160.25,-36.19 154.82,-45.29 161.68,-46.69"></polygon>
</g>
<!-- SiteEngagement&#45;&gt;Purchase -->
<g id="edge6" class="edge">
<title>SiteEngagement-&gt;Purchase</title>
<path fill="none" stroke="black" d="M85.2,-71.88C98.55,-62.89 115.08,-51.76 129.54,-42.03"></path>
<polygon fill="black" stroke="black" points="131.88,-44.68 138.22,-36.19 127.97,-38.87 131.88,-44.68"></polygon>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-retargeting-mediator-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: If SiteEngagement is downstream of exposure and you want the total effect of exposure, controlling for SiteEngagement blocks part of the causal path.
</figcaption>
</figure>
</div>
</div>
</div>
<p>In this DAG, <code>SiteEngagement</code> sits on the pathway from exposure to purchase. That makes it a <strong>mediator</strong> (a variable through which some of the treatment effect flows).</p>
<p>If your estimand (the quantity you want to estimate) is the <em>total effect</em> of retargeting upon purchase behaviour, controlling for downstream engagement is usually the wrong move. It often improves predictive fit because engagement is close to purchase, but it mechanically removes part of the effect you are trying to estimate.</p>
</section>
<section id="b.-conditioning-on-a-collider" class="level3">
<h3 class="anchored" data-anchor-id="b.-conditioning-on-a-collider">B. Conditioning on a collider</h3>
<p>Now consider a second bad-control pattern: a highly predictive variable that is a collider.</p>
<p>To make the timing explicit, think of <code>PostWindowEngagementScore</code> as an intentionally post-window engagement summary (for example, a downstream CRM/analytics feature aggregated after the campaign and purchase window closes). It can be highly predictive and improve fit metrics, but that is exactly why it is a useful teaching example here: “useful for prediction” does not automatically mean “safe to condition on” for causal estimation. This is different from ordinary pre-purchase engagement features.</p>
<p>This is the same structural collider logic as Orduz’s <code>inquiries</code> example <span class="citation" data-cites="orduz2026-no-r2">(Orduz 2026)</span>, translated into the retargeting setting.</p>
<div class="cell" data-fig-height="4.5" data-layout-align="default">
<div class="cell-output-display">
<div id="fig-retargeting-collider" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-retargeting-collider-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="432" viewbox="0.00 0.00 224.65 260.00" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-256 220.65,-256 220.65,4 -4,4"></polygon>
<!-- Intent -->
<g id="node1" class="node">
<title>Intent</title>
<path fill="#e6e6e6" stroke="#444444" stroke-dasharray="5,2" d="M101.89,-252C101.89,-252 71.89,-252 71.89,-252 65.89,-252 59.89,-246 59.89,-240 59.89,-240 59.89,-228 59.89,-228 59.89,-222 65.89,-216 71.89,-216 71.89,-216 101.89,-216 101.89,-216 107.89,-216 113.89,-222 113.89,-228 113.89,-228 113.89,-240 113.89,-240 113.89,-246 107.89,-252 101.89,-252"></path>
<text text-anchor="middle" x="86.89" y="-229.8" font-family="Helvetica,sans-Serif" font-size="14.00">Intent</text>
</g>
<!-- RetargetingExposure -->
<g id="node2" class="node">
<title>RetargetingExposure</title>
<path fill="#d7e7f7" stroke="#444444" d="M204.41,-180C204.41,-180 81.36,-180 81.36,-180 75.36,-180 69.36,-174 69.36,-168 69.36,-168 69.36,-156 69.36,-156 69.36,-150 75.36,-144 81.36,-144 81.36,-144 204.41,-144 204.41,-144 210.41,-144 216.41,-150 216.41,-156 216.41,-156 216.41,-168 216.41,-168 216.41,-174 210.41,-180 204.41,-180"></path>
<text text-anchor="middle" x="142.89" y="-157.8" font-family="Helvetica,sans-Serif" font-size="14.00">RetargetingExposure</text>
</g>
<!-- Intent&#45;&gt;RetargetingExposure -->
<g id="edge1" class="edge">
<title>Intent-&gt;RetargetingExposure</title>
<path fill="none" stroke="black" d="M100.73,-215.7C107.37,-207.39 115.46,-197.28 122.77,-188.14"></path>
<polygon fill="black" stroke="black" points="125.69,-190.1 129.2,-180.1 120.22,-185.73 125.69,-190.1"></polygon>
</g>
<!-- Purchase -->
<g id="node3" class="node">
<title>Purchase</title>
<path fill="#dcefd9" stroke="#444444" d="M92.53,-108C92.53,-108 41.24,-108 41.24,-108 35.24,-108 29.24,-102 29.24,-96 29.24,-96 29.24,-84 29.24,-84 29.24,-78 35.24,-72 41.24,-72 41.24,-72 92.53,-72 92.53,-72 98.53,-72 104.53,-78 104.53,-84 104.53,-84 104.53,-96 104.53,-96 104.53,-102 98.53,-108 92.53,-108"></path>
<text text-anchor="middle" x="66.89" y="-85.8" font-family="Helvetica,sans-Serif" font-size="14.00">Purchase</text>
</g>
<!-- Intent&#45;&gt;Purchase -->
<g id="edge2" class="edge">
<title>Intent-&gt;Purchase</title>
<path fill="none" stroke="black" d="M74.16,-215.85C67.6,-205.92 60.28,-192.88 56.89,-180 51.52,-159.64 54.63,-135.91 58.75,-118.08"></path>
<polygon fill="black" stroke="black" points="62.16,-118.89 61.24,-108.33 55.37,-117.16 62.16,-118.89"></polygon>
</g>
<!-- RetargetingExposure&#45;&gt;Purchase -->
<g id="edge3" class="edge">
<title>RetargetingExposure-&gt;Purchase</title>
<path fill="none" stroke="black" d="M124.1,-143.7C114.71,-135.05 103.2,-124.45 92.97,-115.03"></path>
<polygon fill="black" stroke="black" points="95.18,-112.3 85.46,-108.1 90.44,-117.45 95.18,-112.3"></polygon>
</g>
<!-- PostWindowEngagementScore -->
<g id="node4" class="node">
<title>PostWindowEngagementScore</title>
<path fill="#fbe1c3" stroke="#444444" d="M197.66,-36C197.66,-36 12.11,-36 12.11,-36 6.11,-36 0.11,-30 0.11,-24 0.11,-24 0.11,-12 0.11,-12 0.11,-6 6.11,0 12.11,0 12.11,0 197.66,0 197.66,0 203.66,0 209.66,-6 209.66,-12 209.66,-12 209.66,-24 209.66,-24 209.66,-30 203.66,-36 197.66,-36"></path>
<text text-anchor="middle" x="104.89" y="-13.8" font-family="Helvetica,sans-Serif" font-size="14.00">PostWindowEngagementScore</text>
</g>
<!-- RetargetingExposure&#45;&gt;PostWindowEngagementScore -->
<g id="edge4" class="edge">
<title>RetargetingExposure-&gt;PostWindowEngagementScore</title>
<path fill="none" stroke="black" d="M138.3,-143.87C131.8,-119.56 119.82,-74.82 112.11,-46.01"></path>
<polygon fill="black" stroke="black" points="115.45,-44.94 109.49,-36.19 108.69,-46.75 115.45,-44.94"></polygon>
</g>
<!-- Purchase&#45;&gt;PostWindowEngagementScore -->
<g id="edge5" class="edge">
<title>Purchase-&gt;PostWindowEngagementScore</title>
<path fill="none" stroke="black" d="M76.28,-71.7C80.65,-63.64 85.94,-53.89 90.78,-44.98"></path>
<polygon fill="black" stroke="black" points="93.91,-46.56 95.6,-36.1 87.75,-43.22 93.91,-46.56"></polygon>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-retargeting-collider-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: PostWindowEngagementScore is a collider because it is measured after the campaign window and can increase after RetargetingExposure (more downstream interactions/returns) and after Purchase (post-purchase account, support, or order-tracking activity). Conditioning on it can improve fit while opening a non-causal path.
</figcaption>
</figure>
</div>
</div>
</div>
<p>In this DAG, <code>PostWindowEngagementScore</code> is caused by both exposure and purchase. That makes it a <strong>collider</strong>. Conditioning on a collider can create a spurious path between exposure and purchase, which biases the causal estimate.</p>
<p>So <code>PostWindowEngagementScore</code> can be extremely predictive of purchase and still be the wrong variable to adjust for. This is the specific mechanism behind “fit improves, decision gets worse.”</p>
<p>The worked example in the next section makes this concrete by using one shared data-generating process and comparing two model-building strategies:</p>
<ul>
<li>one model that is aligned to the causal target and adjustment set, and</li>
<li>one model that adds extra predictive features that improve fit but damage the estimated causal effect.</li>
</ul>
</section>
</section>
<section id="two-regression-models-better-fit-versus-better-causal-decisions" class="level2">
<h2 class="anchored" data-anchor-id="two-regression-models-better-fit-versus-better-causal-decisions">Two regression models: better fit versus better causal decisions</h2>
<p>Below is a lightweight simulated example designed for teaching. The aim is not to mimic every detail of a real ad platform. It is to make the causal roles of variables easy to see. The simulated story follows the DAG logic above:</p>
<ul>
<li>latent <code>intent</code> (unobserved “how ready someone is to buy”) affects both exposure and purchase</li>
<li><code>prior_site_visits</code> is an observed proxy for that intent</li>
<li><code>site_engagement</code> happens after exposure (a mediator)</li>
<li><code>post_window_engagement_score</code> is a collider-like bad control (intentionally post-window for teaching)</li>
</ul>
<div class="cell" data-fig-height="5" data-layout-align="default">
<div class="cell-output-display">
<div id="fig-worked-example-dag" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-worked-example-dag-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="480" viewbox="0.00 0.00 342.64 316.00" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 312)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-312 338.64,-312 338.64,4 -4,4"></polygon>
<!-- Intent -->
<g id="node1" class="node">
<title>Intent</title>
<path fill="#e6e6e6" stroke="#444444" stroke-dasharray="5,2" d="M216.57,-308C216.57,-308 186.57,-308 186.57,-308 180.57,-308 174.57,-302 174.57,-296 174.57,-296 174.57,-284 174.57,-284 174.57,-278 180.57,-272 186.57,-272 186.57,-272 216.57,-272 216.57,-272 222.57,-272 228.57,-278 228.57,-284 228.57,-284 228.57,-296 228.57,-296 228.57,-302 222.57,-308 216.57,-308"></path>
<text text-anchor="middle" x="201.57" y="-285.8" font-family="Helvetica,sans-Serif" font-size="14.00">Intent</text>
</g>
<!-- PriorSiteVisits -->
<g id="node2" class="node">
<title>PriorSiteVisits</title>
<path fill="#ffffff" stroke="#444444" d="M91.2,-240C91.2,-240 11.93,-240 11.93,-240 5.93,-240 -0.07,-234 -0.07,-228 -0.07,-228 -0.07,-216 -0.07,-216 -0.07,-210 5.93,-204 11.93,-204 11.93,-204 91.2,-204 91.2,-204 97.2,-204 103.2,-210 103.2,-216 103.2,-216 103.2,-228 103.2,-228 103.2,-234 97.2,-240 91.2,-240"></path>
<text text-anchor="middle" x="51.57" y="-217.8" font-family="Helvetica,sans-Serif" font-size="14.00">PriorSiteVisits</text>
</g>
<!-- Intent&#45;&gt;PriorSiteVisits -->
<g id="edge1" class="edge">
<title>Intent-&gt;PriorSiteVisits</title>
<path fill="none" stroke="black" d="M174.4,-277.05C153.59,-267.89 124.34,-255.02 99.61,-244.14"></path>
<polygon fill="black" stroke="black" points="100.94,-240.9 90.38,-240.08 98.12,-247.31 100.94,-240.9"></polygon>
</g>
<!-- RetargetingExposure -->
<g id="node3" class="node">
<title>RetargetingExposure</title>
<path fill="#d7e7f7" stroke="#444444" d="M263.09,-240C263.09,-240 140.04,-240 140.04,-240 134.04,-240 128.04,-234 128.04,-228 128.04,-228 128.04,-216 128.04,-216 128.04,-210 134.04,-204 140.04,-204 140.04,-204 263.09,-204 263.09,-204 269.09,-204 275.09,-210 275.09,-216 275.09,-216 275.09,-228 275.09,-228 275.09,-234 269.09,-240 263.09,-240"></path>
<text text-anchor="middle" x="201.57" y="-217.8" font-family="Helvetica,sans-Serif" font-size="14.00">RetargetingExposure</text>
</g>
<!-- Intent&#45;&gt;RetargetingExposure -->
<g id="edge2" class="edge">
<title>Intent-&gt;RetargetingExposure</title>
<path fill="none" stroke="black" d="M201.57,-271.66C201.57,-265.19 201.57,-257.68 201.57,-250.52"></path>
<polygon fill="black" stroke="black" points="205.07,-250.45 201.57,-240.45 198.07,-250.45 205.07,-250.45"></polygon>
</g>
<!-- PurchaseValue -->
<g id="node6" class="node">
<title>PurchaseValue</title>
<path fill="#dcefd9" stroke="#444444" d="M273.02,-104C273.02,-104 186.11,-104 186.11,-104 180.11,-104 174.11,-98 174.11,-92 174.11,-92 174.11,-80 174.11,-80 174.11,-74 180.11,-68 186.11,-68 186.11,-68 273.02,-68 273.02,-68 279.02,-68 285.02,-74 285.02,-80 285.02,-80 285.02,-92 285.02,-92 285.02,-98 279.02,-104 273.02,-104"></path>
<text text-anchor="middle" x="229.57" y="-81.8" font-family="Helvetica,sans-Serif" font-size="14.00">PurchaseValue</text>
</g>
<!-- Intent&#45;&gt;PurchaseValue -->
<g id="edge3" class="edge">
<title>Intent-&gt;PurchaseValue</title>
<path fill="none" stroke="black" d="M228.66,-277.86C246.85,-269.42 270.5,-256.47 287.57,-240 313.12,-215.33 319.86,-206.17 329.57,-172 333.94,-156.61 338.03,-149.58 329.57,-136 321.3,-122.74 308.29,-112.98 294.35,-105.81"></path>
<polygon fill="black" stroke="black" points="295.64,-102.55 285.1,-101.47 292.67,-108.89 295.64,-102.55"></polygon>
</g>
<!-- SiteEngagement -->
<g id="node4" class="node">
<title>SiteEngagement</title>
<path fill="#fbe1c3" stroke="#444444" d="M305.08,-172C305.08,-172 210.05,-172 210.05,-172 204.05,-172 198.05,-166 198.05,-160 198.05,-160 198.05,-148 198.05,-148 198.05,-142 204.05,-136 210.05,-136 210.05,-136 305.08,-136 305.08,-136 311.08,-136 317.08,-142 317.08,-148 317.08,-148 317.08,-160 317.08,-160 317.08,-166 311.08,-172 305.08,-172"></path>
<text text-anchor="middle" x="257.57" y="-149.8" font-family="Helvetica,sans-Serif" font-size="14.00">SiteEngagement</text>
</g>
<!-- RetargetingExposure&#45;&gt;SiteEngagement -->
<g id="edge4" class="edge">
<title>RetargetingExposure-&gt;SiteEngagement</title>
<path fill="none" stroke="black" d="M216.28,-203.66C222.28,-196.59 229.33,-188.28 235.9,-180.54"></path>
<polygon fill="black" stroke="black" points="238.95,-182.34 242.76,-172.45 233.62,-177.81 238.95,-182.34"></polygon>
</g>
<!-- PostWindowEngagementScore -->
<g id="node5" class="node">
<title>PostWindowEngagementScore</title>
<path fill="#fbe1c3" stroke="#444444" d="M247.34,-36C247.34,-36 61.79,-36 61.79,-36 55.79,-36 49.79,-30 49.79,-24 49.79,-24 49.79,-12 49.79,-12 49.79,-6 55.79,0 61.79,0 61.79,0 247.34,0 247.34,0 253.34,0 259.34,-6 259.34,-12 259.34,-12 259.34,-24 259.34,-24 259.34,-30 253.34,-36 247.34,-36"></path>
<text text-anchor="middle" x="154.57" y="-13.8" font-family="Helvetica,sans-Serif" font-size="14.00">PostWindowEngagementScore</text>
</g>
<!-- RetargetingExposure&#45;&gt;PostWindowEngagementScore -->
<g id="edge7" class="edge">
<title>RetargetingExposure-&gt;PostWindowEngagementScore</title>
<path fill="none" stroke="black" d="M191.42,-203.79C186.36,-194.61 180.5,-182.97 176.57,-172 161.41,-129.75 156.67,-77.39 155.2,-46.17"></path>
<polygon fill="black" stroke="black" points="158.69,-45.92 154.81,-36.06 151.7,-46.19 158.69,-45.92"></polygon>
</g>
<!-- RetargetingExposure&#45;&gt;PurchaseValue -->
<g id="edge6" class="edge">
<title>RetargetingExposure-&gt;PurchaseValue</title>
<path fill="none" stroke="black" d="M193.02,-203.9C185.47,-186.38 176.92,-158.58 185.57,-136 188.99,-127.06 194.88,-118.73 201.26,-111.56"></path>
<polygon fill="black" stroke="black" points="203.86,-113.9 208.27,-104.27 198.82,-109.05 203.86,-113.9"></polygon>
</g>
<!-- SiteEngagement&#45;&gt;PurchaseValue -->
<g id="edge5" class="edge">
<title>SiteEngagement-&gt;PurchaseValue</title>
<path fill="none" stroke="black" d="M250.21,-135.66C247.4,-129.04 244.13,-121.33 241.03,-114.03"></path>
<polygon fill="black" stroke="black" points="244.1,-112.29 236.97,-104.45 237.65,-115.03 244.1,-112.29"></polygon>
</g>
<!-- PurchaseValue&#45;&gt;PostWindowEngagementScore -->
<g id="edge8" class="edge">
<title>PurchaseValue-&gt;PostWindowEngagementScore</title>
<path fill="none" stroke="black" d="M209.86,-67.66C201.25,-60.08 191.01,-51.07 181.69,-42.87"></path>
<polygon fill="black" stroke="black" points="183.96,-40.2 174.14,-36.22 179.33,-45.46 183.96,-40.2"></polygon>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-worked-example-dag-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Worked-example DAG used in the model comparison. <code>prior_site_visits</code> is a pre-treatment proxy for latent intent, while <code>site_engagement</code> (mediator) and <code>post_window_engagement_score</code> (collider-like, intentionally measured after the campaign window) should not be conditioned on when estimating the total effect of retargeting exposure on purchase value.
</figcaption>
</figure>
</div>
</div>
</div>
<p>We generate simulated data from this DAG to obtain our historical data. The first few rows look like this:</p>
<div id="cell-sim-retargeting-dgp" class="cell" data-message="false" data-execution_count="2">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> sigmoid(x):</span>
<span id="cb1-2">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> np.exp(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x))</span>
<span id="cb1-3"></span>
<span id="cb1-4">N <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4000</span></span>
<span id="cb1-5"></span>
<span id="cb1-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Pre-treatment variables</span></span>
<span id="cb1-7">intent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, N)                     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># latent</span></span>
<span id="cb1-8">prior_site_visits <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> intent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, N)  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># observed proxy</span></span>
<span id="cb1-9"></span>
<span id="cb1-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Treatment assignment (retargeting exposure) depends on intent + visit</span></span>
<span id="cb1-11">exposure_p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> sigmoid(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> intent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> prior_site_visits)</span>
<span id="cb1-12">retargeting_exposure <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.binomial(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, exposure_p, N)</span>
<span id="cb1-13"></span>
<span id="cb1-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Noise terms for DGP (stored so we can compute truth under intervention)</span></span>
<span id="cb1-15">eps_engagement <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>, N)</span>
<span id="cb1-16">eps_purchase <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.0</span>, N)</span>
<span id="cb1-17">eps_clicks <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>, N)</span>
<span id="cb1-18"></span>
<span id="cb1-19">truth <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-20">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta_exposure_direct"</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>,       <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># direct effect on purchase value</span></span>
<span id="cb1-21">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta_engagement_from_x"</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>,     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># exposure -&gt; engagement</span></span>
<span id="cb1-22">    <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta_purchase_from_eng"</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span>,     <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># engagement -&gt; purchase</span></span>
<span id="cb1-23">}</span>
<span id="cb1-24"></span>
<span id="cb1-25"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> generate_site_engagement(x, intent, noise):</span>
<span id="cb1-26">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> intent <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> truth[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta_engagement_from_x"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> noise</span>
<span id="cb1-27"></span>
<span id="cb1-28"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> generate_purchase(x, intent, prior_site_visits, site_engagement, noise):</span>
<span id="cb1-29">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (</span>
<span id="cb1-30">        truth[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta_exposure_direct"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x</span>
<span id="cb1-31">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.9</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> intent</span>
<span id="cb1-32">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> prior_site_visits</span>
<span id="cb1-33">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> truth[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta_purchase_from_eng"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> site_engagement</span>
<span id="cb1-34">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> noise</span>
<span id="cb1-35">    )</span>
<span id="cb1-36"></span>
<span id="cb1-37">site_engagement <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> generate_site_engagement(retargeting_exposure, intent, eps_engagement)</span>
<span id="cb1-38">purchase_value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> generate_purchase(</span>
<span id="cb1-39">    retargeting_exposure, intent, prior_site_visits, site_engagement, eps_purchase</span>
<span id="cb1-40">)</span>
<span id="cb1-41"></span>
<span id="cb1-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Collider-like "bad control" for teaching: intentionally post-window, caused by exposure and purchase</span></span>
<span id="cb1-43">post_window_engagement_score <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> retargeting_exposure <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> purchase_value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> eps_clicks</span>
<span id="cb1-44"></span>
<span id="cb1-45">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame(</span>
<span id="cb1-46">    {</span>
<span id="cb1-47">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"prior_site_visits"</span>: prior_site_visits,</span>
<span id="cb1-48">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"retargeting_exposure"</span>: retargeting_exposure,</span>
<span id="cb1-49">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"site_engagement"</span>: site_engagement,</span>
<span id="cb1-50">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"post_window_engagement_score"</span>: post_window_engagement_score,</span>
<span id="cb1-51">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purchase_value"</span>: purchase_value,</span>
<span id="cb1-52">    }</span>
<span id="cb1-53">)</span>
<span id="cb1-54"></span>
<span id="cb1-55">df.head()</span></code></pre></div></div>
</details>
<div id="sim-retargeting-dgp" class="cell-output cell-output-display" data-execution_count="2">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">prior_site_visits</th>
<th data-quarto-table-cell-role="th">retargeting_exposure</th>
<th data-quarto-table-cell-role="th">site_engagement</th>
<th data-quarto-table-cell-role="th">post_window_engagement_score</th>
<th data-quarto-table-cell-role="th">purchase_value</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>-0.226015</td>
<td>1</td>
<td>1.434008</td>
<td>3.405016</td>
<td>1.975659</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>0.902433</td>
<td>1</td>
<td>1.733130</td>
<td>2.370920</td>
<td>4.525204</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>1.584380</td>
<td>1</td>
<td>1.981409</td>
<td>3.003509</td>
<td>4.435321</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>0.314106</td>
<td>0</td>
<td>-0.895695</td>
<td>-0.604775</td>
<td>-2.749173</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>1.607601</td>
<td>1</td>
<td>0.712520</td>
<td>3.209975</td>
<td>3.378986</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<p>The main causal quantity we care about in this example is the <strong>ATE (average treatment effect)</strong>. Here, the treatment is <code>retargeting_exposure</code> (shown ad vs not shown ad) and the outcome is <code>purchase_value</code>. In words, the ATE is the average change in purchase value if everyone in the population were shown the ad, compared with if no one were shown the ad.</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BATE%7D%20=%20%5Cmathbb%7BE%7D%5BY(1)%20-%20Y(0)%5D%0A"></p>
<p>where <img src="https://latex.codecogs.com/png.latex?Y(1)"> is the purchase value a person would have if shown the ad, and <img src="https://latex.codecogs.com/png.latex?Y(0)"> is the purchase value that same person would have if not shown the ad.</p>
<div class="callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>Potential outcomes and the fundamental problem of causal inference (short version)
</div>
</div>
<div class="callout-body-container callout-body">
<p>The notation <img src="https://latex.codecogs.com/png.latex?Y(1)"> and <img src="https://latex.codecogs.com/png.latex?Y(0)"> comes from the <strong>potential outcomes</strong> framework <span class="citation" data-cites="holland1986statistics">(Holland 1986)</span>. For each person, we can imagine two possible outcomes:</p>
<ul>
<li>purchase value if they are shown the ad, <img src="https://latex.codecogs.com/png.latex?Y(1)">,</li>
<li>purchase value if they are not shown the ad, <img src="https://latex.codecogs.com/png.latex?Y(0)">.</li>
</ul>
<p>The problem is that we never observe both for the same person at the same time. We only observe one of them, depending on what actually happened. This is the <strong>fundamental problem of causal inference</strong> <span class="citation" data-cites="holland1986statistics">(Holland 1986)</span>.</p>
<p>That is why causal inference needs assumptions and modeling: we use observed data (plus a causal model/DAG) to estimate the missing counterfactual outcomes well enough to answer the intervention question. In other words, the decision depends on outcomes we do not directly observe, so “fit to observed outcomes” is not by itself the right target.</p>
</div>
</div>
<section id="model-1-prediction-focused" class="level3">
<h3 class="anchored" data-anchor-id="model-1-prediction-focused">Model 1: prediction-focused</h3>
<p>This model uses variables that are very informative for prediction, including post-treatment engagement and a collider-like post-window engagement summary.</p>
<div id="predictive-model-definition" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">predictive_formula <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purchase_value ~ retargeting_exposure + prior_site_visits + site_engagement + post_window_engagement_score"</span></span>
<span id="cb2-2">model_predictive <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bmb.Model(predictive_formula, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>df)</span>
<span id="cb2-3">idata_predictive <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model_predictive.fit(draws<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, tune<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>seed)</span></code></pre></div></div>
</div>
<p>This is exactly the kind of model that can look excellent on fit metrics because it includes variables that are close to the outcome.</p>
</section>
<section id="model-2-causal-first" class="level3">
<h3 class="anchored" data-anchor-id="model-2-causal-first">Model 2: causal-first</h3>
<p>For the causal model, we want the <strong>total effect</strong> of <code>retargeting_exposure</code> on <code>purchase_value</code>, so we need to be explicit about what we condition on in Figure&nbsp;5.</p>
<p>Adjustment-set logic (concise version):</p>
<ul>
<li>We want the total causal effect of <code>retargeting_exposure</code> on <code>purchase_value</code>.</li>
<li><code>Intent</code> is a confounder, but it is unobserved.</li>
<li><code>prior_site_visits</code> is a pre-treatment proxy for intent, so we include it.</li>
<li><code>site_engagement</code> is a mediator (post-treatment), so conditioning on it would block part of the total effect.</li>
<li><code>post_window_engagement_score</code> is collider-like in this setup, so conditioning on it can introduce bias.</li>
</ul>
<p>So the causal-first model conditions on <code>prior_site_visits</code> but not on <code>site_engagement</code> or <code>post_window_engagement_score</code>.</p>
<div id="causal-model-definition" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">causal_formula <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purchase_value ~ retargeting_exposure + prior_site_visits"</span></span>
<span id="cb3-2">model_causal <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bmb.Model(causal_formula, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>df)</span>
<span id="cb3-3">idata_causal <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model_causal.fit(draws<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, tune<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>seed)</span></code></pre></div></div>
</div>
</section>
<section id="compare-the-models" class="level3">
<h3 class="anchored" data-anchor-id="compare-the-models">Compare the models</h3>
<p>We’ll take the fitted models and use them to estimate the ATE (the causal quantity we care about) using G-computation. Then we’ll compare the ATE estimates and their uncertainty, along with the in-sample fit metrics. We will evaluate each model twice: once on observational fit to the observed outcomes, and once on the causal estimand (ATE). For the fit comparison, I use an in-sample posterior-mean predictive <code>R^2</code> computed from the posterior mean of <code>mu</code> (not Bayesian <code>R^2</code>); the causal lesson here does not depend on the exact fit metric.</p>
<div id="fit-and-compare-worked-example" class="cell" data-message="false" data-execution_count="5">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Truth-level ATE via intervention on exposure, averaging over same units/noise</span></span>
<span id="cb4-2">eng_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> generate_site_engagement(np.ones(N), intent, eps_engagement)</span>
<span id="cb4-3">eng_0 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> generate_site_engagement(np.zeros(N), intent, eps_engagement)</span>
<span id="cb4-4">y_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> generate_purchase(np.ones(N), intent, prior_site_visits, eng_1, eps_purchase)</span>
<span id="cb4-5">y_0 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> generate_purchase(np.zeros(N), intent, prior_site_visits, eng_0, eps_purchase)</span>
<span id="cb4-6">truth_ate <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.mean(y_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> y_0)</span>
<span id="cb4-7"></span>
<span id="cb4-8"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> posterior_mean_r2(model, idata, data, outcome_col):</span>
<span id="cb4-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># In-sample predictive R^2 from posterior-mean mu (not Bayesian R^2)</span></span>
<span id="cb4-10">    model.predict(idata, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>data, inplace<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb4-11">    mu_mean <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> idata.posterior[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>].mean(dim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chain"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draw"</span>)).values</span>
<span id="cb4-12">    y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data[outcome_col].to_numpy()</span>
<span id="cb4-13">    ss_res <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>((y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu_mean) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb4-14">    ss_tot <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">sum</span>((y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> y.mean()) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb4-15">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ss_res <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> ss_tot</span>
<span id="cb4-16"></span>
<span id="cb4-17"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> gcomp_ate(model, idata, data, treatment_col, high<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, low<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>):</span>
<span id="cb4-18">    data_hi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data.copy()</span>
<span id="cb4-19">    data_hi[treatment_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> high</span>
<span id="cb4-20">    model.predict(idata, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>data_hi, inplace<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb4-21">    mu_hi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> idata.posterior[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>].copy(deep<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb4-22"></span>
<span id="cb4-23">    data_lo <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data.copy()</span>
<span id="cb4-24">    data_lo[treatment_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> low</span>
<span id="cb4-25">    model.predict(idata, data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>data_lo, inplace<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb4-26">    mu_lo <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> idata.posterior[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>].copy(deep<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb4-27"></span>
<span id="cb4-28">    ate <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (mu_hi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> mu_lo).mean(dim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"__obs__"</span>)</span>
<span id="cb4-29">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> ate</span>
<span id="cb4-30"></span>
<span id="cb4-31">ate_causal <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gcomp_ate(model_causal, idata_causal, df, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"retargeting_exposure"</span>)</span>
<span id="cb4-32">ate_predictive <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> gcomp_ate(model_predictive, idata_predictive, df, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"retargeting_exposure"</span>)</span>
<span id="cb4-33"></span>
<span id="cb4-34">r2_causal <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> posterior_mean_r2(model_causal, idata_causal, df, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purchase_value"</span>)</span>
<span id="cb4-35">r2_prediction <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> posterior_mean_r2(model_predictive, idata_predictive, df, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"purchase_value"</span>)</span></code></pre></div></div>
</details>
</div>
<div class="callout callout-style-simple callout-note callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Note</span>How we estimate the ATE here (G-computation)
</div>
</div>
<div class="callout-body-container callout-body">
<p>We estimate the ATE using <strong>G-computation</strong> (also called standardization):</p>
<ol type="1">
<li>Fit a regression model.</li>
<li>Predict outcomes if everyone is set to <code>retargeting_exposure = 1</code> (shown ads).</li>
<li>Predict outcomes if everyone is set to <code>retargeting_exposure = 0</code> (not shown ads).</li>
<li>Average the difference.</li>
</ol>
<p>G-computation identifies a causal ATE only under assumptions (including no unmeasured confounding after adjustment, positivity, and an adequate outcome model), and in this simulation we intentionally adjust with a proxy so some residual bias can remain. This turns the fitted regression model into an estimate of the causal quantity defined above by explicitly comparing predicted outcomes under two different hypothetical treatment assignments. That is why it is aligned to the decision question (what happens if we change exposure?) rather than only to observational goodness of fit.</p>
</div>
</div>
<p>Now let’s plot the results.</p>
<div id="cell-fig-worked-example-results" class="cell" data-execution_count="6">
<div class="cell-output cell-output-display">
<div id="fig-worked-example-results" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-worked-example-results-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/goodness_of_fit_not_objective_files/figure-html/fig-worked-example-results-output-1.png" width="832" height="593" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-worked-example-results-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Worked-example model comparison. Top row: observational fit (observed versus posterior-mean predicted purchase value) for the causal-first and prediction-focused models. Bottom row: posterior distributions of the estimated ATE, with the vertical reference line marking the true ATE from the simulation.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Figure&nbsp;6 shows the main point of the post in miniature: the prediction-focused model looks much better on observational fit (top row) but is much worse for the causal quantity we care about (bottom row).</p>
</section>
</section>
<section id="what-did-we-learn" class="level2">
<h2 class="anchored" data-anchor-id="what-did-we-learn">What did we learn?</h2>
<p>The important extension for decision-making is what happens next. If a team trusted the prediction-focused model, it would conclude that retargeting has little or no causal impact on purchases and may recommend cutting a campaign that is actually useful. The causal-first model is not perfect, but it is much closer to the true intervention effect, so it points toward the better decision.</p>
<p>Even if the prediction-focused model also won on holdout predictive fit (note tested here), that would not fix this problem. The decision changes the treatment assignment mechanism, so the relevant target is the interventional distribution, not just predictive performance under the observational one (that is, under the same assignment policy) <span class="citation" data-cites="vincent2025-interventional-distribution">(Vincent 2023)</span>.</p>
<p>One subtle but important point is that the causal-first model may still miss the true ATE by a noticeable amount. That is not a contradiction. In this simulation, the true confounder (<code>Intent</code>) is unobserved, and we adjust using <code>prior_site_visits</code>, which is only a proxy. The proxy reduces confounding bias, but it does not eliminate it completely, so some residual bias can remain.</p>
<p>The exact numbers will vary with simulation choices, but the pattern is the point:</p>
<ul>
<li>the prediction-focused model usually achieves better fit</li>
<li>its causal ATE estimate is often worse because it controls for variables that should not be used when estimating the total effect</li>
<li>the causal-first model can still miss the truth if key confounders are unobserved and only partially captured by proxies</li>
</ul>
<p>So the “better” model depends on what “better” means:</p>
<ul>
<li>better forecasting of observed outcomes</li>
<li>or better estimation of the effect of an intervention</li>
</ul>
<p>Those are often related, but they are not the same objective.</p>
<p>The model-selection lesson is not “prefer worse goodness of fit” for its own sake. The lesson is that <strong>maximizing goodness of fit as the primary objective is the wrong criterion when the model is being used to support intervention decisions</strong>.</p>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>The practical message is not “ignore prediction” and it is not “anti-ML.” It is to separate two jobs that are often collapsed into one:</p>
<ul>
<li>forecasting what happens under the current assignment system</li>
<li>estimating what would change under an intervention</li>
</ul>
<p>In the retargeting example, that separation forced three useful modeling decisions:</p>
<ul>
<li>define the causal target first (the total effect of retargeting on purchases)</li>
<li>classify variables by causal role (proxy, collider, mediator) rather than predictive strength alone</li>
<li>evaluate the model on the causal quantity and decision relevance, not just goodness of fit</li>
</ul>
<p>The key reason is the same one introduced at the start of the post: decisions are interventions, and interventions change the system you are modeling. A model that performs well under the observational distribution can still fail under the interventional distribution if it learns the wrong structure for the decision problem <span class="citation" data-cites="vincent2025-interventional-distribution">(Vincent 2023)</span>.</p>
<p>So if your goal is business decisions, budgeting, targeting, or policy changes, the call to action is simple: do not treat predictive power as the primary objective. Start with the causal question, build the model around the intervention and estimand, and use goodness of fit as a diagnostic rather than the goal.</p>
<p>The worked example also shows a more realistic point: even a causally motivated model can remain biased when important confounders are unobserved and only imperfectly proxied. Causal-first modeling does not guarantee perfect recovery, but it does give you a better chance of making the right decision for the right reason.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-breiman2001two-cultures" class="csl-entry">
Breiman, Leo. 2001. <span>“Statistical Modeling: The Two Cultures.”</span> <em>Statistical Science</em> 16 (3): 199–231. <a href="https://doi.org/10.1214/ss/1009213726">https://doi.org/10.1214/ss/1009213726</a>.
</div>
<div id="ref-cinelli2022good-bad-controls" class="csl-entry">
Cinelli, Carlos, Andrew Forney, and Judea Pearl. 2022. <span>“A Crash Course in Good and Bad Controls.”</span> <em>Sociological Methods &amp; Research</em>, ahead of print. <a href="https://doi.org/10.1177/00491241221099552">https://doi.org/10.1177/00491241221099552</a>.
</div>
<div id="ref-holland1986statistics" class="csl-entry">
Holland, Paul W. 1986. <span>“Statistics and Causal Inference.”</span> <em>Journal of the American Statistical Association</em> 81 (396): 945–60. <a href="https://doi.org/10.1080/01621459.1986.10478354">https://doi.org/10.1080/01621459.1986.10478354</a>.
</div>
<div id="ref-orduz2026-no-r2" class="csl-entry">
Orduz, Juan Camilo. 2026. <em>In-Sample <span>R^2</span> Is Not a Good Metric for Decision Making</em>. <a href="https://juanitorduz.github.io/no_r2/">https://juanitorduz.github.io/no_r2/</a>.
</div>
<div id="ref-pearl2009causality" class="csl-entry">
Pearl, Judea. 2009. <em>Causality: Models, Reasoning, and Inference</em>. 2nd ed. Cambridge University Press.
</div>
<div id="ref-shmueli2010explain-predict" class="csl-entry">
Shmueli, Galit. 2010. <span>“To Explain or to Predict?”</span> <em>Statistical Science</em> 25 (3): 289–310. <a href="https://doi.org/10.1214/10-STS330">https://doi.org/10.1214/10-STS330</a>.
</div>
<div id="ref-vincent2025-interventional-distribution" class="csl-entry">
Vincent, Benjamin T. 2023. <span>“Interventional Distributions and Graph Mutation with the Do-Operator.”</span> In <em>PyMC Examples</em>, edited by PyMC Team. <a href="https://doi.org/10.5281/zenodo.5654871">https://doi.org/10.5281/zenodo.5654871</a>.
</div>
</div>


</section>

 ]]></description>
  <category>causality</category>
  <category>marketing</category>
  <category>decision-making</category>
  <guid>https://drbenvincent.github.io/posts/goodness_of_fit_not_objective.html</guid>
  <pubDate>Mon, 23 Feb 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Bayesian models + grammar of graphics + Python = ❤️</title>
  <dc:creator>Benjamin Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics.html</link>
  <description><![CDATA[ 





<section id="why-another-plotting-post" class="level2">
<h2 class="anchored" data-anchor-id="why-another-plotting-post">Why another plotting post?</h2>
<p>Bayesian modelling in Python is pretty solid: We’ve got PyMC for model building and inference, <a href="https://github.com/arviz-devs/arviz">ArviZ</a> covers diagnostics and plotting, and we’ve got helpful pacakges like <a href="https://github.com/bambinos/bambi">Bambi</a> as a layer on top of PyMC to make linear modelling more convenient.</p>
<p>However, one of the pain points I often encounter is on the plotting side of things. Even for relatively simple models, if you want to get some nice data viz out to deliver some sweet insights to stakeholders, or even just sanity check the results, it can be a bit of a pain. At the moment you have to be pretty familiar with the internals of the <a href="https://python.arviz.org/en/stable/api/generated/arviz.InferenceData.html#arviz.InferenceData"><code>arviz.InferenceData</code></a> object and do a whole bunch of wrangling to get what you need in order to plot it. This often involves <a href="https://en.wikipedia.org/wiki/Imperative_programming">imperative style</a> telling the computer what to do (slice this dimension, aggregate that dimension, loop over this group etc.).</p>
<p>So I’ve been left wondering:</p>
<blockquote class="blockquote">
<p>Can we make the plotting of Bayesian models in Python more declarative?</p>
</blockquote>
<p>This post is a quick exploration of that idea. I don’t have a full solution, but I do have a proof of concept that shows how we can get a grammar-of-graphics approach to plotting Bayesian models in Python.</p>
</section>
<section id="setting-up-the-data-and-modelling-that-well-plot" class="level2">
<h2 class="anchored" data-anchor-id="setting-up-the-data-and-modelling-that-well-plot">Setting up the data and modelling that we’ll plot</h2>
<p>First, we need to generate some data, build a PyMC model, and sample from it. We’ll also generate a grid of points to evaluate the posterior predictive distribution on. At the end of this we’ll have a bunch of MCMC samples from the posterior distribution of the model. This will be stored in an <a href="https://python.arviz.org/en/stable/api/generated/arviz.InferenceData.html#arviz.InferenceData"><code>arviz.InferenceData</code></a> object. We’ll hide all these steps because they are not the focus of this post. But you can un-collapse the code block if you want to see the details.</p>
<div id="53b594e0" class="cell" data-execution_count="1">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> arviz <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> az</span>
<span id="cb1-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> matplotlib.pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb1-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pd</span>
<span id="cb1-4"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> numpy <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> np</span>
<span id="cb1-5"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pymc <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> pm</span>
<span id="cb1-6"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> seaborn <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> sns</span>
<span id="cb1-7"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> plotnine <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> (</span>
<span id="cb1-8">    ggplot,</span>
<span id="cb1-9">    aes,</span>
<span id="cb1-10">    stat_summary,</span>
<span id="cb1-11">    facet_wrap,</span>
<span id="cb1-12">    theme_classic,</span>
<span id="cb1-13">    labs,</span>
<span id="cb1-14">    geom_density,</span>
<span id="cb1-15">    geom_point,</span>
<span id="cb1-16">)</span>
<span id="cb1-17"></span>
<span id="cb1-18">plt.rcParams[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"figure.figsize"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>]</span>
<span id="cb1-19"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span>config InlineBackend.figure_format <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'retina'</span></span>
<span id="cb1-20"></span>
<span id="cb1-21">RANDOM_SEED <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">42</span></span>
<span id="cb1-22">rng <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.random.default_rng(RANDOM_SEED)</span>
<span id="cb1-23"></span>
<span id="cb1-24"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># generate data ------------------------------------------------------------------------</span></span>
<span id="cb1-25">n_groups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb1-26">group_size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>]</span>
<span id="cb1-27"></span>
<span id="cb1-28"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Group-specific parameters</span></span>
<span id="cb1-29">slopes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n_groups)</span>
<span id="cb1-30">intercepts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n_groups)</span>
<span id="cb1-31"></span>
<span id="cb1-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate data</span></span>
<span id="cb1-33">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb1-34"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(n_groups):</span>
<span id="cb1-35">    n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> group_size[i]</span>
<span id="cb1-36">    x_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.sort(rng.uniform(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n))</span>
<span id="cb1-37">    noise <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>n)</span>
<span id="cb1-38">    y_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> slopes[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> intercepts[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> noise</span>
<span id="cb1-39">    group_labels <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.full(n, i)</span>
<span id="cb1-40">    data.append(pd.DataFrame({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>: x_vals, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>: y_vals, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>: group_labels}))</span>
<span id="cb1-41"></span>
<span id="cb1-42"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Combine all groups into a single DataFrame</span></span>
<span id="cb1-43">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.concat(data, ignore_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>)</span>
<span id="cb1-44">df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>].astype(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"category"</span>)</span>
<span id="cb1-45"></span>
<span id="cb1-46"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Build a PyMC model -------------------------------------------------------------------</span></span>
<span id="cb1-47">prior_mean <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb1-48">prior_std <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb1-49"></span>
<span id="cb1-50">x_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df.x.values</span>
<span id="cb1-51">y_data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> df.y.values</span>
<span id="cb1-52"></span>
<span id="cb1-53">coords <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"groups"</span>: df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>].cat.categories, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>: df.index}</span>
<span id="cb1-54"></span>
<span id="cb1-55"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">with</span> pm.Model(coords<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>coords) <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> _m:</span>
<span id="cb1-56">    x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Data(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, x_data, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>)</span>
<span id="cb1-57">    y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Data(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, y_data, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>)</span>
<span id="cb1-58">    group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Data(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>, df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>].cat.codes.values, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>)</span>
<span id="cb1-59">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># priors</span></span>
<span id="cb1-60">    intercept <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"intercept"</span>, mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"groups"</span>])</span>
<span id="cb1-61">    beta <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta"</span>, mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>prior_mean, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>prior_std, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"groups"</span>])</span>
<span id="cb1-62">    sigma <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.HalfNormal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma"</span>, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span>)</span>
<span id="cb1-63">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># likelihood</span></span>
<span id="cb1-64">    mu <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Deterministic(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, intercept[group] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> beta[group] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> x, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>)</span>
<span id="cb1-65">    pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs"</span>, mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>mu, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sigma, observed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>y, dims<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>)</span>
<span id="cb1-66">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># sample</span></span>
<span id="cb1-67">    idata <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.sample()</span>
<span id="cb1-68"></span>
<span id="cb1-69"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Generate a grid of points to evaluate on ---------------------------------------------</span></span>
<span id="cb1-70">n_interp_points <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span></span>
<span id="cb1-71">xi <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.concatenate(</span>
<span id="cb1-72">    [</span>
<span id="cb1-73">        np.linspace(group[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>].x.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">min</span>(), group[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>].x.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">max</span>(), n_interp_points)</span>
<span id="cb1-74">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> group <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> df.groupby(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>)</span>
<span id="cb1-75">    ]</span>
<span id="cb1-76">)</span>
<span id="cb1-77">g <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> np.concatenate([[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n_interp_points <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> i <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">range</span>(n_groups)]).astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>)</span>
<span id="cb1-78">predict_at <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>: xi, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>: g, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>: np.zeros_like(xi)}</span>
<span id="cb1-79"></span>
<span id="cb1-80"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Posterior prediction on the grid of points -------------------------------------------</span></span>
<span id="cb1-81">coords <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"groups"</span>: predict_at[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>], <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>: np.arange(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">len</span>(xi))}</span>
<span id="cb1-82"></span>
<span id="cb1-83"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">with</span> _m:</span>
<span id="cb1-84">    pm.set_data(predict_at, coords<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>coords)</span>
<span id="cb1-85">    idata.extend(</span>
<span id="cb1-86">        pm.sample_posterior_predictive(</span>
<span id="cb1-87">            idata,</span>
<span id="cb1-88">            var_names<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>],</span>
<span id="cb1-89">            random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>rng,</span>
<span id="cb1-90">            progressbar<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>,</span>
<span id="cb1-91">            predictions<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>,</span>
<span id="cb1-92">        )</span>
<span id="cb1-93">    )</span></code></pre></div></div>
</details>
</div>
<p>Ok, so after that we now have the following <code>arviz.InferenceData</code> object. You can click on the dropdowns to get more information about the contents of the object. In short, it contains MCMC samples and data.s</p>
<div id="e4421065" class="cell" data-execution_count="2">
<div class="cell-output cell-output-display" data-execution_count="85">

            <div>
              <div class="xr-header">
                <div class="xr-obj-type">arviz.InferenceData</div>
              </div>
              <ul class="xr-sections group-sections">
              
            <li class="xr-section-item">
                  <input id="idata_posterior8c1bb536-190b-4d42-885d-7e9a56e10941" class="xr-section-summary-in" type="checkbox">
                  <label for="idata_posterior8c1bb536-190b-4d42-885d-7e9a56e10941" class="xr-section-summary">posterior</label>
                  <div class="xr-section-inline-details"></div>
                  <div class="xr-section-details">
                      <ul id="xr-dataset-coord-list" class="xr-var-list">
                          <div style="padding-left:2rem;"><div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewbox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewbox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>
<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1f1f1f;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block !important;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: inline-block;
  opacity: 0;
  height: 0;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:focus + label {
  border: 2px solid var(--xr-font-color0);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: "►";
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: "▼";
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: "(";
}

.xr-dim-list:after {
  content: ")";
}

.xr-dim-list li:not(:last-child):after {
  content: ",";
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-index-preview {
  grid-column: 2 / 5;
  color: var(--xr-font-color2);
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data,
.xr-index-data-in:checked ~ .xr-index-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
.xr-index-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
</style><pre class="xr-text-repr-fallback">&lt;xarray.Dataset&gt; Size: 936kB
Dimensions:    (chain: 4, draw: 1000, groups: 4, obs_ind: 20)
Coordinates:
  * chain      (chain) int64 32B 0 1 2 3
  * draw       (draw) int64 8kB 0 1 2 3 4 5 6 7 ... 993 994 995 996 997 998 999
  * groups     (groups) int64 32B 0 1 2 3
  * obs_ind    (obs_ind) int64 160B 0 1 2 3 4 5 6 7 ... 12 13 14 15 16 17 18 19
Data variables:
    intercept  (chain, draw, groups) float64 128kB -0.4746 -1.427 ... 2.804
    beta       (chain, draw, groups) float64 128kB 0.9442 0.7746 ... 0.9095
    sigma      (chain, draw) float64 32kB 0.7011 0.6883 0.597 ... 1.591 1.37
    mu         (chain, draw, obs_ind) float64 640kB 1.945 8.03 ... 11.46 14.99
Attributes:
    created_at:                 2025-05-02T14:24:27.321753+00:00
    arviz_version:              0.21.0
    inference_library:          pymc
    inference_library_version:  5.22.0
    sampling_time:              1.5654027462005615
    tuning_steps:               1000</pre><div class="xr-wrap" style="display:none"><div class="xr-header"><div class="xr-obj-type">xarray.Dataset</div></div><ul class="xr-sections"><li class="xr-section-item"><input id="section-f10d2f6f-c549-40a7-aec3-049364dcc404" class="xr-section-summary-in" type="checkbox" disabled=""><label for="section-f10d2f6f-c549-40a7-aec3-049364dcc404" class="xr-section-summary" title="Expand/collapse section">Dimensions:</label><div class="xr-section-inline-details"><ul class="xr-dim-list"><li><span class="xr-has-index">chain</span>: 4</li><li><span class="xr-has-index">draw</span>: 1000</li><li><span class="xr-has-index">groups</span>: 4</li><li><span class="xr-has-index">obs_ind</span>: 20</li></ul></div><div class="xr-section-details"></div></li><li class="xr-section-item"><input id="section-7b7ba5a8-8b9f-4158-83e1-0b9d31b29a52" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-7b7ba5a8-8b9f-4158-83e1-0b9d31b29a52" class="xr-section-summary">Coordinates: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">chain</span></div><div class="xr-var-dims">(chain)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3</div><input id="attrs-e85affd5-d990-4303-8523-cf596cd1f1e7" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-e85affd5-d990-4303-8523-cf596cd1f1e7" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-a885899a-b2f1-4214-812c-6a5ec3cbc035" class="xr-var-data-in" type="checkbox"><label for="data-a885899a-b2f1-4214-812c-6a5ec3cbc035" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([0, 1, 2, 3])</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">draw</span></div><div class="xr-var-dims">(draw)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 ... 995 996 997 998 999</div><input id="attrs-3ef7261f-0efb-4d45-a94e-efd5d00931a1" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-3ef7261f-0efb-4d45-a94e-efd5d00931a1" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-94c6882b-ef9c-418d-a33d-068395c2d186" class="xr-var-data-in" type="checkbox"><label for="data-94c6882b-ef9c-418d-a33d-068395c2d186" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([  0,   1,   2, ..., 997, 998, 999], shape=(1000,))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">groups</span></div><div class="xr-var-dims">(groups)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3</div><input id="attrs-fa368518-efe4-4209-be75-b5ff2a8377dd" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-fa368518-efe4-4209-be75-b5ff2a8377dd" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-909b3030-5aeb-4f62-9cbb-b48a7214e4be" class="xr-var-data-in" type="checkbox"><label for="data-909b3030-5aeb-4f62-9cbb-b48a7214e4be" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([0, 1, 2, 3])</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">obs_ind</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 6 ... 14 15 16 17 18 19</div><input id="attrs-1567b0c3-2279-470b-8892-21cd9afa57f1" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-1567b0c3-2279-470b-8892-21cd9afa57f1" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-70046376-e85f-4fea-b5f0-f1669424f719" class="xr-var-data-in" type="checkbox"><label for="data-70046376-e85f-4fea-b5f0-f1669424f719" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19])</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-82078070-98ce-4370-9cc6-80910357f831" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-82078070-98ce-4370-9cc6-80910357f831" class="xr-section-summary">Data variables: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span>intercept</span></div><div class="xr-var-dims">(chain, draw, groups)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">-0.4746 -1.427 ... 0.1586 2.804</div><input id="attrs-81a04a6f-e297-426a-a2d4-7e3db6ecb6de" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-81a04a6f-e297-426a-a2d4-7e3db6ecb6de" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-6839a1a4-775c-4338-9aa1-878c93a1cd58" class="xr-var-data-in" type="checkbox"><label for="data-6839a1a4-775c-4338-9aa1-878c93a1cd58" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[[-0.47456762, -1.4271179 ,  0.46711157, -0.1218181 ],
        [-0.98935497, -0.73799406,  0.48060058,  1.16887132],
        [-1.50599603,  0.04282603,  0.61166684,  0.85009612],
        ...,
        [-1.15958296, -0.87837344, -0.23401673,  0.37146748],
        [ 1.23356353, -1.52252447,  1.70021292, -1.39186581],
        [-2.98264268, -1.29969904, -0.21392282,  1.08222104]],

       [[ 0.44101372, -1.31104234,  1.29417884,  0.266548  ],
        [-2.32714781, -1.16147371,  0.16979219, -0.1247327 ],
        [-0.393656  , -2.22161085,  1.75686926,  0.15224011],
        ...,
        [-0.10212942, -1.06665952,  1.36341386,  0.26706832],
        [-1.32067268, -1.0330045 ,  0.02983723, -0.42154338],
        [-0.89102411, -1.059031  ,  1.18308735,  0.52783979]],

       [[-0.62213742, -1.89008423,  1.22325022, -0.49717993],
        [-0.40923138, -1.72398038,  0.89572242, -0.36489989],
        [-1.11830846, -1.37336769, -0.28743028, -0.09662273],
        ...,
        [-0.05595348, -2.56170259,  0.31230145, -0.35081235],
        [-0.05595348, -2.56170259,  0.31230145, -0.35081235],
        [-0.19140222, -1.12559605,  0.4425998 , -0.33968945]],

       [[-1.76823825, -2.99910191,  0.30763091,  0.18871243],
        [-0.77981316, -0.32429016,  0.79639832,  0.03621362],
        [-0.20022612, -1.87968075,  0.49203988,  0.42528713],
        ...,
        [-0.67987278, -1.46633831,  0.50444727, -0.77809872],
        [-2.17099726, -1.37199211, -0.00703357,  2.52399891],
        [-2.32367672, -1.20762487,  0.15857166,  2.80411447]]],
      shape=(4, 1000, 4))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>beta</span></div><div class="xr-var-dims">(chain, draw, groups)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.9442 0.7746 ... 1.144 0.9095</div><input id="attrs-8d63a80b-5e41-4833-84e5-bb1b62f31c82" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-8d63a80b-5e41-4833-84e5-bb1b62f31c82" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-9fb2cf33-a52f-46e5-8850-dc13a16e00c1" class="xr-var-data-in" type="checkbox"><label for="data-9fb2cf33-a52f-46e5-8850-dc13a16e00c1" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[[0.94419079, 0.77460416, 1.15654101, 1.24047373],
        [1.14578306, 0.71476308, 1.15865428, 1.077356  ],
        [1.08819204, 0.72554139, 1.16301138, 1.07077599],
        ...,
        [1.0424994 , 0.74634983, 1.22278959, 1.13841103],
        [0.64648082, 0.84902802, 1.07592917, 1.34883071],
        [1.2178665 , 0.77037655, 1.20922473, 1.07638336]],

       [[0.82467167, 0.82921395, 1.12258439, 1.17108346],
        [1.24998782, 0.78142674, 1.20729094, 1.22310104],
        [0.99102276, 0.858996  , 1.09078481, 1.14934844],
        ...,
        [0.93865425, 0.74333759, 1.11054785, 1.16799629],
        [1.0355032 , 0.80663373, 1.19544125, 1.28430352],
        [1.00857433, 0.78806789, 1.10966468, 1.08058805]],

       [[1.09838731, 0.79588494, 1.12483609, 1.19089754],
        [1.07235791, 0.80674662, 1.11933938, 1.21820579],
        [0.96796269, 0.77613686, 1.19536188, 1.21255967],
        ...,
        [0.97016287, 0.89971255, 1.17667855, 1.2156209 ],
        [0.97016287, 0.89971255, 1.17667855, 1.2156209 ],
        [0.85228873, 0.79670153, 1.19300919, 1.24133935]],

       [[1.05915992, 0.9419432 , 1.15726096, 1.18410988],
        [1.12853719, 0.71907474, 1.18678122, 1.23646154],
        [1.01969498, 0.90539407, 1.1436981 , 1.14075654],
        ...,
        [0.94955401, 0.81114268, 1.17277169, 1.26130882],
        [1.18626646, 0.82973888, 1.15236929, 0.91686936],
        [1.13840876, 0.83960935, 1.14365885, 0.90945633]]],
      shape=(4, 1000, 4))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>sigma</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.7011 0.6883 0.597 ... 1.591 1.37</div><input id="attrs-c84ff229-e3f9-4919-9274-644e4ba9933c" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-c84ff229-e3f9-4919-9274-644e4ba9933c" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-da0ab164-ed4f-47a1-85ec-c223128531e4" class="xr-var-data-in" type="checkbox"><label for="data-da0ab164-ed4f-47a1-85ec-c223128531e4" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[0.70107658, 0.68827585, 0.59695125, ..., 0.73061048, 0.85816406,
        0.66033115],
       [0.64176871, 0.73289075, 0.69317721, ..., 0.8186892 , 0.69504086,
        0.66579574],
       [0.61403385, 0.65582589, 0.75810312, ..., 0.55300632, 0.55300632,
        0.5280372 ],
       [0.58837632, 0.89276319, 0.77054577, ..., 0.50940075, 1.59069856,
        1.37023692]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>mu</span></div><div class="xr-var-dims">(chain, draw, obs_ind)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">1.945 8.03 2.093 ... 11.46 14.99</div><input id="attrs-c21201d8-d106-4ffd-9929-8ad7049d1054" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-c21201d8-d106-4ffd-9929-8ad7049d1054" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-fcb11fa0-f4e6-44e0-b762-4913886abfb9" class="xr-var-data-in" type="checkbox"><label for="data-fcb11fa0-f4e6-44e0-b762-4913886abfb9" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[[ 1.94470661,  8.03043743,  2.09328327, ..., 11.52761483,
         11.68017114, 16.49591513],
        [ 1.94645363,  9.33153659,  2.51044292, ..., 11.28644677,
         11.41894249, 15.6014339 ],
        [ 1.28224868,  8.29613184,  3.34024797, ..., 10.90587786,
         11.03756435, 15.19451093],
        ...,
        [ 1.51158476,  8.23095848,  2.51361818, ..., 11.06241781,
         11.20242221, 15.62194032],
        [ 2.89002366,  7.05688094,  2.33611636, ..., 11.27516011,
         11.44104241, 16.67744785],
        [ 0.13786335,  7.98755627,  2.20148859, ..., 11.1906623 ,
         11.3230384 , 15.50175383]],

       [[ 2.55404738,  7.86942416,  2.45754802, ..., 11.26432885,
         11.40835139, 15.95470977],
        [ 0.8756618 ,  8.93239092,  2.38993455, ..., 11.36155132,
         11.5119711 , 16.26027117],
        [ 2.14561451,  8.53319829,  1.6823322 , ..., 10.94590488,
         11.0872544 , 15.54923349],
...
        [ 2.42986831,  8.68300079,  1.527288  , ..., 11.06522484,
         11.21472469, 15.93398551],
        [ 2.42986831,  8.68300079,  1.527288  , ..., 11.06522484,
         11.21472469, 15.93398551],
        [ 1.99239388,  7.48577494,  2.49523268, ..., 11.31787262,
         11.47053539, 16.28963987]],

       [[ 0.94561825,  7.77237644,  1.28181747, ..., 11.30882597,
         11.45445053, 16.05137986],
        [ 2.11180683,  9.38573249,  2.94374235, ..., 11.64796762,
         11.8000305 , 16.60019845],
        [ 2.41251044,  8.98489946,  2.23513107, ..., 11.13826441,
         11.27855727, 15.70718107],
        ...,
        [ 1.75314348,  7.87344266,  2.22012221, ..., 11.06699902,
         11.22211768, 16.11874729],
        [ 0.86854086,  8.51455739,  2.39898394, ..., 11.13442568,
         11.24718438, 14.80663754],
        [ 0.59323692,  7.93078924,  2.60821023, ..., 11.3449246 ,
         11.45677163, 14.98744607]]], shape=(4, 1000, 20))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-2cb2ef8d-adf4-4aa2-83a1-bb3255c09b76" class="xr-section-summary-in" type="checkbox"><label for="section-2cb2ef8d-adf4-4aa2-83a1-bb3255c09b76" class="xr-section-summary">Indexes: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-index-name"><div>chain</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-e6ce4236-9d92-4dbd-aaf7-3822d1d3e427" class="xr-index-data-in" type="checkbox"><label for="index-e6ce4236-9d92-4dbd-aaf7-3822d1d3e427" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3], dtype='int64', name='chain'))</pre></div></li><li class="xr-var-item"><div class="xr-index-name"><div>draw</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-92042116-9a52-4e48-88f4-994fd4e73369" class="xr-index-data-in" type="checkbox"><label for="index-92042116-9a52-4e48-88f4-994fd4e73369" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
       ...
       990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
      dtype='int64', name='draw', length=1000))</pre></div></li><li class="xr-var-item"><div class="xr-index-name"><div>groups</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-04075fae-2af0-49e4-b7ad-c49bcfd20031" class="xr-index-data-in" type="checkbox"><label for="index-04075fae-2af0-49e4-b7ad-c49bcfd20031" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3], dtype='int64', name='groups'))</pre></div></li><li class="xr-var-item"><div class="xr-index-name"><div>obs_ind</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-4542b62c-7812-48e7-a74a-19d6d4b5311b" class="xr-index-data-in" type="checkbox"><label for="index-4542b62c-7812-48e7-a74a-19d6d4b5311b" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype='int64', name='obs_ind'))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-54dd0cae-1aee-4fed-8a56-d77ec2b42d93" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-54dd0cae-1aee-4fed-8a56-d77ec2b42d93" class="xr-section-summary">Attributes: <span>(6)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><dl class="xr-attrs"><dt><span>created_at :</span></dt><dd>2025-05-02T14:24:27.321753+00:00</dd><dt><span>arviz_version :</span></dt><dd>0.21.0</dd><dt><span>inference_library :</span></dt><dd>pymc</dd><dt><span>inference_library_version :</span></dt><dd>5.22.0</dd><dt><span>sampling_time :</span></dt><dd>1.5654027462005615</dd><dt><span>tuning_steps :</span></dt><dd>1000</dd></dl></div></li></ul></div></div><br></div>
                      </ul>
                  </div>
            </li>
            
            <li class="xr-section-item">
                  <input id="idata_predictions7d402feb-c779-4564-8e89-d6226431ad98" class="xr-section-summary-in" type="checkbox">
                  <label for="idata_predictions7d402feb-c779-4564-8e89-d6226431ad98" class="xr-section-summary">predictions</label>
                  <div class="xr-section-inline-details"></div>
                  <div class="xr-section-details">
                      <ul id="xr-dataset-coord-list" class="xr-var-list">
                          <div style="padding-left:2rem;"><div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewbox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewbox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>
<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1f1f1f;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block !important;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: inline-block;
  opacity: 0;
  height: 0;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:focus + label {
  border: 2px solid var(--xr-font-color0);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: "►";
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: "▼";
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: "(";
}

.xr-dim-list:after {
  content: ")";
}

.xr-dim-list li:not(:last-child):after {
  content: ",";
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-index-preview {
  grid-column: 2 / 5;
  color: var(--xr-font-color2);
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data,
.xr-index-data-in:checked ~ .xr-index-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
.xr-index-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
</style><pre class="xr-text-repr-fallback">&lt;xarray.Dataset&gt; Size: 5MB
Dimensions:  (chain: 4, draw: 1000, obs_ind: 80)
Coordinates:
  * chain    (chain) int64 32B 0 1 2 3
  * draw     (draw) int64 8kB 0 1 2 3 4 5 6 7 ... 993 994 995 996 997 998 999
  * obs_ind  (obs_ind) int64 640B 0 1 2 3 4 5 6 7 8 ... 72 73 74 75 76 77 78 79
Data variables:
    mu       (chain, draw, obs_ind) float64 3MB 1.945 2.265 ... 14.47 14.99
    y        (chain, draw, obs_ind) float64 3MB 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0
Attributes:
    created_at:                 2025-05-02T14:24:27.413261+00:00
    arviz_version:              0.21.0
    inference_library:          pymc
    inference_library_version:  5.22.0</pre><div class="xr-wrap" style="display:none"><div class="xr-header"><div class="xr-obj-type">xarray.Dataset</div></div><ul class="xr-sections"><li class="xr-section-item"><input id="section-367c7273-7332-4dcd-bfd4-d0c3ce181a12" class="xr-section-summary-in" type="checkbox" disabled=""><label for="section-367c7273-7332-4dcd-bfd4-d0c3ce181a12" class="xr-section-summary" title="Expand/collapse section">Dimensions:</label><div class="xr-section-inline-details"><ul class="xr-dim-list"><li><span class="xr-has-index">chain</span>: 4</li><li><span class="xr-has-index">draw</span>: 1000</li><li><span class="xr-has-index">obs_ind</span>: 80</li></ul></div><div class="xr-section-details"></div></li><li class="xr-section-item"><input id="section-8a775843-4499-4637-baaa-2d1879d27a30" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-8a775843-4499-4637-baaa-2d1879d27a30" class="xr-section-summary">Coordinates: <span>(3)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">chain</span></div><div class="xr-var-dims">(chain)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3</div><input id="attrs-0f2b8c3b-1837-44a6-bf2b-20cde2b12cb4" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-0f2b8c3b-1837-44a6-bf2b-20cde2b12cb4" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-81812fa1-830a-462c-8327-9d6f31a2ac38" class="xr-var-data-in" type="checkbox"><label for="data-81812fa1-830a-462c-8327-9d6f31a2ac38" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([0, 1, 2, 3])</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">draw</span></div><div class="xr-var-dims">(draw)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 ... 995 996 997 998 999</div><input id="attrs-1588090a-2797-4e9f-83f8-1f39fca9a9d1" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-1588090a-2797-4e9f-83f8-1f39fca9a9d1" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-0dabaf70-bc17-4e3b-85ae-4b7311c6f9e8" class="xr-var-data-in" type="checkbox"><label for="data-0dabaf70-bc17-4e3b-85ae-4b7311c6f9e8" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([  0,   1,   2, ..., 997, 998, 999], shape=(1000,))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">obs_ind</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 6 ... 74 75 76 77 78 79</div><input id="attrs-43e79234-833c-499b-80cd-a8489bb17825" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-43e79234-833c-499b-80cd-a8489bb17825" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-f06f268e-197e-44e7-9134-88062ef184af" class="xr-var-data-in" type="checkbox"><label for="data-f06f268e-197e-44e7-9134-88062ef184af" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
       36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
       54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
       72, 73, 74, 75, 76, 77, 78, 79])</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-1dc70799-c730-46e1-98a5-d9c8b488d058" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-1dc70799-c730-46e1-98a5-d9c8b488d058" class="xr-section-summary">Data variables: <span>(2)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span>mu</span></div><div class="xr-var-dims">(chain, draw, obs_ind)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">1.945 2.265 2.585 ... 14.47 14.99</div><input id="attrs-90773d1a-56fe-48f1-8cd1-b502f38a40c5" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-90773d1a-56fe-48f1-8cd1-b502f38a40c5" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-a3e11b09-03ba-498f-82e9-60548699557d" class="xr-var-data-in" type="checkbox"><label for="data-a3e11b09-03ba-498f-82e9-60548699557d" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[[ 1.94470661,  2.26500823,  2.58530985, ..., 15.08597314,
         15.79094413, 16.49591513],
        [ 1.94645363,  2.33514221,  2.72383079, ..., 14.37689408,
         14.98916399, 15.6014339 ],
        [ 1.28224868,  1.65140042,  2.02055217, ..., 13.97745006,
         14.5859805 , 15.19451093],
        ...,
        [ 1.51158476,  1.865236  ,  2.21888725, ..., 14.32800439,
         14.97497236, 15.62194032],
        [ 2.89002366,  3.10933193,  3.32864021, ..., 15.1443456 ,
         15.91089672, 16.67744785],
        [ 0.13786335,  0.55100509,  0.96414682, ..., 14.27831953,
         14.89003668, 15.50175383]],

       [[ 2.55404738,  2.83380405,  3.11356072, ..., 14.62363785,
         15.28917381, 15.95470977],
        [ 0.8756618 ,  1.29970017,  1.72373855, ..., 14.87007524,
         15.56517321, 16.26027117],
        [ 2.14561451,  2.48180313,  2.81799175, ..., 14.24286593,
         14.89604971, 15.54923349],
...
        [ 2.42986831,  2.75898054,  3.08809278, ..., 14.55229163,
         15.24313857, 15.93398551],
        [ 2.42986831,  2.75898054,  3.08809278, ..., 14.55229163,
         15.24313857, 15.93398551],
        [ 1.99239388,  2.2815192 ,  2.57064452, ..., 14.878714  ,
         15.58417693, 16.28963987]],

       [[ 0.94561825,  1.30492132,  1.66422438, ..., 14.70550189,
         15.37844088, 16.05137986],
        [ 2.11180683,  2.49464502,  2.87748322, ..., 15.19481677,
         15.89750761, 16.60019845],
        [ 2.41251044,  2.75842565,  3.10434086, ..., 14.4105792 ,
         15.05888013, 15.70718107],
        ...,
        [ 1.75314348,  2.07526449,  2.3973855 , ..., 14.68512379,
         15.40193554, 16.11874729],
        [ 0.86854086,  1.27096278,  1.6733847 , ..., 13.76450937,
         14.28557346, 14.80663754],
        [ 0.59323692,  0.97942388,  1.36561085, ..., 13.95374366,
         14.47059486, 14.98744607]]], shape=(4, 1000, 80))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>y</span></div><div class="xr-var-dims">(chain, draw, obs_ind)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0</div><input id="attrs-8d7df171-870f-4633-a851-2c25afde2413" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-8d7df171-870f-4633-a851-2c25afde2413" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-2a130d0b-ed36-4f22-88b6-e759f1fe9dc2" class="xr-var-data-in" type="checkbox"><label for="data-2a130d0b-ed36-4f22-88b6-e759f1fe9dc2" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[[0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        ...,
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.]],

       [[0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        ...,
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.]],

       [[0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        ...,
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.]],

       [[0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        ...,
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.],
        [0., 0., 0., ..., 0., 0., 0.]]], shape=(4, 1000, 80))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-a70cfeab-9dbb-4933-8b5a-94bd7649bf50" class="xr-section-summary-in" type="checkbox"><label for="section-a70cfeab-9dbb-4933-8b5a-94bd7649bf50" class="xr-section-summary">Indexes: <span>(3)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-index-name"><div>chain</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-e1305f67-030e-4eaa-abd7-1942a46f66c8" class="xr-index-data-in" type="checkbox"><label for="index-e1305f67-030e-4eaa-abd7-1942a46f66c8" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3], dtype='int64', name='chain'))</pre></div></li><li class="xr-var-item"><div class="xr-index-name"><div>draw</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-e00fc7d3-ddfa-44a0-9fc3-b887abfcbdbc" class="xr-index-data-in" type="checkbox"><label for="index-e00fc7d3-ddfa-44a0-9fc3-b887abfcbdbc" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
       ...
       990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
      dtype='int64', name='draw', length=1000))</pre></div></li><li class="xr-var-item"><div class="xr-index-name"><div>obs_ind</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-1ef9ef1a-452d-4dfc-af5a-5397b7430762" class="xr-index-data-in" type="checkbox"><label for="index-1ef9ef1a-452d-4dfc-af5a-5397b7430762" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
       36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
       54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
       72, 73, 74, 75, 76, 77, 78, 79],
      dtype='int64', name='obs_ind'))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-c3928162-0e9b-4288-8a8f-a38195d7f738" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-c3928162-0e9b-4288-8a8f-a38195d7f738" class="xr-section-summary">Attributes: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><dl class="xr-attrs"><dt><span>created_at :</span></dt><dd>2025-05-02T14:24:27.413261+00:00</dd><dt><span>arviz_version :</span></dt><dd>0.21.0</dd><dt><span>inference_library :</span></dt><dd>pymc</dd><dt><span>inference_library_version :</span></dt><dd>5.22.0</dd></dl></div></li></ul></div></div><br></div>
                      </ul>
                  </div>
            </li>
            
            <li class="xr-section-item">
                  <input id="idata_sample_statse35349be-e623-4d61-9d96-c5dcb5b7fab5" class="xr-section-summary-in" type="checkbox">
                  <label for="idata_sample_statse35349be-e623-4d61-9d96-c5dcb5b7fab5" class="xr-section-summary">sample_stats</label>
                  <div class="xr-section-inline-details"></div>
                  <div class="xr-section-details">
                      <ul id="xr-dataset-coord-list" class="xr-var-list">
                          <div style="padding-left:2rem;"><div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewbox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewbox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>
<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1f1f1f;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block !important;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: inline-block;
  opacity: 0;
  height: 0;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:focus + label {
  border: 2px solid var(--xr-font-color0);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: "►";
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: "▼";
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: "(";
}

.xr-dim-list:after {
  content: ")";
}

.xr-dim-list li:not(:last-child):after {
  content: ",";
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-index-preview {
  grid-column: 2 / 5;
  color: var(--xr-font-color2);
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data,
.xr-index-data-in:checked ~ .xr-index-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
.xr-index-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
</style><pre class="xr-text-repr-fallback">&lt;xarray.Dataset&gt; Size: 496kB
Dimensions:                (chain: 4, draw: 1000)
Coordinates:
  * chain                  (chain) int64 32B 0 1 2 3
  * draw                   (draw) int64 8kB 0 1 2 3 4 5 ... 995 996 997 998 999
Data variables: (12/17)
    energy_error           (chain, draw) float64 32kB -0.5604 0.2792 ... 0.0619
    reached_max_treedepth  (chain, draw) bool 4kB False False ... False False
    acceptance_rate        (chain, draw) float64 32kB 0.9922 0.8937 ... 0.9854
    diverging              (chain, draw) bool 4kB False False ... False False
    energy                 (chain, draw) float64 32kB 45.97 45.99 ... 53.51
    index_in_trajectory    (chain, draw) int64 32kB 8 -4 1 -10 7 ... 12 4 11 -2
    ...                     ...
    step_size              (chain, draw) float64 32kB 0.2877 0.2877 ... 0.2709
    process_time_diff      (chain, draw) float64 32kB 0.000489 ... 0.000262
    smallest_eigval        (chain, draw) float64 32kB nan nan nan ... nan nan
    perf_counter_start     (chain, draw) float64 32kB 6.765e+05 ... 6.765e+05
    step_size_bar          (chain, draw) float64 32kB 0.2695 0.2695 ... 0.2744
    lp                     (chain, draw) float64 32kB -41.07 -44.0 ... -51.52
Attributes:
    created_at:                 2025-05-02T14:24:27.332355+00:00
    arviz_version:              0.21.0
    inference_library:          pymc
    inference_library_version:  5.22.0
    sampling_time:              1.5654027462005615
    tuning_steps:               1000</pre><div class="xr-wrap" style="display:none"><div class="xr-header"><div class="xr-obj-type">xarray.Dataset</div></div><ul class="xr-sections"><li class="xr-section-item"><input id="section-ac96e261-4d92-4d08-a7b3-820e444c0e66" class="xr-section-summary-in" type="checkbox" disabled=""><label for="section-ac96e261-4d92-4d08-a7b3-820e444c0e66" class="xr-section-summary" title="Expand/collapse section">Dimensions:</label><div class="xr-section-inline-details"><ul class="xr-dim-list"><li><span class="xr-has-index">chain</span>: 4</li><li><span class="xr-has-index">draw</span>: 1000</li></ul></div><div class="xr-section-details"></div></li><li class="xr-section-item"><input id="section-28d5f05b-400a-42c6-83fe-e90ec23b8718" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-28d5f05b-400a-42c6-83fe-e90ec23b8718" class="xr-section-summary">Coordinates: <span>(2)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">chain</span></div><div class="xr-var-dims">(chain)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3</div><input id="attrs-fa1811e6-371c-4b04-9122-8de382708377" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-fa1811e6-371c-4b04-9122-8de382708377" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-63e448e4-f0f8-42b2-bc56-3f7542a8547f" class="xr-var-data-in" type="checkbox"><label for="data-63e448e4-f0f8-42b2-bc56-3f7542a8547f" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([0, 1, 2, 3])</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">draw</span></div><div class="xr-var-dims">(draw)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 ... 995 996 997 998 999</div><input id="attrs-d82136d4-4054-4ba4-890f-1bd17c280cbd" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-d82136d4-4054-4ba4-890f-1bd17c280cbd" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-8709a788-3519-4ed5-beeb-e3cb0de0f029" class="xr-var-data-in" type="checkbox"><label for="data-8709a788-3519-4ed5-beeb-e3cb0de0f029" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([  0,   1,   2, ..., 997, 998, 999], shape=(1000,))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-12f70296-695c-4777-aa4b-7d23ccbd3dfb" class="xr-section-summary-in" type="checkbox"><label for="section-12f70296-695c-4777-aa4b-7d23ccbd3dfb" class="xr-section-summary">Data variables: <span>(17)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span>energy_error</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">-0.5604 0.2792 ... 2.772 0.0619</div><input id="attrs-5e555249-c3b3-4607-9f0b-6a8dad9873cb" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-5e555249-c3b3-4607-9f0b-6a8dad9873cb" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-cd9c16ff-f841-4edb-83e8-33f758a4ff30" class="xr-var-data-in" type="checkbox"><label for="data-cd9c16ff-f841-4edb-83e8-33f758a4ff30" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[-0.5604309 ,  0.27920731, -1.12393342, ...,  0.14039449,
         0.37810731,  0.24605628],
       [-0.07718611, -0.0448022 , -0.19793457, ...,  0.20615696,
        -0.19500182, -0.44928881],
       [ 0.42022204, -1.07057488,  0.1609779 , ..., -1.19276468,
         0.        ,  0.25472307],
       [ 0.31838168,  2.35317853, -0.3471548 , ..., -0.48705718,
         2.77186521,  0.06189837]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>reached_max_treedepth</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">bool</div><div class="xr-var-preview xr-preview">False False False ... False False</div><input id="attrs-fa72be1f-14b9-4861-9d22-19d1556fdd2c" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-fa72be1f-14b9-4861-9d22-19d1556fdd2c" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-83b26fa7-d4a4-4226-8efc-e8296855711d" class="xr-var-data-in" type="checkbox"><label for="data-83b26fa7-d4a4-4226-8efc-e8296855711d" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>acceptance_rate</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.9922 0.8937 ... 0.06641 0.9854</div><input id="attrs-592a15eb-86e5-453f-b30c-e293530aaeb3" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-592a15eb-86e5-453f-b30c-e293530aaeb3" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-5be080b9-1004-45f3-b712-68081a1cf974" class="xr-var-data-in" type="checkbox"><label for="data-5be080b9-1004-45f3-b712-68081a1cf974" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[0.99215989, 0.89367733, 0.84955218, ..., 0.63761237, 0.53874176,
        0.86766693],
       [0.94758945, 0.90990965, 0.58494046, ..., 0.74137868, 0.63289058,
        0.87856315],
       [0.94643798, 1.        , 0.77568514, ..., 0.318086  , 0.01787461,
        0.28057653],
       [0.9278176 , 0.0842188 , 0.94939803, ..., 0.80950875, 0.06641064,
        0.98543094]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>diverging</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">bool</div><div class="xr-var-preview xr-preview">False False False ... False False</div><input id="attrs-1b02341a-e402-4998-b928-14fa0856695a" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-1b02341a-e402-4998-b928-14fa0856695a" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-3aa33d79-b1b2-4737-9a93-2da1a3e8bf10" class="xr-var-data-in" type="checkbox"><label for="data-3aa33d79-b1b2-4737-9a93-2da1a3e8bf10" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>energy</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">45.97 45.99 49.38 ... 53.02 53.51</div><input id="attrs-16bb93da-a857-4c02-8037-342b8727a38e" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-16bb93da-a857-4c02-8037-342b8727a38e" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-cd755634-bc04-4d6e-9eca-584f9e17fdfe" class="xr-var-data-in" type="checkbox"><label for="data-cd755634-bc04-4d6e-9eca-584f9e17fdfe" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[45.97393189, 45.99474451, 49.37867337, ..., 43.49506259,
        48.21534859, 49.20470443],
       [43.03462097, 43.06901479, 46.07137476, ..., 45.38463085,
        46.5862229 , 43.15359428],
       [47.56784163, 45.9847832 , 47.07354757, ..., 52.40776359,
        51.7678265 , 47.5946609 ],
       [45.43472193, 53.93571186, 48.18684059, ..., 44.60444273,
        53.01604443, 53.51144545]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>index_in_trajectory</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">8 -4 1 -10 7 0 ... -2 -2 12 4 11 -2</div><input id="attrs-cf9b7061-0984-4b0b-9ae4-1ba769871921" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-cf9b7061-0984-4b0b-9ae4-1ba769871921" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-c32a9cb2-6b2c-4341-a112-3a7c3bc7b252" class="xr-var-data-in" type="checkbox"><label for="data-c32a9cb2-6b2c-4341-a112-3a7c3bc7b252" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[  8,  -4,   1, ...,   8,  10, -13],
       [ -4, -11,  -7, ...,  -8,  13, -10],
       [-10,   1,  -4, ...,   2,   0,   3],
       [ -6,  -6,  14, ...,   4,  11,  -2]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>perf_counter_diff</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.0004882 0.0003583 ... 0.0002623</div><input id="attrs-de352cf1-cbc9-4d24-846a-e3802bc9756c" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-de352cf1-cbc9-4d24-846a-e3802bc9756c" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-109a3fd1-860d-4356-8a1b-636effed3a5f" class="xr-var-data-in" type="checkbox"><label for="data-109a3fd1-860d-4356-8a1b-636effed3a5f" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[0.00048825, 0.00035833, 0.00027292, ..., 0.00048125, 0.00047954,
        0.00048438],
       [0.00048021, 0.00048875, 0.00048054, ..., 0.00046267, 0.00046258,
        0.00045404],
       [0.00047346, 0.00023708, 0.00035083, ..., 0.00413521, 0.00025154,
        0.00048338],
       [0.00049079, 0.00024183, 0.00048317, ..., 0.00048242, 0.00048896,
        0.00026233]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>largest_eigval</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">nan nan nan nan ... nan nan nan nan</div><input id="attrs-1187ddca-54dd-4b28-b646-b18666cec8f0" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-1187ddca-54dd-4b28-b646-b18666cec8f0" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-c17c0c8f-3e7f-4d0e-a053-93d9a8e2c7f7" class="xr-var-data-in" type="checkbox"><label for="data-c17c0c8f-3e7f-4d0e-a053-93d9a8e2c7f7" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>tree_depth</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">4 4 3 4 4 2 3 3 ... 4 4 4 4 4 4 4 3</div><input id="attrs-75b29ee1-6b0e-4a77-8dd0-d6aea5765350" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-75b29ee1-6b0e-4a77-8dd0-d6aea5765350" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-da10c942-ae16-43c6-93cb-946b04344be4" class="xr-var-data-in" type="checkbox"><label for="data-da10c942-ae16-43c6-93cb-946b04344be4" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[4, 4, 3, ..., 4, 4, 4],
       [4, 4, 4, ..., 4, 4, 4],
       [4, 3, 4, ..., 4, 3, 4],
       [4, 3, 4, ..., 4, 4, 3]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>max_energy_error</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">-0.5604 0.4537 ... 3.749 -0.2256</div><input id="attrs-2cae12fe-6e5a-44db-8d59-b66cb75434ee" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-2cae12fe-6e5a-44db-8d59-b66cb75434ee" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-c376b45d-fbe9-4442-b677-aaddc8f34cfe" class="xr-var-data-in" type="checkbox"><label for="data-c376b45d-fbe9-4442-b677-aaddc8f34cfe" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[-0.5604309 ,  0.45368978, -1.12393342, ...,  0.86568608,
         1.71693025,  0.39665647],
       [-0.39820123,  0.26955894,  1.4751485 , ...,  0.60576332,
         1.19682017, -0.48364874],
       [-0.66430451, -1.4399029 ,  0.81304013, ...,  3.71119527,
         9.77709546,  3.19391519],
       [-0.47114156,  3.24506207, -0.73123819, ...,  1.28041881,
         3.74947245, -0.22563799]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>n_steps</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">15.0 11.0 7.0 ... 15.0 15.0 7.0</div><input id="attrs-4c54824e-678a-42c7-a7af-5be203b27f34" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-4c54824e-678a-42c7-a7af-5be203b27f34" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-f7599ce6-7f7f-4ceb-b159-44eec946357b" class="xr-var-data-in" type="checkbox"><label for="data-f7599ce6-7f7f-4ceb-b159-44eec946357b" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[15., 11.,  7., ..., 15., 15., 15.],
       [15., 15., 15., ..., 15., 15., 15.],
       [15.,  7., 11., ..., 15.,  7., 15.],
       [15.,  7., 15., ..., 15., 15.,  7.]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>step_size</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.2877 0.2877 ... 0.2709 0.2709</div><input id="attrs-7614d69b-62bf-4d8c-9861-b27bc6231dc7" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-7614d69b-62bf-4d8c-9861-b27bc6231dc7" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-18d0d56b-4edc-428d-9092-c84dc62795b2" class="xr-var-data-in" type="checkbox"><label for="data-18d0d56b-4edc-428d-9092-c84dc62795b2" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[0.28774935, 0.28774935, 0.28774935, ..., 0.28774935, 0.28774935,
        0.28774935],
       [0.38122138, 0.38122138, 0.38122138, ..., 0.38122138, 0.38122138,
        0.38122138],
       [0.22514426, 0.22514426, 0.22514426, ..., 0.22514426, 0.22514426,
        0.22514426],
       [0.2708713 , 0.2708713 , 0.2708713 , ..., 0.2708713 , 0.2708713 ,
        0.2708713 ]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>process_time_diff</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.000489 0.000358 ... 0.000262</div><input id="attrs-c2b286bc-d549-492e-bdb0-bb65ba352574" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-c2b286bc-d549-492e-bdb0-bb65ba352574" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-ad0de6ae-226f-4a1e-8b87-ad8e874d72b5" class="xr-var-data-in" type="checkbox"><label for="data-ad0de6ae-226f-4a1e-8b87-ad8e874d72b5" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[0.000489, 0.000358, 0.000266, ..., 0.000482, 0.00048 , 0.000484],
       [0.000479, 0.000489, 0.00048 , ..., 0.000463, 0.000463, 0.000454],
       [0.000475, 0.000237, 0.000351, ..., 0.001274, 0.000251, 0.000483],
       [0.000491, 0.000243, 0.000484, ..., 0.000482, 0.00049 , 0.000262]],
      shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>smallest_eigval</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">nan nan nan nan ... nan nan nan nan</div><input id="attrs-fcaaf71b-4598-47cd-afa1-d4482d14644a" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-fcaaf71b-4598-47cd-afa1-d4482d14644a" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-733d9dfa-6137-4d90-bafd-a7fda655f21b" class="xr-var-data-in" type="checkbox"><label for="data-733d9dfa-6137-4d90-bafd-a7fda655f21b" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>perf_counter_start</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">6.765e+05 6.765e+05 ... 6.765e+05</div><input id="attrs-af87abe9-3384-4f42-a267-945b2f6eb457" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-af87abe9-3384-4f42-a267-945b2f6eb457" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-10be885d-da29-488c-b3bd-8f8043667ffe" class="xr-var-data-in" type="checkbox"><label for="data-10be885d-da29-488c-b3bd-8f8043667ffe" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[676490.686682  , 676490.68721187, 676490.68761067, ...,
        676491.21102325, 676491.21154429, 676491.21206262],
       [676490.62572796, 676490.62625029, 676490.62678296, ...,
        676491.16271092, 676491.16321229, 676491.163712  ],
       [676490.67355042, 676490.67407879, 676490.67435363, ...,
        676491.25928342, 676491.26350933, 676491.26381021],
       [676490.65493158, 676490.65546608, 676490.65574792, ...,
        676491.21229008, 676491.21280921, 676491.21631221]],
      shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>step_size_bar</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">0.2695 0.2695 ... 0.2744 0.2744</div><input id="attrs-0447a247-9ca1-476c-aa02-0ebd61eda086" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-0447a247-9ca1-476c-aa02-0ebd61eda086" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-01a0cb2c-397f-47fc-8930-2b2af47785b5" class="xr-var-data-in" type="checkbox"><label for="data-01a0cb2c-397f-47fc-8930-2b2af47785b5" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[0.26949419, 0.26949419, 0.26949419, ..., 0.26949419, 0.26949419,
        0.26949419],
       [0.27986525, 0.27986525, 0.27986525, ..., 0.27986525, 0.27986525,
        0.27986525],
       [0.26619142, 0.26619142, 0.26619142, ..., 0.26619142, 0.26619142,
        0.26619142],
       [0.27442445, 0.27442445, 0.27442445, ..., 0.27442445, 0.27442445,
        0.27442445]], shape=(4, 1000))</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>lp</span></div><div class="xr-var-dims">(chain, draw)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">-41.07 -44.0 ... -51.88 -51.52</div><input id="attrs-417b9067-03ba-4ff7-b2b4-e5160fc24572" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-417b9067-03ba-4ff7-b2b4-e5160fc24572" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-f4f3a7c4-1e95-4274-b92d-79273ae0bef2" class="xr-var-data-in" type="checkbox"><label for="data-f4f3a7c4-1e95-4274-b92d-79273ae0bef2" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([[-41.06824294, -43.99986513, -43.39303114, ..., -40.76566071,
        -45.96272744, -45.36904947],
       [-41.65773848, -41.63143409, -41.60952909, ..., -41.67377221,
        -41.95538758, -41.23552628],
       [-45.01610075, -41.86386052, -41.8325865 , ..., -41.89829893,
        -41.89829893, -42.73851568],
       [-43.76723966, -44.76412616, -43.21989952, ..., -41.71136624,
        -51.8800495 , -51.52204418]], shape=(4, 1000))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-b3ac9532-1124-4344-a41e-5d09a37578f2" class="xr-section-summary-in" type="checkbox"><label for="section-b3ac9532-1124-4344-a41e-5d09a37578f2" class="xr-section-summary">Indexes: <span>(2)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-index-name"><div>chain</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-dd219966-d7f3-4b0a-bf7d-39fb64ddc971" class="xr-index-data-in" type="checkbox"><label for="index-dd219966-d7f3-4b0a-bf7d-39fb64ddc971" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3], dtype='int64', name='chain'))</pre></div></li><li class="xr-var-item"><div class="xr-index-name"><div>draw</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-9eb3bd60-4d44-4f17-9055-ec40808ff665" class="xr-index-data-in" type="checkbox"><label for="index-9eb3bd60-4d44-4f17-9055-ec40808ff665" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
       ...
       990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
      dtype='int64', name='draw', length=1000))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-02f99e4c-3957-496a-921b-66505ebc7ad5" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-02f99e4c-3957-496a-921b-66505ebc7ad5" class="xr-section-summary">Attributes: <span>(6)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><dl class="xr-attrs"><dt><span>created_at :</span></dt><dd>2025-05-02T14:24:27.332355+00:00</dd><dt><span>arviz_version :</span></dt><dd>0.21.0</dd><dt><span>inference_library :</span></dt><dd>pymc</dd><dt><span>inference_library_version :</span></dt><dd>5.22.0</dd><dt><span>sampling_time :</span></dt><dd>1.5654027462005615</dd><dt><span>tuning_steps :</span></dt><dd>1000</dd></dl></div></li></ul></div></div><br></div>
                      </ul>
                  </div>
            </li>
            
            <li class="xr-section-item">
                  <input id="idata_observed_data80e5a0c5-2364-434e-bb3a-32e9155aa7b6" class="xr-section-summary-in" type="checkbox">
                  <label for="idata_observed_data80e5a0c5-2364-434e-bb3a-32e9155aa7b6" class="xr-section-summary">observed_data</label>
                  <div class="xr-section-inline-details"></div>
                  <div class="xr-section-details">
                      <ul id="xr-dataset-coord-list" class="xr-var-list">
                          <div style="padding-left:2rem;"><div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewbox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewbox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>
<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1f1f1f;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block !important;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: inline-block;
  opacity: 0;
  height: 0;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:focus + label {
  border: 2px solid var(--xr-font-color0);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: "►";
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: "▼";
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: "(";
}

.xr-dim-list:after {
  content: ")";
}

.xr-dim-list li:not(:last-child):after {
  content: ",";
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-index-preview {
  grid-column: 2 / 5;
  color: var(--xr-font-color2);
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data,
.xr-index-data-in:checked ~ .xr-index-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
.xr-index-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
</style><pre class="xr-text-repr-fallback">&lt;xarray.Dataset&gt; Size: 320B
Dimensions:  (obs_ind: 20)
Coordinates:
  * obs_ind  (obs_ind) int64 160B 0 1 2 3 4 5 6 7 8 ... 12 13 14 15 16 17 18 19
Data variables:
    obs      (obs_ind) float64 160B 1.647 8.383 2.666 ... 11.06 11.86 15.82
Attributes:
    created_at:                 2025-05-02T14:24:27.335212+00:00
    arviz_version:              0.21.0
    inference_library:          pymc
    inference_library_version:  5.22.0</pre><div class="xr-wrap" style="display:none"><div class="xr-header"><div class="xr-obj-type">xarray.Dataset</div></div><ul class="xr-sections"><li class="xr-section-item"><input id="section-299baaa6-dd8e-43bc-8c95-3c3178e4e7d5" class="xr-section-summary-in" type="checkbox" disabled=""><label for="section-299baaa6-dd8e-43bc-8c95-3c3178e4e7d5" class="xr-section-summary" title="Expand/collapse section">Dimensions:</label><div class="xr-section-inline-details"><ul class="xr-dim-list"><li><span class="xr-has-index">obs_ind</span>: 20</li></ul></div><div class="xr-section-details"></div></li><li class="xr-section-item"><input id="section-2d5253ee-5aa1-4753-a522-8efe3524a793" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-2d5253ee-5aa1-4753-a522-8efe3524a793" class="xr-section-summary">Coordinates: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">obs_ind</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 6 ... 14 15 16 17 18 19</div><input id="attrs-b93c0057-6979-4039-bcb1-883f33ea56ed" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-b93c0057-6979-4039-bcb1-883f33ea56ed" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-a633b9bc-1f99-44ed-9ed0-0e63fb1564f7" class="xr-var-data-in" type="checkbox"><label for="data-a633b9bc-1f99-44ed-9ed0-0e63fb1564f7" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19])</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-c5421092-cf2e-47ce-8a95-ba3f8629ecad" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-c5421092-cf2e-47ce-8a95-ba3f8629ecad" class="xr-section-summary">Data variables: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span>obs</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">1.647 8.383 2.666 ... 11.86 15.82</div><input id="attrs-10a6e9a0-9b5e-416b-baa6-4b8998f8f805" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-10a6e9a0-9b5e-416b-baa6-4b8998f8f805" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-1ec85b19-7f85-4283-857d-056c1a1330a5" class="xr-var-data-in" type="checkbox"><label for="data-1ec85b19-7f85-4283-857d-056c1a1330a5" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 1.64678909,  8.38343666,  2.66604708,  4.76264699,  9.77513523,
       11.68049084,  5.13719115,  8.64802158, 17.97795922, 18.46288665,
       22.81288568, 22.04923185,  3.51424002,  4.72917916,  4.41012639,
        7.65826524,  8.60340265, 11.06015274, 11.85900979, 15.82364649])</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-4ae00e24-d457-45ff-a63f-1946c123878d" class="xr-section-summary-in" type="checkbox"><label for="section-4ae00e24-d457-45ff-a63f-1946c123878d" class="xr-section-summary">Indexes: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-index-name"><div>obs_ind</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-fe8a0f53-964d-4948-918f-d54808eb025d" class="xr-index-data-in" type="checkbox"><label for="index-fe8a0f53-964d-4948-918f-d54808eb025d" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype='int64', name='obs_ind'))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-6a42606d-c461-464b-bfd3-0ed7ecb5573c" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-6a42606d-c461-464b-bfd3-0ed7ecb5573c" class="xr-section-summary">Attributes: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><dl class="xr-attrs"><dt><span>created_at :</span></dt><dd>2025-05-02T14:24:27.335212+00:00</dd><dt><span>arviz_version :</span></dt><dd>0.21.0</dd><dt><span>inference_library :</span></dt><dd>pymc</dd><dt><span>inference_library_version :</span></dt><dd>5.22.0</dd></dl></div></li></ul></div></div><br></div>
                      </ul>
                  </div>
            </li>
            
            <li class="xr-section-item">
                  <input id="idata_constant_data16799355-6361-4724-93bd-1d6b06c13709" class="xr-section-summary-in" type="checkbox">
                  <label for="idata_constant_data16799355-6361-4724-93bd-1d6b06c13709" class="xr-section-summary">constant_data</label>
                  <div class="xr-section-inline-details"></div>
                  <div class="xr-section-details">
                      <ul id="xr-dataset-coord-list" class="xr-var-list">
                          <div style="padding-left:2rem;"><div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewbox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewbox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>
<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1f1f1f;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block !important;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: inline-block;
  opacity: 0;
  height: 0;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:focus + label {
  border: 2px solid var(--xr-font-color0);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: "►";
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: "▼";
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: "(";
}

.xr-dim-list:after {
  content: ")";
}

.xr-dim-list li:not(:last-child):after {
  content: ",";
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-index-preview {
  grid-column: 2 / 5;
  color: var(--xr-font-color2);
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data,
.xr-index-data-in:checked ~ .xr-index-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
.xr-index-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
</style><pre class="xr-text-repr-fallback">&lt;xarray.Dataset&gt; Size: 400B
Dimensions:  (obs_ind: 20)
Coordinates:
  * obs_ind  (obs_ind) int64 160B 0 1 2 3 4 5 6 7 8 ... 12 13 14 15 16 17 18 19
Data variables:
    x        (obs_ind) float64 160B 2.562 9.008 4.545 8.868 ... 9.391 9.514 13.4
    group    (obs_ind) int32 80B 0 0 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3
Attributes:
    created_at:                 2025-05-02T14:24:27.335975+00:00
    arviz_version:              0.21.0
    inference_library:          pymc
    inference_library_version:  5.22.0</pre><div class="xr-wrap" style="display:none"><div class="xr-header"><div class="xr-obj-type">xarray.Dataset</div></div><ul class="xr-sections"><li class="xr-section-item"><input id="section-1ca5d8f9-b0c7-4df9-b419-5064c2144e0e" class="xr-section-summary-in" type="checkbox" disabled=""><label for="section-1ca5d8f9-b0c7-4df9-b419-5064c2144e0e" class="xr-section-summary" title="Expand/collapse section">Dimensions:</label><div class="xr-section-inline-details"><ul class="xr-dim-list"><li><span class="xr-has-index">obs_ind</span>: 20</li></ul></div><div class="xr-section-details"></div></li><li class="xr-section-item"><input id="section-7a7731a1-4fa3-4b09-9e7e-29fb50f9c2b2" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-7a7731a1-4fa3-4b09-9e7e-29fb50f9c2b2" class="xr-section-summary">Coordinates: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">obs_ind</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 6 ... 14 15 16 17 18 19</div><input id="attrs-25a35132-e2f5-4658-8ad8-aa02ec5de7cb" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-25a35132-e2f5-4658-8ad8-aa02ec5de7cb" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-95945e19-e33d-4b82-b772-f58f7712cb05" class="xr-var-data-in" type="checkbox"><label for="data-95945e19-e33d-4b82-b772-f58f7712cb05" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19])</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-980f7dad-b98c-42ae-8921-ced6517cc436" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-980f7dad-b98c-42ae-8921-ced6517cc436" class="xr-section-summary">Data variables: <span>(2)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span>x</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">2.562 9.008 4.545 ... 9.514 13.4</div><input id="attrs-cb37e1f7-3a6d-4969-8675-3c8e35b5f165" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-cb37e1f7-3a6d-4969-8675-3c8e35b5f165" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-c76eb1c7-d69f-44ef-9691-e8b5a3378fc4" class="xr-var-data-in" type="checkbox"><label for="data-c76eb1c7-d69f-44ef-9691-e8b5a3378fc4" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 2.56227265,  9.00771876,  4.54477444,  8.86828398, 12.8773024 ,
       16.45523227,  3.89277416,  7.09051936, 15.1617548 , 15.56766994,
       17.86242243, 19.41396049,  2.59843011,  3.78942718,  4.53818698,
        6.51650716,  7.40919412,  9.39111623,  9.51409852, 13.39627989])</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>group</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int32</div><div class="xr-var-preview xr-preview">0 0 1 1 1 1 2 2 ... 3 3 3 3 3 3 3 3</div><input id="attrs-fafe43bf-e534-4fba-b5d3-d359e9ab6026" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-fafe43bf-e534-4fba-b5d3-d359e9ab6026" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-287cd7e2-975a-4939-a749-8f77d3ed9628" class="xr-var-data-in" type="checkbox"><label for="data-287cd7e2-975a-4939-a749-8f77d3ed9628" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3],
      dtype=int32)</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-e3ace610-b42b-4832-83e7-641fdc80c32a" class="xr-section-summary-in" type="checkbox"><label for="section-e3ace610-b42b-4832-83e7-641fdc80c32a" class="xr-section-summary">Indexes: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-index-name"><div>obs_ind</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-cbbaa83d-3e19-41d9-a490-36e2c43c6db5" class="xr-index-data-in" type="checkbox"><label for="index-cbbaa83d-3e19-41d9-a490-36e2c43c6db5" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype='int64', name='obs_ind'))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-dc04c2ba-4e20-4963-a068-2e85cef3835c" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-dc04c2ba-4e20-4963-a068-2e85cef3835c" class="xr-section-summary">Attributes: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><dl class="xr-attrs"><dt><span>created_at :</span></dt><dd>2025-05-02T14:24:27.335975+00:00</dd><dt><span>arviz_version :</span></dt><dd>0.21.0</dd><dt><span>inference_library :</span></dt><dd>pymc</dd><dt><span>inference_library_version :</span></dt><dd>5.22.0</dd></dl></div></li></ul></div></div><br></div>
                      </ul>
                  </div>
            </li>
            
            <li class="xr-section-item">
                  <input id="idata_predictions_constant_data994ff918-b9e8-487d-ae20-bc1de9adc249" class="xr-section-summary-in" type="checkbox">
                  <label for="idata_predictions_constant_data994ff918-b9e8-487d-ae20-bc1de9adc249" class="xr-section-summary">predictions_constant_data</label>
                  <div class="xr-section-inline-details"></div>
                  <div class="xr-section-details">
                      <ul id="xr-dataset-coord-list" class="xr-var-list">
                          <div style="padding-left:2rem;"><div><svg style="position: absolute; width: 0; height: 0; overflow: hidden">
<defs>
<symbol id="icon-database" viewbox="0 0 32 32">
<path d="M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z"></path>
<path d="M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
<path d="M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z"></path>
</symbol>
<symbol id="icon-file-text2" viewbox="0 0 32 32">
<path d="M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z"></path>
<path d="M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
<path d="M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z"></path>
</symbol>
</defs>
</svg>
<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme="dark"],
html[data-theme="dark"],
body[data-theme="dark"],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1f1f1f;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block !important;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 0 20px 0 20px;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: inline-block;
  opacity: 0;
  height: 0;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:focus + label {
  border: 2px solid var(--xr-font-color0);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: "►";
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: "▼";
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: "(";
}

.xr-dim-list:after {
  content: ")";
}

.xr-dim-list li:not(:last-child):after {
  content: ",";
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-index-preview {
  grid-column: 2 / 5;
  color: var(--xr-font-color2);
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data,
.xr-index-data-in:checked ~ .xr-index-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-index-name div,
.xr-index-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data,
.xr-index-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2,
.xr-no-icon {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
</style><pre class="xr-text-repr-fallback">&lt;xarray.Dataset&gt; Size: 2kB
Dimensions:  (obs_ind: 80)
Coordinates:
  * obs_ind  (obs_ind) int64 640B 0 1 2 3 4 5 6 7 8 ... 72 73 74 75 76 77 78 79
Data variables:
    x        (obs_ind) float64 640B 2.562 2.902 3.241 3.58 ... 12.26 12.83 13.4
    group    (obs_ind) int32 320B 0 0 0 0 0 0 0 0 0 0 0 ... 3 3 3 3 3 3 3 3 3 3
Attributes:
    created_at:                 2025-05-02T14:24:27.414827+00:00
    arviz_version:              0.21.0
    inference_library:          pymc
    inference_library_version:  5.22.0</pre><div class="xr-wrap" style="display:none"><div class="xr-header"><div class="xr-obj-type">xarray.Dataset</div></div><ul class="xr-sections"><li class="xr-section-item"><input id="section-510c732f-a008-46b5-8f27-082f58fd908b" class="xr-section-summary-in" type="checkbox" disabled=""><label for="section-510c732f-a008-46b5-8f27-082f58fd908b" class="xr-section-summary" title="Expand/collapse section">Dimensions:</label><div class="xr-section-inline-details"><ul class="xr-dim-list"><li><span class="xr-has-index">obs_ind</span>: 80</li></ul></div><div class="xr-section-details"></div></li><li class="xr-section-item"><input id="section-692404ed-578a-4fd3-a998-bf93c2b2a497" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-692404ed-578a-4fd3-a998-bf93c2b2a497" class="xr-section-summary">Coordinates: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span class="xr-has-index">obs_ind</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int64</div><div class="xr-var-preview xr-preview">0 1 2 3 4 5 6 ... 74 75 76 77 78 79</div><input id="attrs-6bb1ed41-0a4f-402b-b4ba-e4f7b975fa24" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-6bb1ed41-0a4f-402b-b4ba-e4f7b975fa24" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-a93187d3-8f53-4929-844d-4bb284095d8b" class="xr-var-data-in" type="checkbox"><label for="data-a93187d3-8f53-4929-844d-4bb284095d8b" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
       36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
       54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
       72, 73, 74, 75, 76, 77, 78, 79])</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-edd8a2df-fa63-4fce-b5e5-52ce62f863ff" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-edd8a2df-fa63-4fce-b5e5-52ce62f863ff" class="xr-section-summary">Data variables: <span>(2)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-var-name"><span>x</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">float64</div><div class="xr-var-preview xr-preview">2.562 2.902 3.241 ... 12.83 13.4</div><input id="attrs-80a4ac3e-aef6-4783-8b15-2415e31f438d" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-80a4ac3e-aef6-4783-8b15-2415e31f438d" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-11753fc2-5887-46fe-9631-b05a7fd4b944" class="xr-var-data-in" type="checkbox"><label for="data-11753fc2-5887-46fe-9631-b05a7fd4b944" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([ 2.56227265,  2.90150666,  3.24074066,  3.57997467,  3.91920868,
        4.25844268,  4.59767669,  4.93691069,  5.2761447 ,  5.6153787 ,
        5.95461271,  6.29384671,  6.63308072,  6.97231472,  7.31154873,
        7.65078274,  7.99001674,  8.32925075,  8.66848475,  9.00771876,
        4.54477444,  5.17164064,  5.79850684,  6.42537304,  7.05223924,
        7.67910544,  8.30597165,  8.93283785,  9.55970405, 10.18657025,
       10.81343645, 11.44030265, 12.06716885, 12.69403506, 13.32090126,
       13.94776746, 14.57463366, 15.20149986, 15.82836606, 16.45523227,
        3.89277416,  4.7096787 ,  5.52658324,  6.34348779,  7.16039233,
        7.97729688,  8.79420142,  9.61110596, 10.42801051, 11.24491505,
       12.06181959, 12.87872414, 13.69562868, 14.51253323, 15.32943777,
       16.14634231, 16.96324686, 17.7801514 , 18.59705594, 19.41396049,
        2.59843011,  3.16673799,  3.73504587,  4.30335376,  4.87166164,
        5.43996952,  6.00827741,  6.57658529,  7.14489317,  7.71320106,
        8.28150894,  8.84981683,  9.41812471,  9.98643259, 10.55474048,
       11.12304836, 11.69135624, 12.25966413, 12.82797201, 13.39627989])</pre></div></li><li class="xr-var-item"><div class="xr-var-name"><span>group</span></div><div class="xr-var-dims">(obs_ind)</div><div class="xr-var-dtype">int32</div><div class="xr-var-preview xr-preview">0 0 0 0 0 0 0 0 ... 3 3 3 3 3 3 3 3</div><input id="attrs-c5507519-c131-41b6-8681-33bf61ba07fb" class="xr-var-attrs-in" type="checkbox" disabled=""><label for="attrs-c5507519-c131-41b6-8681-33bf61ba07fb" title="Show/Hide attributes"><svg class="icon xr-icon-file-text2"><use href="#icon-file-text2"></use></svg></label><input id="data-91bd4d37-a490-4241-a083-8780bda50eeb" class="xr-var-data-in" type="checkbox"><label for="data-91bd4d37-a490-4241-a083-8780bda50eeb" title="Show/Hide data repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-var-attrs"><dl class="xr-attrs"></dl></div><div class="xr-var-data"><pre>array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], dtype=int32)</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-753b4206-b9fc-47af-8392-d114c1a37f23" class="xr-section-summary-in" type="checkbox"><label for="section-753b4206-b9fc-47af-8392-d114c1a37f23" class="xr-section-summary">Indexes: <span>(1)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><ul class="xr-var-list"><li class="xr-var-item"><div class="xr-index-name"><div>obs_ind</div></div><div class="xr-index-preview">PandasIndex</div><input type="checkbox" disabled=""><label></label><input id="index-481a74d4-b9ea-4c30-ab2f-e3365989f430" class="xr-index-data-in" type="checkbox"><label for="index-481a74d4-b9ea-4c30-ab2f-e3365989f430" title="Show/Hide index repr"><svg class="icon xr-icon-database"><use href="#icon-database"></use></svg></label><div class="xr-index-data"><pre>PandasIndex(Index([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
       36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
       54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
       72, 73, 74, 75, 76, 77, 78, 79],
      dtype='int64', name='obs_ind'))</pre></div></li></ul></div></li><li class="xr-section-item"><input id="section-72cce438-2d61-46af-8e0f-7435928079a7" class="xr-section-summary-in" type="checkbox" checked=""><label for="section-72cce438-2d61-46af-8e0f-7435928079a7" class="xr-section-summary">Attributes: <span>(4)</span></label><div class="xr-section-inline-details"></div><div class="xr-section-details"><dl class="xr-attrs"><dt><span>created_at :</span></dt><dd>2025-05-02T14:24:27.414827+00:00</dd><dt><span>arviz_version :</span></dt><dd>0.21.0</dd><dt><span>inference_library :</span></dt><dd>pymc</dd><dt><span>inference_library_version :</span></dt><dd>5.22.0</dd></dl></div></li></ul></div></div><br></div>
                      </ul>
                  </div>
            </li>
            
              </ul>
            </div>
            <style> /* CSS stylesheet for displaying InferenceData objects in jupyterlab.
 *
 */

:root {
  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));
  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));
  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));
  --xr-border-color: var(--jp-border-color2, #e0e0e0);
  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);
  --xr-background-color: var(--jp-layout-color0, white);
  --xr-background-color-row-even: var(--jp-layout-color1, white);
  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);
}

html[theme=dark],
body.vscode-dark {
  --xr-font-color0: rgba(255, 255, 255, 1);
  --xr-font-color2: rgba(255, 255, 255, 0.54);
  --xr-font-color3: rgba(255, 255, 255, 0.38);
  --xr-border-color: #1F1F1F;
  --xr-disabled-color: #515151;
  --xr-background-color: #111111;
  --xr-background-color-row-even: #111111;
  --xr-background-color-row-odd: #313131;
}

.xr-wrap {
  display: block;
  min-width: 300px;
  max-width: 700px;
}

.xr-text-repr-fallback {
  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */
  display: none;
}

.xr-header {
  padding-top: 6px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: solid 1px var(--xr-border-color);
}

.xr-header > div,
.xr-header > ul {
  display: inline;
  margin-top: 0;
  margin-bottom: 0;
}

.xr-obj-type,
.xr-array-name {
  margin-left: 2px;
  margin-right: 10px;
}

.xr-obj-type {
  color: var(--xr-font-color2);
}

.xr-sections {
  padding-left: 0 !important;
  display: grid;
  grid-template-columns: 150px auto auto 1fr 20px 20px;
}

.xr-sections.group-sections {
  grid-template-columns: auto;
}

.xr-section-item {
  display: contents;
}

.xr-section-item input {
  display: none;
}

.xr-section-item input + label {
  color: var(--xr-disabled-color);
}

.xr-section-item input:enabled + label {
  cursor: pointer;
  color: var(--xr-font-color2);
}

.xr-section-item input:enabled + label:hover {
  color: var(--xr-font-color0);
}

.xr-section-summary {
  grid-column: 1;
  color: var(--xr-font-color2);
  font-weight: 500;
}

.xr-section-summary > span {
  display: inline-block;
  padding-left: 0.5em;
}

.xr-section-summary-in:disabled + label {
  color: var(--xr-font-color2);
}

.xr-section-summary-in + label:before {
  display: inline-block;
  content: '►';
  font-size: 11px;
  width: 15px;
  text-align: center;
}

.xr-section-summary-in:disabled + label:before {
  color: var(--xr-disabled-color);
}

.xr-section-summary-in:checked + label:before {
  content: '▼';
}

.xr-section-summary-in:checked + label > span {
  display: none;
}

.xr-section-summary,
.xr-section-inline-details {
  padding-top: 4px;
  padding-bottom: 4px;
}

.xr-section-inline-details {
  grid-column: 2 / -1;
}

.xr-section-details {
  display: none;
  grid-column: 1 / -1;
  margin-bottom: 5px;
}

.xr-section-summary-in:checked ~ .xr-section-details {
  display: contents;
}

.xr-array-wrap {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px auto;
}

.xr-array-wrap > label {
  grid-column: 1;
  vertical-align: top;
}

.xr-preview {
  color: var(--xr-font-color3);
}

.xr-array-preview,
.xr-array-data {
  padding: 0 5px !important;
  grid-column: 2;
}

.xr-array-data,
.xr-array-in:checked ~ .xr-array-preview {
  display: none;
}

.xr-array-in:checked ~ .xr-array-data,
.xr-array-preview {
  display: inline-block;
}

.xr-dim-list {
  display: inline-block !important;
  list-style: none;
  padding: 0 !important;
  margin: 0;
}

.xr-dim-list li {
  display: inline-block;
  padding: 0;
  margin: 0;
}

.xr-dim-list:before {
  content: '(';
}

.xr-dim-list:after {
  content: ')';
}

.xr-dim-list li:not(:last-child):after {
  content: ',';
  padding-right: 5px;
}

.xr-has-index {
  font-weight: bold;
}

.xr-var-list,
.xr-var-item {
  display: contents;
}

.xr-var-item > div,
.xr-var-item label,
.xr-var-item > .xr-var-name span {
  background-color: var(--xr-background-color-row-even);
  margin-bottom: 0;
}

.xr-var-item > .xr-var-name:hover span {
  padding-right: 5px;
}

.xr-var-list > li:nth-child(odd) > div,
.xr-var-list > li:nth-child(odd) > label,
.xr-var-list > li:nth-child(odd) > .xr-var-name span {
  background-color: var(--xr-background-color-row-odd);
}

.xr-var-name {
  grid-column: 1;
}

.xr-var-dims {
  grid-column: 2;
}

.xr-var-dtype {
  grid-column: 3;
  text-align: right;
  color: var(--xr-font-color2);
}

.xr-var-preview {
  grid-column: 4;
}

.xr-var-name,
.xr-var-dims,
.xr-var-dtype,
.xr-preview,
.xr-attrs dt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 10px;
}

.xr-var-name:hover,
.xr-var-dims:hover,
.xr-var-dtype:hover,
.xr-attrs dt:hover {
  overflow: visible;
  width: auto;
  z-index: 1;
}

.xr-var-attrs,
.xr-var-data {
  display: none;
  background-color: var(--xr-background-color) !important;
  padding-bottom: 5px !important;
}

.xr-var-attrs-in:checked ~ .xr-var-attrs,
.xr-var-data-in:checked ~ .xr-var-data {
  display: block;
}

.xr-var-data > table {
  float: right;
}

.xr-var-name span,
.xr-var-data,
.xr-attrs {
  padding-left: 25px !important;
}

.xr-attrs,
.xr-var-attrs,
.xr-var-data {
  grid-column: 1 / -1;
}

dl.xr-attrs {
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 125px auto;
}

.xr-attrs dt,
.xr-attrs dd {
  padding: 0;
  margin: 0;
  float: left;
  padding-right: 10px;
  width: auto;
}

.xr-attrs dt {
  font-weight: normal;
  grid-column: 1;
}

.xr-attrs dt:hover span {
  display: inline-block;
  background: var(--xr-background-color);
  padding-right: 10px;
}

.xr-attrs dd {
  grid-column: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

.xr-icon-database,
.xr-icon-file-text2 {
  display: inline-block;
  vertical-align: middle;
  width: 1em;
  height: 1.5em !important;
  stroke-width: 0;
  stroke: currentColor;
  fill: currentColor;
}
.xr-wrap{width:700px!important;} </style>
</div>
</div>
<p>We can see it contains a number of blocks, some of which are most relevant for our purposes:</p>
<ul>
<li>The <code>posterior</code> block contains MCMC samples from the posterior distribution of the model parameters.</li>
<li>The <code>predictions</code> block contains posterior predictive samples for the <code>mu</code> and <code>y</code> variables. The <code>mu</code> variable is the mean of the normal distribution, while <code>y</code> is the observed data.</li>
<li>The <code>predictions_constant_data</code> block contains the constant data used in the model to generate the predictions. This is our grid of points where we evaluated the posterior predictive distribution.</li>
</ul>
</section>
<section id="plotting-imperatively-with-arviz" class="level2">
<h2 class="anchored" data-anchor-id="plotting-imperatively-with-arviz">Plotting imperatively with <code>arviz</code></h2>
<p>First, we’ll use the amazing (imperative) plotting capabilities of <code>arviz</code>. This is the go-to package to visualize the outputs of Bayesian models in Python - although the package does more than just the visualization side of things.</p>
<p>You can tell that this follows an imperative style because we are doing lots of manual things which don’t actually have anything to do with plotting. For example, we are iterating over the groups, creating masks, looking up subsets of data with those masks, and so on. This is all very low level - it can be fine when you have experience with it, but fundamentally there is a lot of boilerplate and munging of the data, rather than just saying what we want to plot.</p>
<div id="c3ebe4f5" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots()</span>
<span id="cb2-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> group <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> np.unique(predict_at[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>]):</span>
<span id="cb2-3">    group_mask <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> predict_at[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> group</span>
<span id="cb2-4">    x_group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> predict_at[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>][group_mask]</span>
<span id="cb2-5">    y_group <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> idata.predictions[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>].isel(obs_ind<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>group_mask)</span>
<span id="cb2-6">    plt.plot(x_group, y_group.mean(dim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chain"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draw"</span>]), label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Group </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>group<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb2-7">    az.plot_hdi(</span>
<span id="cb2-8">        x_group,</span>
<span id="cb2-9">        y_group,</span>
<span id="cb2-10">        hdi_prob<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.95</span>,</span>
<span id="cb2-11">        color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sns.color_palette()[group],</span>
<span id="cb2-12">        fill_kwargs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alpha"</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>},</span>
<span id="cb2-13">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax,</span>
<span id="cb2-14">    )</span>
<span id="cb2-15">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(title<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Data space: posterior predictives for each group"</span>, xlabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, ylabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>)</span>
<span id="cb2-16"></span>
<span id="cb2-17"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># plot the data</span></span>
<span id="cb2-18"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> g <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> np.unique(df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>]):</span>
<span id="cb2-19">    plt.scatter(</span>
<span id="cb2-20">        df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>][df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> g], df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>][df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> g], label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Group </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>g<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb2-21">    )</span>
<span id="cb2-22">plt.legend()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics_files/figure-html/cell-4-output-1.png" width="666" height="449" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Just for good measure, let’s use the same Bayesian model results and generate a plot of the posterior distributions of the slopes for each group in parameters space. The code snippet below is not very bad at all. However, it still requires a good mental model of the internal structure of the <code>InferenceData</code> object. Though the powerful <code>sel</code> method of <code>xarray</code> is nice.</p>
<div id="d7d4e1a6" class="cell" data-execution_count="4">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">fig, ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> plt.subplots()</span>
<span id="cb3-2"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> group <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> np.unique(idata.predictions_constant_data[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>]):</span>
<span id="cb3-3">    az.plot_dist(</span>
<span id="cb3-4">        idata[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"posterior"</span>][<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta"</span>].sel(groups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>group),</span>
<span id="cb3-5">        label<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">f"Group </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span>group<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>,</span>
<span id="cb3-6">        color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sns.color_palette()[group],</span>
<span id="cb3-7">        fill_kwargs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alpha"</span>: <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>},</span>
<span id="cb3-8">        ax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>ax,</span>
<span id="cb3-9">    )</span>
<span id="cb3-10">ax.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">set</span>(</span>
<span id="cb3-11">    title<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Parameter space: posterior distributions of slopes"</span>,</span>
<span id="cb3-12">    xlabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"β"</span>,</span>
<span id="cb3-13">    ylabel<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Density"</span>,</span>
<span id="cb3-14">)</span></code></pre></div></div>
<div class="cell-output cell-output-display" data-execution_count="87">
<pre><code>[Text(0.5, 1.0, 'Parameter space: posterior distributions of slopes'),
 Text(0.5, 0, 'β'),
 Text(0, 0.5, 'Density')]</code></pre>
</div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics_files/figure-html/cell-5-output-2.png" width="654" height="454" class="figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="plotting-bayesian-models-declaratively" class="level2">
<h2 class="anchored" data-anchor-id="plotting-bayesian-models-declaratively">Plotting Bayesian models declaratively</h2>
<p>The main thing we need to do is to convert the <code>arviz.InferenceData</code> object into a <code>pandas.DataFrame</code> object. More specifically, it needs to be in a tidybayes format.</p>
<section id="step-1-convert-the-arviz.inferencedata-object-to-a-tidy-dataframe" class="level3">
<h3 class="anchored" data-anchor-id="step-1-convert-the-arviz.inferencedata-object-to-a-tidy-dataframe">Step 1: Convert the <code>arviz.InferenceData</code> object to a tidy dataframe</h3>
<p>Note that this is the only really novel part of this post - the conversion of the <code>InferenceData</code> object to a tidy dataframe. The rest of the code is just using the <code>plotnine</code> package to plot the data.</p>
<div class="callout callout-style-default callout-warning callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Warning
</div>
</div>
<div class="callout-body-container callout-body">
<p>The function below is not very general - it has hard-coded parameter names for example so it won’t work for all models. It would take a bit more work to make it general, but it’s doable!</p>
</div>
</div>
<div id="110fd0a5" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">def</span> make_tidy(idata: az.InferenceData) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-&gt;</span> pd.DataFrame:</span>
<span id="cb5-2">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">"""A not very general function to convert an InferenceData object into a tidy</span></span>
<span id="cb5-3"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">    dataframe."""</span></span>
<span id="cb5-4"></span>
<span id="cb5-5">    coef_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb5-6">        idata.posterior[[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"intercept"</span>]]</span>
<span id="cb5-7">        .to_dataframe()</span>
<span id="cb5-8">        .reset_index()</span>
<span id="cb5-9">        .rename(columns<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>{<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"groups"</span>: <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>})</span>
<span id="cb5-10">    )</span>
<span id="cb5-11"></span>
<span id="cb5-12">    mu_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> idata.predictions[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>].to_dataframe(name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>).reset_index()</span>
<span id="cb5-13"></span>
<span id="cb5-14">    const_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> idata.predictions_constant_data.to_dataframe().reset_index()</span>
<span id="cb5-15"></span>
<span id="cb5-16">    mu_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> mu_df.merge(const_df, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"obs_ind"</span>, how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb5-17">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> mu_df.merge(coef_df, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"chain"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"draw"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>], how<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb5-18"></span>
<span id="cb5-19"></span>
<span id="cb5-20">tidy_df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> make_tidy(idata)</span></code></pre></div></div>
</div>
<p>So let’s use that with our <code>InferenceData</code> object and see what we get out.</p>
<div id="f780ab37" class="cell" data-execution_count="6">
<div class="cell-output cell-output-display" data-execution_count="89">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">chain</th>
<th data-quarto-table-cell-role="th">draw</th>
<th data-quarto-table-cell-role="th">obs_ind</th>
<th data-quarto-table-cell-role="th">mu</th>
<th data-quarto-table-cell-role="th">x</th>
<th data-quarto-table-cell-role="th">group</th>
<th data-quarto-table-cell-role="th">beta</th>
<th data-quarto-table-cell-role="th">intercept</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>0</td>
<td>0</td>
<td>0</td>
<td>1.944707</td>
<td>2.562273</td>
<td>0</td>
<td>0.944191</td>
<td>-0.474568</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>0</td>
<td>0</td>
<td>1</td>
<td>2.265008</td>
<td>2.901507</td>
<td>0</td>
<td>0.944191</td>
<td>-0.474568</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2.585310</td>
<td>3.240741</td>
<td>0</td>
<td>0.944191</td>
<td>-0.474568</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>0</td>
<td>0</td>
<td>3</td>
<td>2.905611</td>
<td>3.579975</td>
<td>0</td>
<td>0.944191</td>
<td>-0.474568</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>0</td>
<td>0</td>
<td>4</td>
<td>3.225913</td>
<td>3.919209</td>
<td>0</td>
<td>0.944191</td>
<td>-0.474568</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">...</th>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">319995</th>
<td>3</td>
<td>999</td>
<td>75</td>
<td>12.920041</td>
<td>11.123048</td>
<td>3</td>
<td>0.909456</td>
<td>2.804114</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">319996</th>
<td>3</td>
<td>999</td>
<td>76</td>
<td>13.436892</td>
<td>11.691356</td>
<td>3</td>
<td>0.909456</td>
<td>2.804114</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">319997</th>
<td>3</td>
<td>999</td>
<td>77</td>
<td>13.953744</td>
<td>12.259664</td>
<td>3</td>
<td>0.909456</td>
<td>2.804114</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">319998</th>
<td>3</td>
<td>999</td>
<td>78</td>
<td>14.470595</td>
<td>12.827972</td>
<td>3</td>
<td>0.909456</td>
<td>2.804114</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">319999</th>
<td>3</td>
<td>999</td>
<td>79</td>
<td>14.987446</td>
<td>13.396280</td>
<td>3</td>
<td>0.909456</td>
<td>2.804114</td>
</tr>
</tbody>
</table>

<p>320000 rows × 8 columns</p>
</div>
</div>
</div>
<p>Well, that’s quite a lot of rows! But the key thing here is that we’ve got both data and parameters into a single tidy dataframe.</p>
</section>
<section id="step-2-plot" class="level3">
<h3 class="anchored" data-anchor-id="step-2-plot">Step 2: Plot!</h3>
<p>Now we have everything we need to plot the outputs declaratively with <code>plotnine</code>:</p>
<div id="afd5a13e" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1">p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (</span>
<span id="cb6-2">    ggplot(</span>
<span id="cb6-3">        tidy_df,</span>
<span id="cb6-4">        aes(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"mu"</span>, group<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"factor(group)"</span>, fill<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"factor(group)"</span>),</span>
<span id="cb6-5">    )</span>
<span id="cb6-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> stat_summary(</span>
<span id="cb6-7">        geom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"ribbon"</span>,</span>
<span id="cb6-8">        fun_ymin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">lambda</span> y: np.quantile(y, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.03</span>),</span>
<span id="cb6-9">        fun_ymax<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">lambda</span> y: np.quantile(y, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.97</span>),</span>
<span id="cb6-10">        alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.20</span>,</span>
<span id="cb6-11">        size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,</span>
<span id="cb6-12">    )</span>
<span id="cb6-13">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> stat_summary(geom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"line"</span>, fun_y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>np.median, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb6-14">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> theme_classic()</span>
<span id="cb6-15">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> labs(</span>
<span id="cb6-16">        x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>,</span>
<span id="cb6-17">        y<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>,</span>
<span id="cb6-18">        fill<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>,</span>
<span id="cb6-19">        color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"group"</span>,</span>
<span id="cb6-20">        title<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r"Predicted mu with 94% percentile intervals"</span>,</span>
<span id="cb6-21">    )</span>
<span id="cb6-22">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> geom_point(df, aes(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"factor(group)"</span>), size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.6</span>, alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)</span>
<span id="cb6-23">)</span>
<span id="cb6-24">p</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics_files/figure-html/cell-8-output-1.png" width="672" height="480" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>So that is certainly not a 1-liner, but it is declarative! Every piece of that code relates to <em>what</em> we want to plot.</p>
<p>One advantage you get from this is that it’s much easier to customize the plot because you are in grammar of graphics territory. For example, we can just add a <code>facet_wrap</code> to completely change the pixels being plotted.</p>
<div id="6abaaa61" class="cell" data-execution_count="8">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> facet_wrap(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'group'</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics_files/figure-html/cell-9-output-1.png" width="672" height="480" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>And now let’s see how we can plot the posterior distributions of the slopes for each group in parameters space.</p>
<div id="71463f95" class="cell" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1">(</span>
<span id="cb8-2">    ggplot(tidy_df, aes(x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"beta"</span>, color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"factor(group)"</span>))</span>
<span id="cb8-3">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> geom_density(alpha<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb8-4">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> theme_classic()</span>
<span id="cb8-5">)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics_files/figure-html/cell-10-output-1.png" width="672" height="480" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<p>Admittedly, these defaults for <code>plotnine</code> are not great. It is totally possible to customize them, but I’m not doing that here.</p>
</section>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>This approach will not necessarily lead to plotting complex graphics in a single line of code, but it does allow you to build up plots in a modular way. This is the main advantage of the grammar of graphics approach - you can build up complex graphics from simple components. And the code you are writing is all about <em>what</em> you want to plot, rather than <em>how</em> to wrangle the data. This is a big difference in terms of mental model and can make it easier to understand what is going on.</p>
<p>Some people may love this, some may be indifferent, some may hate it. Either way, the main point I am making in this blog post is: <strong>if you want to to do Bayesian model data viz in a different way, you can do that in Python</strong>.</p>
<p>Readers should note that you’ve been able to do this in R for a while now with the <a href="https://ggplot2.tidyverse.org"><code>ggplot2</code></a> and <a href="https://mjskay.github.io/tidybayes/"><code>tidybayes</code></a> packages. It would be interesting to see if this approach is appealing to people. We could even build more geoms and stats or use other grammar of graphics based pagages.</p>


</section>

 ]]></description>
  <category>python</category>
  <category>bayes</category>
  <category>data-viz</category>
  <guid>https://drbenvincent.github.io/posts/mcmc_grammar_of_graphics.html</guid>
  <pubDate>Wed, 23 Apr 2025 23:00:00 GMT</pubDate>
</item>
<item>
  <title>Causal Inference: have you been doing science wrong all this time?</title>
  <dc:creator>Benjamin Vincent</dc:creator>
  <link>https://drbenvincent.github.io/posts/causal_fear.html</link>
  <description><![CDATA[ 





<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
<p>If you are a researcher in academia or industry, depending where you are in your causal journey, this post may blow your mind! Its primary purpose is to convey that if you have not started thinking about causality yet, then you should perhaps start to feel deep existential dread.</p>
<p>Let’s say you are doing a social science study and you are interested in how a bunch of predictor variables (e.g.&nbsp;impulsivity, age, sex, etc.) influence some outcome variable such as body mass index. An exceedingly common practice is to throw all of these variables into a multiple linear regression.</p>
<p>When you do this you will get regression coefficients that inform you of the <em>statistical</em> associations between your predictors and outcome variables. The problem is that these are only sometimes useful in telling us what we really care about, namely the <em>causal</em> relationships between the variables.</p>
<p>Now, it’s entirely possible that you’ve gotten lucky and by running a multiple regression with a bunch of control variables you end up with a statistical estimate that is not too far away from a true causal effect.</p>
<p>Then again, it is entirely possible that you are not lucky, and by including one or more predictor variables in your regression you have actually introduced massive bias into your estimate of the causal effect. Maybe you think there is a causal effect <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y"> but actually there is no causal effect at all. Or maybe there is a causal effect but it is in the opposite direction to what you think. Or maybe there is a causal effect but it is much larger or smaller than you think.</p>
<p>At this point you might be thinking either “I don’t believe you” or “I need to be convinced before I start to panic.” Well, that is what this post is about. By using a simulated dataset with a known causal structure, we will see how different approaches to estimating causal effects can lead to very different results.</p>
<p>We will see two approaches that can be used to estimate causal effects: (1) linear regression (with good controls included and none of the bad controls), and (2) structural causal models. The first approach is perhaps easier to implement because regressions are familiar, but the second approach is more powerful and automatic. But there is no magic pill however, both approaches require you to think carefully about the causal structure of your data, and there are no guarantees that you’ve imagined the correct causal structure. But by at least thinking about it we can do our best to avoid making egregious errors out of ignorance.</p>
</section>
<section id="generate-a-dataset" class="level2">
<h2 class="anchored" data-anchor-id="generate-a-dataset">Generate a dataset</h2>
<p>First we will generate some data from this causal <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">DAG</a>. Just to keep things simple, all the nodes are normally distributed and the relationships between the nodes are linear.</p>
<div class="cell" data-layout-align="default">
<div class="cell-output-display">
<div id="fig-causal-dag" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-causal-dag-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="480" viewbox="0.00 0.00 117.00 260.00" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
<title>G</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-256 113,-256 113,4 -4,4"></polygon>
<!-- Q -->
<g id="node1" class="node">
<title>Q</title>
<ellipse fill="none" stroke="black" cx="54" cy="-234" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="54" y="-229.8" font-family="Times,serif" font-size="14.00">Q</text>
</g>
<!-- X -->
<g id="node2" class="node">
<title>X</title>
<ellipse fill="none" stroke="black" cx="82" cy="-162" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="82" y="-157.8" font-family="Times,serif" font-size="14.00">X</text>
</g>
<!-- Q&#45;&gt;X -->
<g id="edge1" class="edge">
<title>Q-&gt;X</title>
<path fill="none" stroke="black" d="M60.64,-216.41C63.91,-208.22 67.94,-198.14 71.62,-188.95"></path>
<polygon fill="black" stroke="black" points="74.95,-190.05 75.41,-179.47 68.45,-187.45 74.95,-190.05"></polygon>
</g>
<!-- Y -->
<g id="node3" class="node">
<title>Y</title>
<ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="27" y="-85.8" font-family="Times,serif" font-size="14.00">Y</text>
</g>
<!-- Q&#45;&gt;Y -->
<g id="edge2" class="edge">
<title>Q-&gt;Y</title>
<path fill="none" stroke="black" d="M50.74,-215.87C46.14,-191.67 37.69,-147.21 32.21,-118.39"></path>
<polygon fill="black" stroke="black" points="35.57,-117.36 30.27,-108.19 28.7,-118.67 35.57,-117.36"></polygon>
</g>
<!-- X&#45;&gt;Y -->
<g id="edge3" class="edge">
<title>X-&gt;Y</title>
<path fill="none" stroke="black" d="M70.07,-145.81C62.79,-136.55 53.34,-124.52 45.15,-114.09"></path>
<polygon fill="black" stroke="black" points="47.84,-111.86 38.91,-106.16 42.34,-116.18 47.84,-111.86"></polygon>
</g>
<!-- P -->
<g id="node4" class="node">
<title>P</title>
<ellipse fill="none" stroke="black" cx="54" cy="-18" rx="27" ry="18"></ellipse>
<text text-anchor="middle" x="54" y="-13.8" font-family="Times,serif" font-size="14.00">P</text>
</g>
<!-- X&#45;&gt;P -->
<g id="edge4" class="edge">
<title>X-&gt;P</title>
<path fill="none" stroke="black" d="M78.62,-143.87C73.83,-119.56 65.01,-74.82 59.33,-46.01"></path>
<polygon fill="black" stroke="black" points="62.76,-45.32 57.39,-36.19 55.89,-46.68 62.76,-45.32"></polygon>
</g>
<!-- Y&#45;&gt;P -->
<g id="edge5" class="edge">
<title>Y-&gt;P</title>
<path fill="none" stroke="black" d="M33.4,-72.41C36.51,-64.34 40.33,-54.43 43.83,-45.35"></path>
<polygon fill="black" stroke="black" points="47.13,-46.55 47.46,-35.96 40.6,-44.03 47.13,-46.55"></polygon>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-causal-dag-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: A causal DAG with four variables. We are primarily interested in the relationship between <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y">. But there is a confounding variable <img src="https://latex.codecogs.com/png.latex?Q"> which influences both <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y">. There is also a collider <img src="https://latex.codecogs.com/png.latex?P"> which is influenced by <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y">. This DAG is loosely based on Molak <span class="citation" data-cites="molak2023">(2023, p 139)</span>.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Let’s generate a simulated dataset of 5,000 observations and look at the first 5. This is perhaps quite a lot of observations, but doing this means that we can be less worried about the estimation error and focus more on how good or bad our estimates are in the best case scenario of abundant data.</p>
<div id="059e79ff" class="cell" data-execution_count="2">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1">N <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5_000</span></span>
<span id="cb1-2">Q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>N)</span>
<span id="cb1-3">X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.14</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Q, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>N)</span>
<span id="cb1-4">Y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.11</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Q, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.24</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>N)</span>
<span id="cb1-5">P <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> rng.normal(loc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.43</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.21</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Y, scale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.22</span>, size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>N)</span>
<span id="cb1-6">df <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pd.DataFrame({<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q"</span>: Q, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>: X, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y"</span>: Y, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P"</span>: P})</span>
<span id="cb1-7"></span>
<span id="cb1-8">df.head()</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display" data-execution_count="3">
<div>


<table class="dataframe caption-top table table-sm table-striped small" data-border="1">
<thead>
<tr class="header">
<th data-quarto-table-cell-role="th"></th>
<th data-quarto-table-cell-role="th">Q</th>
<th data-quarto-table-cell-role="th">X</th>
<th data-quarto-table-cell-role="th">Y</th>
<th data-quarto-table-cell-role="th">P</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<th data-quarto-table-cell-role="th">0</th>
<td>0.304717</td>
<td>-0.060520</td>
<td>0.033461</td>
<td>0.185277</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">1</th>
<td>-1.039984</td>
<td>-0.265392</td>
<td>-0.084383</td>
<td>0.079660</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">2</th>
<td>0.750451</td>
<td>-0.173601</td>
<td>-0.392316</td>
<td>0.007946</td>
</tr>
<tr class="even">
<th data-quarto-table-cell-role="th">3</th>
<td>0.940565</td>
<td>0.303072</td>
<td>0.247141</td>
<td>0.279045</td>
</tr>
<tr class="odd">
<th data-quarto-table-cell-role="th">4</th>
<td>-1.951035</td>
<td>-0.179286</td>
<td>-0.141118</td>
<td>-0.015906</td>
</tr>
</tbody>
</table>

</div>
</div>
</div>
<div class="callout callout-style-simple callout-note">
<div class="callout-body d-flex">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-body-container">
<p>Importantly for later, we specified a true causal effect between <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y"> of 0.7. We will see how well we can recover this value with different approaches below.</p>
</div>
</div>
</div>
</section>
<section id="linear-regression-approach" class="level2">
<h2 class="anchored" data-anchor-id="linear-regression-approach">Linear regression approach</h2>
<section id="approach-1-estimate-x-rightarrow-y-only." class="level3">
<h3 class="anchored" data-anchor-id="approach-1-estimate-x-rightarrow-y-only.">Approach 1: estimate <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y"> only.</h3>
<p>What we care about is the relationship between <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y">. This might be a bit simplistic, but it is not uncommon to see people just estimate this relationship directly. We can build a model to do this in <a href="https://github.com/bambinos/bambi"><code>bambi</code></a> <span class="citation" data-cites="Capretto2022">(Capretto et al. 2022)</span> using trusty formula notation, <code>Y ~ X</code> <span class="citation" data-cites="wilkinson_notation">(Wilkinson and Rogers 1973)</span>.</p>
<div id="cedcea25" class="cell" data-execution_count="3">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bmb.Model(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Y ~ X'</span>, df)</span>
<span id="cb2-2">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit(random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>RANDOM_SEED)</span></code></pre></div></div>
</div>
<p>We can use the <a href="https://github.com/arviz-devs/arviz"><code>arviz</code></a> package <span class="citation" data-cites="arviz_2019">(Kumar et al. 2019)</span> to plot the posterior distribution of the causal effect of <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y">. For the non-Bayesians, you can think of this as the distribution of relative credibility of different causal effect strengths given the data and the model.</p>
<div id="cell-fig-result-xy" class="cell" data-execution_count="4">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1">ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> az.plot_posterior(results.posterior[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>], ref_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb3-2">ax.set_title(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r"Posterior distribution of causal effect of </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">X </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ightarrow Y</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="fig-result-xy" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-result-xy-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/causal_fear_files/figure-html/fig-result-xy-output-1.png" width="614" height="288" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-result-xy-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: The posterior distribution of the causal effect parameter is shown by the distribution. The thick horizontal line shows the 94% Bayesian credible interval (specifically the highest density interval, HDI). The vertical line shows the true value of the causal effect for comparison.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Okay, so this didn’t work out too well<sup>1</sup>. We can see that our estimated causal influence of <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y"> is way off the true value. Most people with some statistical training won’t be too surprised by this. After all, we did not take into account any of the other variables in our dataset.</p>
</section>
<section id="approach-2---include-all-the-variables-in-the-multiple-regression" class="level3">
<h3 class="anchored" data-anchor-id="approach-2---include-all-the-variables-in-the-multiple-regression">Approach 2 - include all the variables in the multiple regression</h3>
<p>So let’s try to fix that. This time we will include all the variables in the regression. This is a <em>very</em> common approach and one that I used many times in my academic research career. The approach has been termed “the causal salad” <span class="citation" data-cites="mcelreath2020rethinking Bulbulia2021">(see McElreath 2020; also Bulbulia et al. 2021)</span>. The intuition is that if we include all the variables into the regression and then we can see the effect of <img src="https://latex.codecogs.com/png.latex?X"> on <img src="https://latex.codecogs.com/png.latex?Y"> after controlling for all the other variables. Kind of makes sense right? But let’s see how well that works out for us.</p>
<div id="7a9c3859" class="cell" data-execution_count="5">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bmb.Model(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Y ~ Q + X + P'</span>, df)</span>
<span id="cb4-2">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit(random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>RANDOM_SEED)</span></code></pre></div></div>
</div>
<div id="cell-fig-result-causal-salad" class="cell" data-execution_count="6">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1">ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> az.plot_posterior(results.posterior[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>], ref_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb5-2">ax.set_title(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r"Posterior distribution of causal effect of </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">X </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ightarrow Y</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="fig-result-causal-salad" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-result-causal-salad-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/causal_fear_files/figure-html/fig-result-causal-salad-output-1.png" width="617" height="288" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-result-causal-salad-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Our estimated causal effect is now an underestimate and even further off than before.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Arrrrrrggggghhhh! This is even worse than before. What is going on here? Well, the problem is that we have included both <em>good</em> and <em>bad</em> controls in our regression.</p>
<p>Good and bad controls? What are you talking about? Many people will not have heard of this before. I certainly hadn’t until I started reading about causal inference.</p>
</section>
<section id="approach-3---include-only-the-good-controls" class="level3">
<h3 class="anchored" data-anchor-id="approach-3---include-only-the-good-controls">Approach 3 - include only the good controls</h3>
<p>So I’m not going to really explain <em>how</em> you find out what the good controls are. That is a whole other topic. For now, all you need to know is that we have a <em>backdoor path</em> between <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?Y"> via <img src="https://latex.codecogs.com/png.latex?Q">. What this means is that there is a <em>statistical</em> route in which <img src="https://latex.codecogs.com/png.latex?X"> can influence <img src="https://latex.codecogs.com/png.latex?Y"> via <img src="https://latex.codecogs.com/png.latex?Q">. When we have a backdoor path, we need to block it. We can do this by including <img src="https://latex.codecogs.com/png.latex?Q"> in our regression. This is a <em>good</em> control.</p>
<div id="bbed6ce2" class="cell" data-execution_count="7">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1">model <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> bmb.Model(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Y ~ X + Q'</span>, df)</span>
<span id="cb6-2">results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> model.fit(random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>RANDOM_SEED)</span></code></pre></div></div>
</div>
<div id="cell-fig-result-adjustment-set" class="cell" data-execution_count="8">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1">ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> az.plot_posterior(results.posterior[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>], ref_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb7-2">ax.set_title(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r"Posterior distribution of causal effect of </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">X </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ightarrow Y</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="fig-result-adjustment-set" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-result-adjustment-set-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/causal_fear_files/figure-html/fig-result-adjustment-set-output-1.png" width="614" height="288" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-result-adjustment-set-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: Bingo! Our posterior estimate of the causal effect is now very close to the true value.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Sweet! We have recovered the true causal effect of <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y">. We did this through the ‘magic’ of only including the <em>good</em> controls in our regression.</p>
</section>
</section>
<section id="bayesian-structural-causal-modeling-approach" class="level2">
<h2 class="anchored" data-anchor-id="bayesian-structural-causal-modeling-approach">Bayesian Structural Causal Modeling approach</h2>
<p>But what if we don’t want to do all that? What if we just want to specify the DAG and let the Bayes do the rest?</p>
<p>Well, let’s do that. First we will specify the DAG using the <a href="https://www.pymc.io/"><code>PyMC</code></a> <span class="citation" data-cites="thomas_wiecki_2023_8146216">(<span class="nocase">Wiecki et al.</span> 2023)</span> package and plot its graphical representation.</p>
<div id="cell-fig-SCM" class="cell" data-execution_count="9">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">with</span> pm.Model() <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> model:</span>
<span id="cb8-2">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># data</span></span>
<span id="cb8-3">    _Q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.MutableData(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_Q"</span>, df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q"</span>])</span>
<span id="cb8-4">    _X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.MutableData(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_X"</span>, df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>])</span>
<span id="cb8-5">    _Y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.MutableData(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_Y"</span>, df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y"</span>])</span>
<span id="cb8-6">    _P <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.MutableData(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"_P"</span>, df[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P"</span>])</span>
<span id="cb8-7"></span>
<span id="cb8-8">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># priors on slopes</span></span>
<span id="cb8-9">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># x ~ q</span></span>
<span id="cb8-10">    qx <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qx"</span>)</span>
<span id="cb8-11">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># y ~ x + q</span></span>
<span id="cb8-12">    xy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xy"</span>)</span>
<span id="cb8-13">    qy <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"qy"</span>)</span>
<span id="cb8-14">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># p ~ x + y</span></span>
<span id="cb8-15">    xp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xp"</span>)</span>
<span id="cb8-16">    yp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"yp"</span>)</span>
<span id="cb8-17"></span>
<span id="cb8-18">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># priors on sd's</span></span>
<span id="cb8-19">    sigma_x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.HalfNormal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_x"</span>)</span>
<span id="cb8-20">    sigma_y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.HalfNormal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_y"</span>)</span>
<span id="cb8-21">    sigma_p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.HalfNormal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sigma_p"</span>)</span>
<span id="cb8-22">    </span>
<span id="cb8-23">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># model</span></span>
<span id="cb8-24">    Q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Q"</span>, observed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_Q)</span>
<span id="cb8-25">    X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"X"</span>, mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>qx<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Q, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sigma_x, observed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_X)</span>
<span id="cb8-26">    Y <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Y"</span>, mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>xy<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> qy<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Q, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sigma_y, observed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_Y)</span>
<span id="cb8-27">    P <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.Normal(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"P"</span>, mu<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>xp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>X <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> yp<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>Y, sigma<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>sigma_p, observed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>_P)</span>
<span id="cb8-28"></span>
<span id="cb8-29">pm.model_to_graphviz(model)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-stderr">
<pre><code>/Users/benjamv/mambaforge/envs/pymc_env/lib/python3.12/site-packages/pymc/data.py:321: FutureWarning: MutableData is deprecated. All Data variables are now mutable. Use Data instead.
  warnings.warn(</code></pre>
</div>
<div class="cell-output cell-output-display" data-execution_count="10">
<div id="fig-scm" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-scm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/causal_fear_files/figure-html/fig-scm-output-2.svg" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-scm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Holy moley! That is a lot of code and a complex DAG! But it is not as bad as it looks. We are just specifying the simple DAG we saw in Figure&nbsp;1. Because we are taking a Bayesian approach, we are also specifying the priors on the slopes and the sd’s.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Now we’ve recovered from that ordeal, let’s sample from the posterior distribution…</p>
<div id="6678b6f7" class="cell" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">with</span> model:</span>
<span id="cb10-2">    idata <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pm.sample(random_seed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>RANDOM_SEED)</span></code></pre></div></div>
</div>
<p>… and plot the output</p>
<div id="cell-fig-result-scm" class="cell" data-execution_count="11">
<details class="code-fold">
<summary>Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1">ax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> az.plot_posterior(idata, var_names<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"xy"</span>, ref_val<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.7</span>)</span>
<span id="cb11-2">ax.set_title(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">r"Posterior distribution of causal effect of </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">X </span><span class="ch" style="color: #20794D;
background-color: null;
font-style: inherit;">\r</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">ightarrow Y</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">$</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="fig-result-scm" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-result-scm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://drbenvincent.github.io/posts/causal_fear_files/figure-html/fig-result-scm-output-1.png" width="626" height="288" class="figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-result-scm-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;6: Another sucessful recovery of the true causal effect.
</figcaption>
</figure>
</div>
</div>
</div>
<p>Neat! We have recovered the true causal effect of <img src="https://latex.codecogs.com/png.latex?X%20%5Crightarrow%20Y">, but this time we didn’t have to think about the good and bad controls. We just specified the DAG and let Bayes do the rest.</p>
</section>
<section id="summary" class="level2">
<h2 class="anchored" data-anchor-id="summary">Summary</h2>
<p>What have we learned here? We have possibly learnt that we’ve been doing science wrong all this time. You really cannot just throw all your variables into a regression and hope for the best. You need to think about the causal relationships between your variables and then include the good controls. If you include bad controls, then you will get the wrong answer and fool yourself and publish stuff that is wrong.</p>
<p>However, there is a message of hope. If you learn about causal inference, you can do better science. You can get the right answer and publish stuff that is less wrong. So the main question here is how to distinguish the good from the bad controls. That will be the topic of another post.</p>
<p>However, if you are lazy and don’t want to do that, there is another way! You can use Bayesian Structural Causal Modeling. You can specify the DAG (which takes a little more typing) and let the computer do the rest. This is a very powerful approach and one that I am very excited about. I hope you are too.</p>
<p>That said, the overall take-home message of this blogpost is that if you have not started on the causal journey then you should be scared shitless.</p>
<p>If you are interested in this approach of learning about causal inference through simulation, then check out the paper “Why we should teach causal inference: Examples in linear regression with simulated data” <span class="citation" data-cites="lubke2020we">(Lübke et al. 2020)</span>. And you can follow me on <a href="https://www.linkedin.com/in/dr-benjamin-vincent-503571127/">LinkedIn</a> to get notified of future posts.</p>
</section>
<section id="references" class="level2">
<h2 class="anchored" data-anchor-id="references">References</h2>
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-Bulbulia2021" class="csl-entry">
Bulbulia, Joseph, Uffe Schjoedt, John H. Shaver, Richard Sosis, and Wesley J. Wildman. 2021. <span>“Causal Inference in Regression: Advice to Authors.”</span> <em>Religion, Brain &amp; Behavior</em> 11 (4): 353–60. <a href="https://doi.org/10.1080/2153599X.2021.2001259">https://doi.org/10.1080/2153599X.2021.2001259</a>.
</div>
<div id="ref-Capretto2022" class="csl-entry">
Capretto, Tomás, Camen Piho, Ravin Kumar, Jacob Westfall, Tal Yarkoni, and Osvaldo A Martin. 2022. <span>“Bambi: A Simple Interface for Fitting Bayesian Linear Models in Python.”</span> <em>Journal of Statistical Software</em> 103 (15): 1–29. <a href="https://doi.org/10.18637/jss.v103.i15">https://doi.org/10.18637/jss.v103.i15</a>.
</div>
<div id="ref-arviz_2019" class="csl-entry">
Kumar, Ravin, Colin Carroll, Ari Hartikainen, and Osvaldo Martin. 2019. <span>“ArviZ a Unified Library for Exploratory Analysis of Bayesian Models in Python.”</span> <em>Journal of Open Source Software</em> 4 (33): 1143. <a href="https://doi.org/10.21105/joss.01143">https://doi.org/10.21105/joss.01143</a>.
</div>
<div id="ref-lubke2020we" class="csl-entry">
Lübke, Karsten, Matthias Gehrke, Jörg Horst, and Gero Szepannek. 2020. <span>“Why We Should Teach Causal Inference: Examples in Linear Regression with Simulated Data.”</span> <em>Journal of Statistics Education</em> 28 (2): 133–39.
</div>
<div id="ref-mcelreath2020rethinking" class="csl-entry">
McElreath, Richard. 2020. <em>Statistical Rethinking: A Bayesian Course with Examples in r and Stan</em>. CRC press.
</div>
<div id="ref-molak2023" class="csl-entry">
Molak, Aleksander. 2023. <em>Causal Inference and Discovery in Python</em>. Packt Publishing.
</div>
<div id="ref-thomas_wiecki_2023_8146216" class="csl-entry">
<span class="nocase">Wiecki, Thomas, John Salvatier, Ricardo Vieira, et al.</span> 2023. <em>Pymc-Devs/Pymc: V5.6.1</em>. V. v5.6.1. Zenodo, released July. <a href="https://doi.org/10.5281/zenodo.8146216">https://doi.org/10.5281/zenodo.8146216</a>.
</div>
<div id="ref-wilkinson_notation" class="csl-entry">
Wilkinson, GN, and CE Rogers. 1973. <span>“Symbolic Description of Factorial Models for Analysis of Variance.”</span> <em>Journal of the Royal Statistical Society Series C: Applied Statistics</em> 22 (3): 392–99.
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>If you are a Bayesian then you will be used to interpreting these kinds of posterior distribution plots. For our present purposes we can just ask whether the credible interval of our posterior distribution is anywhere close to the true value.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>python</category>
  <category>bayes</category>
  <category>causality</category>
  <guid>https://drbenvincent.github.io/posts/causal_fear.html</guid>
  <pubDate>Sat, 29 Jul 2023 23:00:00 GMT</pubDate>
  <media:content url="https://drbenvincent.github.io/img/cover_causal_fear.png" medium="image" type="image/png" height="77" width="144"/>
</item>
</channel>
</rss>
