r/datascience • u/WhatsTheImpactdotcom • Oct 06 '26
Analysis Model Selection Technique for Causal Inference
How do you choose between causal inference models when you can never see the true effect? Model selection is well documented in machine learning, but it often gets skipped in causal inference work. Doing it well is one of the things that separates senior and staff-level data scientists from more junior ones.
I simulated two years of weekly bookings for 40 regions, five of which received a treatment on the date marked by the red vertical line. Because I generated the data, I know the ground truth: the treatment increased bookings in those five regions by exactly 10%. With five treated regions and 35 untreated ones, two natural options are synthetic control and difference-in-differences, though there are others.
Code in colab and explanatory video, free and ungated: https://whatstheimpact.com/learn-causal-inference/
When I gave Claude Code free rein on this data, it built its whole analysis around difference-in-differences where it found a 24% increase, more than double the true effect. To its credit, it flagged that the pre-treatment trends weren't parallel, but it never tested whether a different model would be more accurate.
Importantly, Claude skipped an A/A test, sometimes called a placebo test. You take only the data from before the real treatment, pretend the treatment started three months earlier, and randomly picked five regions (for consistency) to call "treated." Because nothing actually happened in that window, the true effect is zero. That means any effect the model reports there is pure estimation error, and I repeated this for 500 draws for each model to see the full spread.
For difference-in-differences, 90% of the placebo estimates landed between -14% and +10%. The RMSE, which measures how far the estimates typically land from the true answer of zero, was 7.6 percentage points. Synthetic control on the exact same placebo draws was much tighter, with 90% of estimates landing between -7% and +9%. Its RMSE dropped to 4.9 points, more than a third lower than difference-in-differences.
The outcome you model is a choice too, so I also ran synthetic control on bookings per 1,000 people instead of raw bookings. Putting every region on the same scale helps the model track the treated regions more closely before treatment, and the RMSE fell a bit further to 4.4 points.
Sure enough, the real treatment period lines up with that ranking: synthetic control estimates 7% on raw bookings and 9.6% per 1,000 people, both much closer to the true 10% than the 24% from difference-in-differences. With one simulated dataset, I wouldn't read much into the small gap between the two synthetic control versions or claim that synthetic control always wins. What carries over is the workflow: in real work you never see the ground truth, but you can usually run this A/A test on whatever models you're considering before trusting one.
18
u/ClasslessHero Oct 06 '26
I'd say the textbooks do an excellent job telling us which model to select, but it almost never follows the textbook examples in industry.
For example: if I build a recommender system and my final output is some LTR. XGBoost, LightGBM, or some other approach - it doesn't matter. I need to decide between Model A and Model B. In a sentence, the textbook will instruct me to pick the model that has the highest NDCG@K, given that I haven't massively overfit or underfit. I can walk through that procedure and pick the best model based on that number, right? Not at all. I need to pay attention to the errors. The lower NDCG model might have "better" or maybe "more realistic" errors. If I'm serving these recommendations to users, then I need realistic errors. A model that is excellent at being correct but has terrible errors can lead to a jarring user experience. This could also be the case with a model for outbound marketing, work prioritization, etc. Ultimately, the model I chose to deploy has to feel like it produces reasonable content, or at least not completely miss the business objective when it's wrong.
What does all this mean? As much as we call it data science, sometimes it is data art and data vibes. Our problems are squishier than they are solid, and we need to apply nuance.
8
u/Warlord_Zap Oct 06 '26
To me this highlights the importance of good validation more than anything else, which really is key to these methods.
5
u/LibiSC Oct 07 '26
Follow you in TikTok, one of the most random places to find someone that somewhat gives real practical examples. Keep the good work.
4
u/wscottsanders Oct 06 '26
To me itās not an apples to apples comparison. Iād consider that a difference in differences model could potentially be severely underpowered at just 40 cases of which only 5 are treated. That means random variation can cause wild swings. Your synthetic control model is designed to do just that - soak up variance accounting for latent factors shared between the cases.
4
u/Sinainios Oct 07 '26
Nice writeup. Backtesting estimators on placebo windows is underused, and "choose the model by how it behaves where you know the answer is zero" is the right instinct.
A few things I'd add:
Agreed that the transferable lesson is the workflow, not "SC beats DiD."
2
u/Present-Square-5823 Oct 08 '26
In my opinion, you'd get better results by setting up the right harness or by building an agent work flow that follows clear protocols. regime had changed for data analysis. It's all about building good agents now.
1
u/OddsRelay Oct 07 '26
Worth adding synthetic DiD too. It weights both the control regions and the pre-period weeks, so it copes with the non-parallel trends that hurt plain DiD here. With only five treated regions, your 500 placebo draws can also serve as its variance estimate. That's the placebo method from the original SDID paper.
2
u/offthecuff87 Oct 06 '26
You need a context, technical constraints, resources contraints to select model properly. Although I believe modeling is a very tiny part in the business streamline
2
u/Available-Craft-8143 Oct 07 '26
The Claude Code part is the most instructive bit ā it did not fail at estimation, it failed at protocol: no pre-specified candidate set, no selection step before estimating. An agent asked to 'analyze the effect' will happily return one confident number. The fix is not a smarter model, it is forcing the selection procedure (candidates plus placebos) into the workflow before any estimate is allowed.
1
u/Reliable_Panda_35 Oct 23 '26
The A/A test is the part I'd take from this for any model comparison. Ranking models by how tightly their placebo estimates cluster around zero is easier to check than picking whichever model gives the most believable effect. I'd also run the placebo over several fake start dates, since one window can favor one model by chance. The non-parallel pre-trends Claude flagged are a strong reason to rethink the design before building the rest of the analysis on difference-in-differences.
1
u/frank-andreas8 10h ago
Raw bookings and bookings per 1,000 people can be different estimands, especially if treatment could affect population. Define the target first, then compare placebo performance among estimators for that target.
1
u/loon011 Oct 09 '26
Hi Jonathan, I shot you a DM for advice on a potential small-scale personal project involving causal inference. Any advice would be greatly appreciated!
1
u/data501 Oct 12 '26
When it comes to causal inference, model selection is definitely crucial, especially with complex datasets. Your workflow makes a compelling case for running A/A tests; they offer powerful insights into estimation error before committing to a model. The comparison between synthetic control and difference-in-differences is particularly interesting. It's enlightening to see how the RMSEs differed, as that really impacts reliability in real-world applications. Your findings serve as a solid reminder that every detail counts in these analyses.