Design a fair testLesson 10 of 30 · 7 min
When one change depends on another
Recognise an interaction by comparing treatment differences at two levels of another factor.
A factor is an input deliberately varied in an experiment. Its levels are the settings tested. A two-by-two factorial design tests every combination of two factors with two levels each.
An interaction means the effect of one factor depends on the level of another. Here, the cache helps when keys repeat, but adds overhead when all keys are unique. Reporting one average cache benefit would hide that dependence.
The four invented cells below illustrate the calculation. A real experiment needs randomised order and independent replication within these combinations to estimate uncertainty. Changing one factor at a time at a single setting of the other can miss an interaction entirely.
- Unique keys
- Repeated keys
Can cache-on be slower for one workload and faster for another?
Write a prediction (optional)
Run the prepared example
This page puts the example in the Python editor. Select Run Python with the code unchanged.
Invented data
A saved draft is open. To run the published example, open Editor tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
What to compare
In the table, find cache_effect_ms for each workload. Which workload gets faster with the cache? Find Difference of effects (ms) and check which effect the code subtracts.
Your result
Result tools
The cache adds 10 ms to unique-key work and saves 40 ms with repeated keys. The difference of the two effects is −50 ms, so a single average would hide a direction change.
Published example output
The site ran the original code to produce this reference. Build environment ↗
workload off_ms on_ms cache_effect_ms unique 100 110 10 repeated 100 60 -40 Difference of effects (ms): -50
The cache adds 10 ms to unique-key work and saves 40 ms with repeated keys. The difference of the two effects is −50 ms, so a single average would hide a direction change.
Change and run again
In the Python editor, find the on_ms list and change the first value from 110 to 60. Select Run Python again. Compare cache_effect_ms and Difference of effects (ms). Are the effects equal for both workloads now? Return to the Python editor
What this example supports. The table has one invented value per combination. It demonstrates an interaction calculation, not a statistically established interaction.
Try a fresh case
A material change helps at high temperature and hurts at low temperature. What should you report?
Hints for this question
- Ask whether one treatment effect describes both conditions.
- Compare differences, not just the four cell values.