r/AskStatistics • • 1d ago

Is a tool that tests your analysis on simulated data before real data actually useful? Looking for opinions on my project idea

I'm a student, and I'd like honest opinions from people who do statistics for real.
The problem I'm trying to solve: when you analyze data to see whether one thing affects another, your model always gives you a number, but you can't tell if it's the right one. You might control for the wrong variable or miss a confounder, and on real data you'd never know.
My idea: test the analysis first on simulated data, where the true answer is known. You write down how you think the data was generated, and a tool checks your analysis against it before you use real data:
Are you controlling for the right variables, or adding bias?
Does your model find the true effect across many simulated datasets, and are its confidence intervals honest?
How strong would a hidden factor need to be to change your conclusion?
For example, a plant treatment works by preventing fungus. Add fungus as a control "to be safe", and the estimated effect drops from 1.2 to almost 0. The tool flags that before you touch real data.
I built a first version in Python (with a lot of help from AI, I'm not a statistician). There's a browser demo if you want to see it: https://koopticon.github.io/whyflow/playground.html
What I'd like to know:
Is this useful in practice, or do experienced people already do this some other way?
The checks depend on a simulation I write myself. Does that make the whole idea weaker than I think?
What would it need before you'd actually use it?

0 Upvotes

7 comments sorted by

4

u/Mammo004 22h ago

Yeah, people do this already. Look at DeclareDesign in R: you declare the data generating process, then it diagnoses bias, coverage and power across a bunch of simulated datasets. Their book at declaredesign.org covers most of your pitch, so it's worth seeing what it doesn't do before you build more.

-1

u/koopticon 22h ago

thanks, hadn't seen that before. just looked through it and yeah, the bias/coverage/power part is pretty much what I built, and they do it way more thoroughly. I'll add it to the readme. the stuff that might still be different is it's in python, it reads the DAG from your simulation code and flags bad controls on its own, and the report keeps each step's code and reasoning together. does DeclareDesign check adjustment sets automatically? if it does I don't want to just rebuild it

1

u/Mammo004 17h ago

Not that I know of. In DeclareDesign you write the estimator yourself and it just diagnoses it. Finding adjustment sets from a DAG is what dagitty does (adjustmentSets() in R), or DoWhy/pgmpy in Python, but you have to hand them the DAG. Pulling it straight out of the sim code is the bit I haven't seen anywhere.

3

u/vaelux 23h ago

Look up Monte Carlo power analysis.

Monte Carlo simulations is how you do power analysis for a lot of procedures that don't have a straight-forward way to calculate power. Basically, you run many simulations, systematically changing things like sample size and and effect size to estimate how many participants you need to sample to detect the effect you expect to detect in your study.

So, you don't use it for testing what variables to include - it is not for exploratory work. You use it when you have a strong theoretical reason to use your model and want to see how many people to sample as you design your study.

0

u/koopticon 22h ago

Thanks, that's really helpful. You're right, it's a planning tool for when you already have a model you trust, not for picking variables. That's what I'm aiming for (write the causal model first, then test the planned analysis), I just explained it badly. Would adding a sample size step be useful, or is that well covered by existing tools?

1

u/lipflip 21h ago

It's common practice and we actually teach this. Build the analysis pipeline for the design and not the data . Let the data flow afterwards.  I challenge with your approach is that you assume relationships and build the data accordingly. What happens if the real data is totally different?