How to configure spatial mixing
This guide shows how to set up a spatial mixing model and attach it to an infection component so that disease spreads between patches.
Choose a mixing model
Select one of the four available models based on your needs:
| Model | Best for | Key advantage |
|---|---|---|
GravityMixing |
General use, calibration to travel data | Intuitive, tunable parameters |
RadiationMixing |
Minimal calibration needed | Nearly parameter-free |
CompetingDestinationsMixing |
Clustered urban areas | Captures destination competition |
StoufferMixing |
Terrain-constrained travel | Distance-independent opportunity model |
If you are unsure, start with GravityMixing — it is the most widely used in epidemiological modeling.
Set up the mixer
Create the mixer with its parameter object. You do not need to pass the scenario data — the model provides it automatically before the first timestep.
1 2 3 4 5 6 7 | |
For the radiation model:
1 2 3 | |
Attach the mixer to an infection component
Pass the mixer to the infection component's parameter class. The exact parameter class depends on your model type.
1 2 3 4 5 6 7 | |
The infection component reads the mixing matrix at each timestep to distribute infectious pressure across patches.
Inspect the mixing matrix before running
If you want to examine the mixing matrix before running a simulation, pass the scenario data explicitly:
1 2 3 4 5 6 7 8 9 10 | |
You can also check trip volumes:
1 2 3 4 5 | |
Adjust the scale parameter k
The k parameter controls overall mobility. Start with the default (k=0.01) and adjust based on your study:
- Increase
kif spatial spread is too slow compared to surveillance data. - Decrease
kif outbreaks synchronize across patches faster than observed. - Set
k=0to disable inter-patch transmission entirely (useful for debugging).
The right value depends on your timestep length, geographic scale, and study population. For a country-level simulation with admin-2 patches and daily timesteps, values between 0.001 and 0.05 are typical.
Switch between mixing models
Because all mixers share the same BaseMixing interface, switching models requires only changing the import and parameter class:
1 2 3 4 5 | |
The rest of your code — infection component setup, model construction, analysis — remains unchanged.
See also
- Spatial mixing — conceptual explanation of the four mixing models
- Tutorial: Spatial mixing — hands-on tutorial on spatial mixing
- Worked examples — complete runnable scripts showing component wiring
- Troubleshooting — common issues with mixing and components
- API reference — full parameter details