The rate rose, but no group changed
Overall conversion rose from 4.0% to 4.6% while mobile and desktop stayed exactly where they were. Find where the rise came from.
2 parts · 6 and 5 min
Free course. Your Maestro, an AI, .
On the previous page, an upward trend already under way made a four-week before-and-after comparison look like a win for the redesign. Time trends are only one trap in an observational comparison. Another happens even when no group changes over time at all.
Suppose analytics compares checkout conversion in the month before the redesign with the month after and reports that overall conversion rose from 4.0% to 4.6%. Before acting on that 0.6-point gain, you ask for the same table broken down by device: mobile and desktop. Looking inside each device group turns up a puzzle: neither group's conversion rate moved.
An overall conversion rate across all visitors is a Glossary word of the conversion rates of the groups inside it, where each group's weight is its share of total sessions. Because both the group rates and the group shares feed into that total, the overall rate can move without a single group changing.
Try it
Run the starter code to compare the overall rate in each period with the rate inside each device. Then complete the two calculations at the bottom of the script:
- Compute each device's share of its period's total sessions using
sessions.groupby("period")["sessions"].transform("sum"). - Compute what the after period's overall rate would have been if the traffic split had stayed at the before period's shares: align the rows by device and sum
after["rate"] * before["share"].
If aligning the two periods by device gets in your way, ask your Maestro how .set_index("device") pairs the rows.
A good place to stop. Up next: Where the 0.6 points came from · 5 min
Where the 0.6 points came from
Look at the numbers your script printed. Both periods had 10,000 total sessions, and within each device the conversion rate stayed exactly where it was:
- Mobile converted at 2.0% (0.02) in the before period (100 orders out of 5,000 sessions) and 2.0% (0.02) in the after period (70 orders out of 3,500 sessions).
- Desktop converted at 6.0% (0.06) in the before period (300 orders out of 5,000 sessions) and 6.0% (0.06) in the after period (390 orders out of 6,500 sessions).
Yet the combined rate rose from 4.0% (0.04, from 400 orders out of 10,000 sessions) to 4.6% (0.046, from 460 orders out of 10,000 sessions). Your share calculation shows why: in the before period, mobile and desktop each accounted for 50% (0.50) of sessions. In the after period, desktop rose to 65% (0.65) of sessions and mobile dropped to 35% (0.35).
Because desktop converts at 6.0% compared with mobile's 2.0%, shifting 1,500 sessions from mobile to desktop added 60 orders (90 more on desktop minus 30 fewer on mobile) without changing how visitors on either device behaved. That is a composition shift, also called a mix shift: the overall rate moved because the mix of groups changed rather than any group changing.
Standardizing to a fixed mix
To separate within-group change from a shift in who showed up, you standardize the after-period rates to a fixed mix of traffic, such as the before period's 50/50 split. Multiplying each device's after-period rate by its before-period share and adding them together via (after["rate"] * before["share"]).sum() gives:
0.02 * 0.5 + 0.06 * 0.5 = 0.04
At the before period's mix, the after period converts at 4.0% (0.04), matching the before period's 4.0% rate with zero difference. All 0.6 percentage points of the headline gain came from the change in device composition, and 0.0 points came from changes within mobile or desktop. If you want to work through a case where both the group rates and the group shares move at the same time, ask your Maestro how standardization splits the two.
The same family as Simpson's paradox
Composition shift belongs to the same family of effects as Glossary word, the extreme case in which every group moves in one direction while the combined rate moves in the opposite direction. The classic real-world analysis is Bickel, Hammel and O'Connell (1975), "Sex bias in graduate admissions: data from Berkeley", Science 187(4175):398–404, which showed that an apparent overall difference in graduate admission rates came from applicants applying in different shares to departments with very different admission rates.
A mix shift does not have to reverse every group's direction to throw off a decision. Whenever groups have different baseline rates (here, 2.0% on mobile and 6.0% on desktop) and their shares of traffic change between the two periods you compare (50% desktop to 65% desktop), the overall rate blends any real change inside the groups with the shift in group weights.
Why randomization protects against mix shifts
Composition shift is a prime hazard of before-and-after comparisons because two calendar periods rarely draw the exact same mix of visitors. A desktop ad campaign, an email blast during work hours, or a mobile app bug in the second month can shift the desktop share from 50% to 65% right when a redesign goes live.
In a randomized test, incoming visitors during the same time window are assigned by chance to control or treatment. Because a mobile visitor and a desktop visitor have the same probability of landing in either arm, random assignment balances the device mix between control and treatment in expectation. The device shares in the two arms can still differ slightly from pure sampling wobble, which the intervals from Module 1 account for, but randomization prevents a month-over-month traffic shift from masquerading as an effect of the redesign.