Model dependenceLesson 26 of 76 · 7 min
Make the shared cause visible
Represent common conditions once per trial and propagate them to related inputs.
A common cause is a simulated condition that influences several outcomes. It should be drawn once for the relevant unit. Drawing a fresh weather condition for every calculation in one event would erase the relationship the model intends to represent.
Here a busy-day factor affects both arrival counts and average spending. Each trial draws one factor and passes it into both calculations. Conditional on that factor, additional randomness can still remain in each outcome.
This hierarchical model draws a shared condition first, then outcomes given that condition. The factor is latent, meaning unobserved in the scenario, rather than a separate measured input. It is one possible mechanism, not proof about a real shop. Inspect intermediate values and challenge the shared-cause assumption.
F is the shared busy-day multiplier; log(F) is normal with mean 0 and SD .25. The arrows mean use that same F in both calculations.
- Draw the common condition
- Use it in both inputs
- Propagate the relationship
What happens to the intended dependence if you redraw the day factor separately for spending?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Arrival/spending correlation: 0.84 Mean and P90 revenue (£): 545.45 929.91 First three shared factors: [0.574 1.007 0.874]
Read the first result
The model makes the common factor inspectable. Revenue inherits both its direct and indirect effects.
Try an edit
On the spend_per_customer line, replace 12 * busy_factor with 12 * rng.lognormal(0, .25, len(busy_factor)). The arrival calculation stays fixed. Select Run Python again. Compare Arrival/spending correlation and Mean and P90 revenue (£) with the first run. What changed when spending used a fresh factor with the same distribution?
Scope. The busy-day mechanism is invented, and the chosen spending noise is not fitted to observations.
Try a fresh case
A regional storm affects several deliveries. Where should its state be drawn?
Need a hint?
Hint 1
Name the unit to which the storm belongs.
Hint 2
Keep all outcomes from that unit attached to the same state.