Which inputs matter? Sensitivity and design of experiments¶
In short
- You build: a script that ranks three inputs of a call centre by how far they move the mean wait. It then runs a full factorial design to see their effects together.
- You need: Python 3.11 or later,
pip install nagasim, and the replications tutorial.- Time: about fifteen minutes.
A model has many inputs, and an experiment on all of them at once is slow. By the end you rank the inputs with a tornado table, run a DOE over the three that matter, and read each main effect and the signs of an interaction.
This page has three parts: Step by step, Check yourself and If stuck. The last section lists the reference pages for the elements used.
Step by step¶
- Save this script as
goal-doe.py. It models a call centre with six agents. It names three factors: the number of agents, the arrival rate and the service rate. The response is the mean wait of a caller.
from nagasim import build as nb, optimize
m = nb.Model(time_limit=480, warmup=0) # one 8-hour day, in minutes
m.add_resource(name="Agents", capacity=6)
arrive = m.create(distribution=nb.Exponential(rate=2.0)) # two calls a minute
serve = m.process(resource_name="Agents", distribution=nb.Exponential(rate=0.5)) # 2 minutes each
arrive >> serve >> m.dispose()
layout = m.to_dict()
wait = "resource/Agents/Time in Queue Avg"
factors = [
optimize.Factor(path="resources.Agents.capacity", kind="integer", low=5, high=7, name="agents"),
optimize.Factor(path=f"blocks.{arrive.name}.params.dist_params.rate", low=1.6, high=2.0, name="arrival rate"),
optimize.Factor(path=f"blocks.{serve.name}.params.dist_params.rate", low=0.45, high=0.55, name="service rate"),
]
# One-at-a-time first: which factor moves the wait most, one run each.
print(optimize.tornado(layout, factors, wait, replications=5, seed=1)
[["Factor", "KPI at low", "KPI at high", "Swing"]].round(2).to_string(index=False))
# Then a full factorial, every combination of low and high, on common random numbers.
design = optimize.full_factorial(factors, levels=2)
result = optimize.run_design(layout, factors, design, responses=[wait], replications=5, seed=1)
print(result.table[["Point", "agents", "arrival rate", "service rate", "Mean"]].round(2).to_string(index=False))
print(result.main_effects(wait)[["Factor", "Level", "Mean", "Effect", "Effect LB", "Effect UB"]].round(2).to_string(index=False))
- Run it.
python goal-doe.py
You should see this. The script seeds itself, so the numbers are the same on your machine.
Factor KPI at low KPI at high Swing
agents 0.68 0.05 0.63
service rate 0.37 0.09 0.28
arrival rate 0.10 0.33 0.23
Point agents arrival rate service rate Mean
0 5 1.6 0.45 0.71
1 5 1.6 0.55 0.21
2 5 2.0 0.45 3.23
3 5 2.0 0.55 0.66
4 7 1.6 0.45 0.05
5 7 1.6 0.55 0.01
6 7 2.0 0.45 0.20
7 7 2.0 0.55 0.04
Factor Level Mean Effect Effect LB Effect UB
agents 5.00 1.20 -1.12 -2.43 0.19
agents 7.00 0.08 -1.12 -2.43 0.19
arrival rate 1.60 0.25 0.79 -0.14 1.72
arrival rate 2.00 1.03 0.79 -0.14 1.72
service rate 0.45 1.05 -0.82 -1.82 0.19
service rate 0.55 0.23 -0.82 -1.82 0.19
-
Read the first table, the tornado. Each factor moves alone from its low to its high value while the other two stay in the middle of their ranges.
Swingis the distance between the two results. The table is sorted by swing, so the first row is the input to look at first. -
Read the second table. A full factorial runs every combination of the low and high value of each factor, so three factors give eight points. Every point runs on the same seeds, so differences between points are not luck. Point 2 has few agents, a high arrival rate and a slow service, and it waits far longer than the rest.
-
Read the third table. For each factor it gives the mean wait at its low and high level, taken over all points, and the
Effect, the change between the two levels.Effect LBandEffect UBare the ends of a 95% interval on that change. When the interval holds zero, five replications per point cannot separate the effect from noise. -
Compare the tables. The tornado changes one input at a time and cannot see that agents matter most when arrivals are high and service is slow. The factorial can, because point 2 sits far above the others. An average over all points, the main effect, spreads that one bad corner over every row. That is what an interaction looks like.
Check yourself¶
- Predict, then run: if you raise
replicationsfrom 5 to 20, will the effect intervals get narrower or wider? CheckEffect LBandEffect UB. - Explain it back: why does the tornado rank agents first while the main-effect interval for agents still holds zero?
Done when¶
- [ ] The script prints a tornado table with three rows, a design table with eight points and a main-effect table with six rows.
- [ ] You can say what
Swingmeasures and what it does not test. - [ ] You can point at the design row that shows an interaction.
If stuck¶
| What happens | Likely cause | Fix |
|---|---|---|
ModelValidationError: override path 'blocks.nope.params.distribution': no blocks entry named 'nope' |
The block name in a factor's path is not one the model has | Build the path from the block object, as the script does with arrive.name. |
ValueError: unknown response KPI |
The response key is misspelled | Copy the key from the KPI reference. |
| The design has fewer points than you expect | An integer factor with a narrow range has fewer distinct levels than you asked for | Widen the range. An integer factor from 3 to 4 has two levels however many you ask for. |
| Every effect interval holds zero | Too few replications for the noise | Raise replications, or use fewer and wider factors. |
Elements this page uses¶
- Python:
run_design,full_factorialandtornadofromnagasim.optimize(its entry pointoptimizeis on the previous page), andModel. - Blocks: CREATE, PROCESS and DISPOSE.
- Distribution: Exponential.
- KPI:
Time in Queue Avgin the resource summary. - Background: Experiments covers the three design types and the command line (
naga doe).