Chapter 4 · Learning from Experiments
Vienna University of Economics and Business (WU)
November 2026
Experiments I (session 3)
4.1 Back to the A/B test
4.2 The difference between two means
4.3 Testing a hypothesis
4.4 Same people, both conditions: the paired t-test
4.5 How large is the effect?
4.6 Reporting the result
Experiments II (session 4)
4.7 The difference between two shares
4.8 How many users do we need?
4.9 More than two groups and other tests
4.10 Using p-values responsibly
Driving question: Did it work?
Welch Two Sample t-test
data: hours by group
t = 2.2, df = 387, p-value = 0.03
alternative hypothesis: true difference in means between group Smart Mix and group Control is not equal to 0
95 percent confidence interval:
0.2936 6.1961
sample estimates:
mean in group Smart Mix mean in group Control
23.22 19.97
Where Chapter 3 ended: two means with their intervals — and a test output with numbers we have not decoded yet.
Boxplot + the actual users (jitter): the first chart in any analysis.
The formulas stay minimal: we compute one standard error by hand to see what a test does. After that, R does the arithmetic — we do the interpretation.
Repeat the experiment many times → the difference varies too. Its sampling distribution is:
SE_{\bar{x}_1 - \bar{x}_2} = \sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}
Smart Mix:
\sqrt{\frac{16.2^2}{200} + \frac{13.7^2}{200}} = 1.50 \text{ hours}
Every test compares the signal (observed difference) with the noise (the standard error). This is the only SE we compute by hand today.
If Smart Mix had no effect, a difference of 3.2 hours or more would occur in only ~4% of experiments. Either Smart Mix works — or the team saw a rare accident.
Course book, §4.2 — change the users per group and the observed difference.
https://wu-rds.github.io/MA2026/04-experiments.html#sec-exp-difference
Is a difference of 3.2 hours surprising with 50 users per group? With 800?
Test statistic = signal / noise:
t = \frac{3.24 - 0}{1.50} = 2.16
If H_0 were true, 95% of all t values would lie between −1.97 and +1.97. Ours lies outside.
p-value: the probability of a difference at least as extreme as the observed one — if H_0 were true.
Our simulation said ~4%, the t-test says 3.1% — the test formalizes the thought experiment.
(\bar{x}_1 - \bar{x}_2) \pm t_{0.975} \times SE_{\bar{x}_1 - \bar{x}_2} = 3.24 \pm 1.97 \times 1.50
CI excludes 0 ⇔ p < 0.05. Test and interval always agree.
The interval tells more: the effect could be a quarter of an hour — or six hours.
| Output | Meaning |
|---|---|
Welch Two Sample t-test |
Two independent groups; equal variances not assumed (R’s safe default) |
t = 2.1617 |
Observed difference = 2.16 standard errors away from zero |
df = 386.96 |
Degrees of freedom — shape of the t-distribution; irrelevant for large samples |
p-value = 0.03125 |
With no effect, ≥ this difference in 3.1% of experiments |
alternative hypothesis: … |
Two-sided: a difference in either direction |
95 percent confidence interval: 0.29 6.20 |
Effects compatible with the data |
mean in group … |
Group means; their difference = the estimated effect |
An information budget. Each observation is one piece of information. Every quantity we estimate from the data uses one up. What is left — n minus the number of estimated parameters — is the information available for judging the noise.
| Situation | Estimated | df |
|---|---|---|
| One sample, SD of n values | 1 mean | n - 1 |
| Two groups (t-test) | 2 means | n_1 + n_2 - 2 |
| ANOVA with 3 groups | 3 means | N - 3 |
| Regression with k predictors | k + 1 coefficients | n - k - 1 |
Why “free to vary”? Budget of 100 € for three presents, all spent: choose present 1 (30 €) and 2 (50 €) freely — present 3 is fixed (20 €). Three values, one constraint → 2 degrees of freedom. Same with deviations from a mean: once the mean is known, the last deviation is determined.
Fewer df → less information about the noise → the standard error is itself uncertain → fatter tails, larger critical values. Smart Mix: ~398 df → practically the normal distribution. Welch’s 386.96: a weighted version of the same idea.
| Design (§1.6) | Who is compared | Data | Test |
|---|---|---|---|
| Between-subjects | Different people in each condition | One row per person + a group variable | Welch t-test: t.test(y ~ group) |
| Within-subjects | The same people in every condition | One row per person, one column per condition | Paired t-test: t.test(x1, x2, paired = TRUE) |
Smart Mix was between-subjects (each user saw one home screen) → Welch test. The question does not change with the design — but the data come in pairs, and the test must use that.
The question: does the new search design let users find songs faster?
Within-subjects design: the same 60 users search for songs with the old design and with the new one, in random order (half old → new, half new → old). Outcome: seconds to find a song.
Paired t-test
data: search_test$new_design and search_test$old_design
t = -3.9, df = 59, p-value = 0.0003
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-3.235 -1.031
sample estimates:
mean difference
-2.133
paired = TRUE tests whether the mean of the within-user differences is zero: the new design saves 2.1 seconds (95% CI 1.0–3.2). Each user is their own control — the differences between users drop out.
Welch Two Sample t-test
data: search_test$new_design and search_test$old_design
t = -1.5, df = 118, p-value = 0.1
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-4.9714 0.7047
sample estimates:
mean of x mean of y
39.49 41.62
Same data, same means, same 2 seconds — but p = 0.14 and the interval includes 0. The independent-groups test judges the difference against the spread of all search times (users differ: SD ≈ 8 s); the paired test against the spread of the within-user differences (SD ≈ 4 s). Comparing different people adds uncertainty — the within-subjects design removes it.
When to use which: between-subjects data → Welch test (nothing to pair). Within-subjects data, matched pairs, before/after on the same people → paired test. Price of within-subjects: carryover and order effects (§1.6) — the paired test cannot fix those.
A food-delivery app — two experiments, two data sets (04-experiments.R, section “Your turn”):
(1) The free-delivery voucher. 300 new customers, randomly split: 150 got a voucher for their first four weeks, 150 did not. Outcome: order value in euros.
(2) The routing app. 40 couriers delivered with the old app and the new one (random order). Outcome: minutes per delivery.
First question for both: which design is this — and therefore which test?
d = \frac{\bar{x}_1 - \bar{x}_2}{s_{\text{pooled}}}, \qquad s_{\text{pooled}} = \sqrt{\frac{s_1^2 + s_2^2}{2}}
Smart Mix: s_{\text{pooled}} = √((16.2² + 13.7²)/2) = 15.0 hours → d = 3.2 / 15.0 = 0.22
(Sign = order of the groups; size ≈ 0.22. For unequal group sizes, R weights the two variances by group size — still no √n anywhere.)
t vs. d — same numerator, different denominator. t divides by the standard error s_{\text{pooled}}\sqrt{2/n}, which shrinks with √n → t grows with the sample. d divides by s_{\text{pooled}} itself → the same at 400 or 40,000 users. t says how detectable the effect is; d how large.
Conventions (Cohen, 1992): 0.2 small · 0.5 medium · 0.8 large — a starting point, not a verdict: +16% listening time can be worth a lot.
Users with Smart Mix listened on average 23.2 hours in four weeks, compared with 20.0 hours in the control group — an increase of 3.2 hours (+16%, 95% CI [0.3; 6.2] hours). The difference is statistically significant (Welch t-test: t(387) = 2.16, p = .031) but small in standardized terms (d = 0.22). The confidence interval is wide: the true effect could be anywhere between a few minutes and six hours.
The last sentence is the most important one: it tells the reader how much the conclusion is worth.
The chart that goes with the paragraph: means, their intervals, and the test result on the bracket.
Debrief A1 + quiz Chapter 3 (15 min, one sheet)
Assignment 2 is handed out today (end of session).
New: devices only when we code
Today: shares → sample size → coding block 1 → ANOVA → coding block 2 → non-parametric tests → p-values.
2-sample test for equality of proportions with continuity correction
data: c(131, 104) out of c(2000, 2000)
X-squared = 3.1, df = 1, p-value = 0.08
alternative hypothesis: two.sided
95 percent confidence interval:
-0.001569 0.028569
sample estimates:
prop 1 prop 2
0.0655 0.0520
SE_{\hat{p}_1 - \hat{p}_2} = \sqrt{\frac{\hat{p}_1 (1 - \hat{p}_1)}{n_1} + \frac{\hat{p}_2 (1 - \hat{p}_2)}{n_2}} \qquad \text{CI: } (\hat{p}_1 - \hat{p}_2) \pm 1.96 \times SE
Same intuition as for means: more variation within the groups and smaller groups → more uncertain difference. Premium test: 1.35 ± 1.96 × 0.74 = [−0.11; 2.81] points.
Why not [−0.11; 2.81] as on the previous slide? prop.test() applies a continuity correction by default (counts are whole numbers): the interval widens by ½ × (1/2,000 + 1/2,000) = 0.05 points on each side, and p rises from 0.07 to 0.08. prop.test(..., correct = FALSE) reproduces the hand calculation exactly.
The right conclusion: “this experiment was too small to tell” — not “the trial offer does not work”. (prop.test() = chi-square test for a 2 × 2 table; chisq.test() for more groups or categories.)
Two sales agents each talk to 300 customers. Jon gets 200 to buy, Mark 100.
prop.test() and report the difference with its 95% CI.Example after McDonnell Feit & McCullough, Business Experiments.
Means — Smart Mix, d = 0.22, 80% power:
Shares — Premium test, 5% → 6%:
Start from the smallest effect that would still matter for the decision — not from the effect you hope for.
power and give n instead → the power of the test you ranLow baseline rates + small lifts = enormous samples.
Lewis & Rao (2015), “The Unfavorable Economics of Measuring the Returns to Advertising”, Quarterly Journal of Economics, 130(4), 1941–1973.
| No effect in reality (H_0 true) | Effect in reality (H_0 false) | |
|---|---|---|
| Significant | Type I error — false alarm (\alpha) | ✓ effect detected (power = 1 - \beta) |
| Not significant | ✓ | Type II error — effect missed (\beta) |
sig.level): one in twenty tests of a useless feature is “significant” anywaypower = 0.80): one in five real effects of that size is still missedpower.t.test() / power.prop.test() computeCourse book, §4.8 — baseline rate, lift, and traffic per day.
https://wu-rds.github.io/MA2026/04-experiments.html#sec-exp-power
Your group project: ~60 per condition → only d \gtrsim 0.5 detectable with 80% power (small effects: < 20% power). Make your manipulation strong.
A newsletter has a click-through rate of 2%. A new subject line should be tested.
Use power.prop.test().
| Situation | Type I error (false alarm) | Type II error (missed effect) |
|---|---|---|
| Pregnancy test | “Pregnant” — but she is not | “Not pregnant” — but she is |
| Smoke detector | Alarm because of burnt toast | Real fire, no alarm |
| Court trial | Innocent person convicted | Guilty person acquitted |
| A/B test | Useless feature rolled out | Valuable feature dropped |
The court trial is a test: H_0 = “innocent” is kept unless the evidence is strong. “Not guilty” does not prove innocence — just as “not significant” does not prove “no effect”.
Effect size · sample size · variability. With a true effect of 3 hours, Smart Mix had only ~55% power — the team was somewhat lucky.
Course book, §4.8 — change the true effect, the users per group, and α.
https://wu-rds.github.io/MA2026/04-experiments.html#sec-exp-power
Halve the true effect. How many more users do you need for the same power?
In the widget, you set the true effect — in practice, you never know it (otherwise: no experiment needed). Power analysis uses an assumed effect:
No “post-hoc power”: computing power after the experiment with the observed effect adds nothing — it is just a transformation of the p-value. Power belongs to the planning stage; afterwards, look at the confidence interval.
The case. A streaming service tests a new subject line for its weekly newsletter: 8,000 subscribers, randomly split — 4,000 get the old subject line, 4,000 the new one. Outcome: did the subscriber click (1) or not (0)?
Data: newsletter_test.csv — section “Coding block 1” in 04-experiments.R
Laptops open — alone or with your neighbor.
Tasks (same steps as the Premium example)
prop.test(): is the difference significant? Report it in one sentence — effect, uncertainty, testAt the end: one group presents its numbers.
Three versions of Smart Mix, tested at once:
The product team asks: does the update frequency matter — and if so, which version is better than which?
Three versions → three pairwise tests, each with a 5% false-alarm risk:
\text{family-wise error rate} = 1 - (1 - \alpha)^k
Two steps: (1) Is there any difference? → ANOVA. (2) Which groups differ? → corrected pairwise comparisons.
Total = model + residual: SS_T = SS_M + SS_R
135,122 = 3,367 + 131,755
F = \dfrac{SS_M / (k - 1)}{SS_R / (N - k)} = \dfrac{3{,}367 / 2}{131{,}755 / 447} = 5.71 · \eta^2 = SS_M / SS_T = 2.5%
Group means far apart (9.7 / 22.1 / 34.1 hours), users within a group similar → most of the total variation lies between the groups.
\eta^2 = 44,550 / 55,075 = 81% · F(2, 447) = 946, p < .001
Group means (almost) equal to the grand mean (22.1 / 20.8 / 22.2 hours) → the model panel is (almost) empty: SS_R \approx SS_T.
\eta^2 = 200 / 104,549 = 0.2% · F(2, 447) = 0.43, p = .65 — no evidence that the version matters
F = \frac{\text{variation between groups (per df)}}{\text{variation within groups (per df)}}
Df Sum Sq Mean Sq F value Pr(>F)
version 2 3367 1683 5.71 0.0036 **
Residuals 447 131755 295
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
[1] 0.02492
F(2, 447) = 5.71, p = .004 — at least one version differs; but the versions explain only 2.5% of the variation.
Uncorrected (each test at 5%):
No mix Weekly mix
Weekly mix 0.1910654 NA
Daily mix 0.0008673 0.04158
Bonferroni-corrected:
Bonferroni, step by step: 3 comparisons, family-wise \alpha = 5%
Only daily vs. no mix differs (p = .003). Alternatives: Holm (R’s default, equally safe, more powerful), Tukey’s HSD (TukeyHSD(mix_aov)).
Mean listening time differed between the three versions of Smart Mix (no mix: 19.1 hours, weekly mix: 21.7, daily mix: 25.7; one-way ANOVA: F(2, 447) = 5.71, p = .004, \eta^2 = .025). Bonferroni-corrected pairwise comparisons showed that users with the daily mix listened 6.6 hours more than users without a mix (p = .003); the weekly mix did not differ significantly from either of the other versions (both p > .12).
Means first, then the overall test with df, p and effect size, then which groups differ (corrected).
The case. An online shop tests three versions of its checkout page: Standard, Discount banner, Bundle offer. 360 customers, randomly assigned (120 per version). Outcome: order value in euros.
Data: price_page.csv — section “Coding block 2” in 04-experiments.R
Laptops open — alone or with your neighbor.
Tasks (same steps as the Smart Mix example)
At the end: one group presents its numbers.
Smart Mix: t-test p = .031, Wilcoxon p = .073 — different questions: average (pulled up by heavy listeners) vs. typical user. Code for all three tests: “Under the hood” boxes in the book.
| Outcome | Groups | Design | Test | R |
|---|---|---|---|---|
| Metric | 2 | different people | Welch t-test | t.test(y ~ group) |
| Yes/no | 2+ | different people | proportions / chi-square | prop.test(), chisq.test() |
| Metric | 2 | same people | paired t-test | t.test(x1, x2, paired = TRUE) |
| Metric | 3+ | different people | ANOVA + corrected post-hoc | aov(), pairwise.t.test() |
| Ordinal / extreme skew, small n | 2 | different people | Wilcoxon rank-sum | wilcox.test(y ~ group) |
| Ordinal / extreme skew, small n | 2 | same people | Wilcoxon signed-rank | wilcox.test(x1, x2, paired = TRUE) |
| Ordinal / extreme skew, small n | 3+ | different people | Kruskal–Wallis | kruskal.test(y ~ group) |
flowchart LR A["Outcome?"] -->|Metric| Q["Assumptions<br/>in doubt?"] A -->|Yes/no| C["prop.test()<br/>chisq.test()"] A -->|Ordinal| N["Groups?"] Q -->|No| B["Groups?"] Q -->|"Yes (small n, extreme<br/>skew / outliers)"| N B -->|Two| D["Same people?"] B -->|3+| E["ANOVA +<br/>post-hoc"] D -->|No| F["Welch t-test"] D -->|Yes| G["Paired t-test"] N -->|"Two, different people"| H["Wilcoxon<br/>rank-sum"] N -->|"Two, same people"| I["Wilcoxon<br/>signed-rank"] N -->|3+| J["Kruskal–Wallis"]
A starting point, not a recipe: the right analysis follows from the research question and the design — not from walking down a tree.
p = P(data | H_0)
“If there were no effect, how likely would data like ours be?”
Not: P(H_0 | data)
P(runny nose | cold) ≠ P(cold | runny nose)
p = 0.031. True or false?
| Everyday comparison | d | n per group (80%) |
|---|---|---|
| Men taller than women | 1.85 | 6 |
| Spicy-food fans like Indian food more | 0.80 | 26 |
| Men weigh more than women | 0.59 | 46 |
| Science fans name more planets | 0.07 | 3,669 |
Nothing special happens at p = 0.05: 0.049 is no stronger evidence than 0.051. Report the exact p, the effect size, and the CI — as leading journals (e.g., JM, JMR) now ask authors to do.
Simmons, Nelson & Simonsohn (2013), survey of 697 US participants; Wasserstein & Lazar (2016), “The ASA Statement on p-Values”, The American Statistician.
Checking the dashboard every day and stopping at p < 0.05 turns a 5% false-alarm rate into 30–40%. Fix the sample size in advance; evaluate once — or use sequential testing.
Course book, §4.10 — 200 A/B tests without any effect; the analyst stops at the first p < 0.05.
https://wu-rds.github.io/MA2026/04-experiments.html#sec-exp-nhst
What happens to the false-alarm rate if the analyst checks more often, or lets the test run longer?
van Zwet & Cator (2021), Statistica Neerlandica, CC BY-NC-ND 4.0
10 points: report 7 + debrief 3. Report effect sizes and confidence intervals — not just p-values. Your results may well be non-significant — interpret them correctly.
Module 5 · Observational data I — What if we cannot randomize?
Marketing Analytics — Nils Wlömert