Model dependenceLesson 29 of 76 · 7 min
Sample one condition after another
Use conditional sampling to preserve relationships and constraints.
Conditional sampling specifies a distribution after a relevant condition has been drawn. It gives a transparent sequence: simulate the state, select the appropriate input model, then simulate the outcome from that model.
In this event example, rain is drawn once per event. Attendance probability is lower on rainy days. The guest count is then drawn using the event’s probability. Marginally, guests share a weather influence, so the resulting attendance distribution is not the same as one fixed-probability binomial in every respect.
The law of total expectation gives a useful exact mean check: average the conditional expectations using the state probabilities. Matching that mean does not establish the correct tail shape. Compare both the overall distribution and the conditional groups when checking a model.
reads ‘attendance X given guest chance p’. The weather selects p once for each complete event.
- Weather
- Attendance chance
- Event attendance
Can replacing the two weather-dependent probabilities with their average preserve the mean while changing the spread?
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 ↗
Simulated / exact mean attendance: 71.132 71.0 Mean on rainy / dry days: 49.97 80.0 Overall attendance SD: 14.369 P(attendance > 80): 0.3248
Read the first result
Compare the rainy-day and dry-day means in Mean on rainy / dry days. The shared weather condition affects the spread of the overall counts. P(attendance > 80) gives the fraction of simulated events with more than 80 attendees.
Try an edit
Replace attendance = rng.binomial(100, attendance_probability) with attendance = rng.binomial(100, .71, size=len(rainy)). Select Run Python again. Compare Overall attendance SD and P(attendance > 80) with the first run. Why can the probability of a high-attendance event change even when the model mean stays 71?
Scope. The rain probabilities are assumptions, and weather effects are simplified to two event states.
Try a fresh case
A delivery duration depends on its route. Which generation order preserves that model?
Need a hint?
Hint 1
Identify which condition chooses the distribution.
Hint 2
Preserve that condition within the same trial.