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.

Look for an interaction
00.250.50.7515067.585102120Time (ms)Cache: 0 off, 1 on
00.250.50.7515067.585102120Time (ms)Cache: 0 off, 1 on
(−40)−(+10)=−50  ms(-40)-(+10)=-50\;\mathrm{ms}
  • Unique keys
  • Repeated keys
Four invented cells. Switching the cache on adds 10 ms for unique keys but saves 40 ms for repeated keys. These lines describe an interaction; they do not estimate uncertainty.

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

Editor tools
About Python ↗

Ctrl+Enter or ⌘+Enter runs the code.

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.

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
Cache-on time rises for unique keys and falls for repeated keys in the invented table.
Open full-size figure ↗

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?

Choose an answer

Hints for this question
  1. Ask whether one treatment effect describes both conditions.
  2. Compare differences, not just the four cell values.
Your notes