Marketing Analytics

Chapter 6 · Mechanisms & Heterogeneity

Nils Wlömert

Vienna University of Economics and Business (WU)

November 2026

Before we start

Paper quiz on Chapter 5, Part II (§5.7–5.10, 8 min)

  • Individual, closed book, counts toward participation

Assignment 3 is running: deadline Group A Sun, Nov 22 · Group B Wed, Nov 25; debrief at the start of next session.

Devices only when we code

  • Input blocks: laptops closed, phones away
  • Coding block (40 min, at the end): laptops open, alone or with your neighbor; results via Menti, then two tables present

Today: interactions and marginal effects → three kinds of moderators → a 2 × 3 experiment → mediation → your group project → one coding block with two cases at the end.

Today’s session

6.1 The average effect hides the interesting part
6.2 Interactions and marginal effects
6.3 Continuous × categorical
6.4 Continuous × continuous
6.5 Categorical × categorical: a 2 × 3 experiment
6.7 Mediation: why does it work?
6.8 Your group project: one moderator, one mediator
Coding block: two cases (40 min)

Reading: 6.6 The pitfalls of looking for heterogeneity

Driving question: Why — and for whom — does it work?

One new ingredient: the product of two variables.

6.1 The average effect hides the interesting part

Smart Mix, second wave

  • 1,200 users, randomized to Smart Mix or control
  • This time with covariates: plan (free/Premium), prior listening, tenure, device
  • And one more variable: new artists discovered during the four weeks
  • Average effect: +3.7 hours (95% CI 3.1–4.3)

The product team asks two more questions:

  1. For whom does it work — free or Premium users? light or heavy listeners?
  2. Why does it work — does it make users discover new music?

Moderation (for whom): the effect depends on a third variable. Mediation (why): the effect runs through a third variable. Easy to confuse — a moderator changes how large, a mediator is part of the path.

6.2 Interactions and marginal effects

What an interaction term does

y = \beta_0 + \beta_1 x + \beta_2 z + \beta_3 (x \times z) + \varepsilon \qquad \Rightarrow \qquad \frac{\partial y}{\partial x} = \beta_1 + \beta_3 z

  • The marginal effect of x depends on z
  • \beta_1 = effect of x when z = 0 (a conditional effect, not a “main effect”)
  • \beta_3 = how much the effect of x changes per unit of z
  • Symmetric: effect of z = \beta_2 + \beta_3 x

Two rules: (1) if zero is not a meaningful value of z, \beta_1 is not meaningful either → center (§6.4). (2) Always keep both main terms: in R, x * z = x + z + x:z.

Parallel, diverging, crossing

With a group indicator as z: no interaction = parallel lines (same slope, different level) · interaction = different slopes · crossover = the effect of x reverses. \beta_3 is simply the difference between the slopes.

6.3 Continuous × categorical

Face 1: a treatment effect that differs between groups

Why a manager cares: if Smart Mix mainly helps free users, it belongs in the free tier’s roadmap and in the upgrade pitch — not in the Premium feature list.

model_plan <- lm(hours ~ smart_mix * premium + prior_hours + tenure, data = wave2)
round(coef(summary(model_plan)), 3)
                  Estimate Std. Error t value Pr(>|t|)
(Intercept)          1.560      0.469   3.327    0.001
smart_mix            4.999      0.378  13.212    0.000
premium              2.685      0.431   6.224    0.000
prior_hours          0.752      0.017  43.974    0.000
tenure               0.028      0.009   3.256    0.001
smart_mix:premium   -3.111      0.590  -5.273    0.000

smart_mix = effect for free users (premium = 0): 5.0 h · smart_mix:premium = how much the effect differs for Premium: −3.1 h (the heterogeneity test) · effect for Premium = 5.0 − 3.1 = 1.9 h · premium = plan difference in the control group.

The chart shows raw means; the coefficients hold prior listening and tenure constant — which is why 5.0 and 1.9 are not exactly the gaps in the chart (4.6 and 1.0). Randomization makes both unbiased; the adjusted estimates are more precise.

Face 1: the marginal effect of Smart Mix

\text{Effect of Smart Mix} \;=\; \beta_{\text{smart\_mix}} + \beta_{\text{smart\_mix:premium}} \times \text{premium} \;=\; 5.00 - 3.11 \times \text{premium}

From the coefficients:

b <- coef(model_plan)
b["smart_mix"] + b["smart_mix:premium"] * c(free = 0, premium = 1)
   free premium 
  4.999   1.887 

With standard errors and confidence intervals (emmeans package):

library(emmeans)
emtrends(model_plan, ~ premium, var = "smart_mix")
 premium smart_mix.trend    SE   df lower.CL upper.CL
       0            5.00 0.378 1194    4.256     5.74
       1            1.89 0.453 1194    0.998     2.78

Results are averaged over the levels of: smart_mix 
Confidence level used: 0.95 

The interaction coefficient (−3.11, p < .001) tests whether the two effects differ; the marginal effects tell you what they are: 5.0 h (CI 4.3–5.7) for free users, 1.9 h (CI 1.0–2.8) for Premium users. Report both.

Both effects with their uncertainty

  • The CI of the Premium effect is not in the regression output — it combines two coefficients and their covariance (emtrends() does it for you)
  • Actionable: promote Smart Mix to free users first

The emtrends() table as a picture: what the product team should see.

Face 2: a slope that differs between groups

Why a manager cares: if the spend elasticity differs by genre, the next promotion euro should go where a percent of budget buys the most streams.

model_genre <- lm(log(streams) ~ log(spend) * genre +
                    log(followers) + placements, data = promo)
round(coef(summary(model_genre)), 3)
                              Estimate Std. Error t value Pr(>|t|)
(Intercept)                     -3.648      0.321 -11.357    0.000
log(spend)                       0.206      0.033   6.171    0.000
genreHipHop/Rap                 -2.058      0.430  -4.786    0.000
genreRock                        0.356      0.654   0.544    0.587
genreElectro/Dance               0.021      0.616   0.034    0.973
log(followers)                   0.507      0.015  33.456    0.000
placements                       0.122      0.011  11.417    0.000
log(spend):genreHipHop/Rap       0.268      0.052   5.178    0.000
log(spend):genreRock            -0.053      0.079  -0.669    0.504
log(spend):genreElectro/Dance    0.005      0.076   0.068    0.946

Same model, different question: log(spend) = elasticity for Pop (reference); log(spend):genreHipHop/Rap = +0.27 → HipHop/Rap elasticity = 0.21 + 0.27 ≈ 0.47. Rock and Electro: no evidence of a different slope. The genre “main effects” are level differences at log(spend) = 0, i.e., at a spend of 1 euro (log(1) = 0) — not at a typical spend.

Face 2: the elasticity of each genre

\text{Elasticity}_{\text{genre}} \;=\; \beta_{\log(\text{spend})} + \beta_{\log(\text{spend}):\text{genre}} \qquad (\text{0 for the reference genre Pop})

From the coefficients:

b <- coef(model_genre)
elasticity <- b["log(spend)"] +
  c(0, b["log(spend):genreHipHop/Rap"], b["log(spend):genreRock"],
    b["log(spend):genreElectro/Dance"])
names(elasticity) <- levels(promo$genre)
elasticity
          Pop    HipHop/Rap          Rock Electro/Dance 
       0.2058        0.4737        0.1532        0.2109 

With confidence intervals:

emtrends(model_genre, ~ genre, var = "log(spend)")
 genre         log(spend).trend     SE  df lower.CL upper.CL
 Pop                      0.206 0.0334 590   0.1403    0.271
 HipHop/Rap               0.474 0.0396 590   0.3959    0.551
 Rock                     0.153 0.0712 590   0.0133    0.293
 Electro/Dance            0.211 0.0679 590   0.0776    0.344

Confidence level used: 0.95 

+1% spend → +0.21% streams for Pop, +0.47% for HipHop/Rap. The intervals of Rock and Electro/Dance overlap Pop’s: no evidence that their elasticities differ.

Moderation by a continuous variable

Why a manager cares: if light listeners gain the most, the feature’s onboarding should target them — heavy listeners need a different lever.

model_prior <- lm(hours ~ smart_mix * prior_hours +
                    premium + tenure, data = wave2)
round(coef(summary(model_prior)), 3)
                      Estimate Std. Error t value Pr(>|t|)
(Intercept)              1.446      0.532   2.720    0.007
smart_mix                5.391      0.660   8.164    0.000
prior_hours              0.797      0.023  34.426    0.000
premium                  1.041      0.301   3.462    0.001
tenure                   0.027      0.009   3.152    0.002
smart_mix:prior_hours   -0.096      0.034  -2.822    0.005
  • smart_mix:prior_hours = −0.096: each hour of prior listening reduces the Smart Mix effect by 0.1 h — the interaction is significant (p = .005)
  • smart_mix alone = effect at zero prior hours — a user who hardly exists

The marginal effect at meaningful values

\text{Effect of Smart Mix} \;=\; \beta_{\text{smart\_mix}} + \beta_{\text{smart\_mix:prior\_hours}} \times \text{prior\_hours} \;=\; 5.39 - 0.096 \times \text{prior\_hours}

From the coefficients, at 10 / 20 / 30 hours:

b <- coef(model_prior)
b["smart_mix"] + b["smart_mix:prior_hours"] * c(10, 20, 30)
[1] 4.427 3.463 2.499

With confidence intervals:

emtrends(model_prior, ~ prior_hours, var = "smart_mix",
         at = list(prior_hours = c(10, 20, 30)))
 prior_hours smart_mix.trend    SE   df lower.CL upper.CL
          10            4.43 0.385 1194     3.67     5.18
          20            3.46 0.307 1194     2.86     4.07
          30            2.50 0.523 1194     1.47     3.52

Results are averaged over the levels of: smart_mix, premium 
Confidence level used: 0.95 

With a continuous moderator, report the effect at meaningful values (e.g., the 10th / 50th / 90th percentile: 9, 15, 28 prior hours) or as a curve with its confidence band — never the coefficient at zero.

Your turn (5 min)

Fit the interaction of Smart Mix with device:

model_device <- lm(hours ~ smart_mix * device + prior_hours + premium + tenure, data = wave2)
round(coef(summary(model_device)), 3)

For which device is the effect of Smart Mix largest? Compute the effect for each device from the coefficients (or with emtrends()). Are the differences significant? (Why a manager cares: a device-specific effect would change the rollout order across the apps.)

6.4 Continuous × continuous

Spend × followers: the uncentered model

Why a manager cares: if promotion pays off more for artists with a large audience, the label can concentrate its budget on them — or deliberately counter “rich get richer”.

\begin{aligned} \log(\text{streams}) &= \beta_0 + \beta_1 \log(\text{spend}) + \beta_2 \log(\text{followers}) + \beta_3 \log(\text{spend}) \times \log(\text{followers}) + \dots \\ \text{Spend elasticity} &= \beta_1 + \beta_3 \log(\text{followers}) \end{aligned}

model_cc <- lm(log(streams) ~ log(spend) * log(followers) + placements + genre, data = promo)
round(coef(summary(model_cc)), 3)
                          Estimate Std. Error t value Pr(>|t|)
(Intercept)                  5.410      1.506   3.593    0.000
log(spend)                  -0.896      0.183  -4.901    0.000
log(followers)              -0.422      0.143  -2.960    0.003
placements                   0.121      0.011  11.435    0.000
genreHipHop/Rap              0.165      0.044   3.767    0.000
genreRock                   -0.096      0.059  -1.624    0.105
genreElectro/Dance           0.065      0.058   1.129    0.260
log(spend):log(followers)    0.113      0.017   6.528    0.000

A negative spend elasticity (β₁ = −0.90)? It is the elasticity for an artist with log(followers) = 0 — one follower (log(1) = 0). Nobody in the data is anywhere near that (median: 36,000 followers). The interaction β₃ = +0.113 (p < .001) is the real finding: each additional unit of log(followers) adds 0.11 to the spend elasticity — and one unit of log(followers) means a follower base multiplied by e ≈ 2.7 (log(2.7 × followers) = log(followers) + 1). Promotion and reach reinforce each other: the same percentage budget increase buys a larger percentage gain for a bigger artist.

Centered at the means

The approach: subtract each variable’s mean from every observation — nothing else changes. But the zero point of each variable is now the mean of the data, so the main effects become marginal effects at the average artist instead of at one follower and one euro.

promo_c <- promo |>
  mutate(log_spend_c = log(spend) - mean(log(spend)),
         log_fol_c   = log(followers) - mean(log(followers)))
model_cc_centered <- lm(log(streams) ~ log_spend_c * log_fol_c + placements + genre, data = promo_c)
round(coef(summary(model_cc_centered)), 3)
                      Estimate Std. Error t value Pr(>|t|)
(Intercept)              3.411      0.044  77.500    0.000
log_spend_c              0.299      0.022  13.314    0.000
log_fol_c                0.508      0.015  33.870    0.000
placements               0.121      0.011  11.435    0.000
genreHipHop/Rap          0.165      0.044   3.767    0.000
genreRock               -0.096      0.059  -1.624    0.105
genreElectro/Dance       0.065      0.058   1.129    0.260
log_spend_c:log_fol_c    0.113      0.017   6.528    0.000

Now log_spend_c = 0.30 is the elasticity for an artist with an average (log) follower count (≈ 39,000 followers). The interaction, the other coefficients, R² and all predictions are unchanged — centering changes what the main effects mean, not the model.

The marginal effect across the follower distribution

\text{Elasticity} \;=\; \beta_{\text{log\_spend\_c}} + \beta_{\text{log\_spend\_c:log\_fol\_c}} \times \big(\log(\text{followers}) - \overline{\log(\text{followers})}\big)

At the 10th / 50th / 90th percentile of followers (7,800 / 36,000 / 205,000):

b <- coef(model_cc_centered)
fol_q <- quantile(promo$followers, c(0.1, 0.5, 0.9))
b["log_spend_c"] + b["log_spend_c:log_fol_c"] *
  (log(fol_q) - mean(log(promo$followers)))
   10%    50%    90% 
0.1175 0.2917 0.4869 

Small artist: +10% spend → +1.2% streams. Big artist: +4.9%. Communicate with the plot, not with the table.

6.5 Categorical × categorical: a 2 × 3 experiment

Are AI-made ads judged as creative as human-made ads?

Why a manager cares: whether to disclose AI involvement is a policy decision — the interaction says when disclosure costs creativity points, and when it does not.

  • 360 respondents rate the creativity of an ad (0–100)
  • Factor 1 — source of the design: Human · AI · Human + AI
  • Factor 2 — disclosure: source revealed · not revealed
  • 2 × 3 = 6 cells, 60 respondents each, randomized

Revealed: human designs win. Not revealed: AI and hybrid designs are rated as creative — slightly higher. Crossing lines = the effect of the source depends on disclosure.

The regression: six coefficients, six cell means

model_ads <- lm(creativity ~ source * disclosure, data = ads)
round(coef(summary(model_ads)), 3)
                                        Estimate Std. Error t value Pr(>|t|)
(Intercept)                               61.800      1.854  33.330        0
sourceAI                                 -13.533      2.622  -5.161        0
sourceHuman + AI                         -18.250      2.622  -6.960        0
disclosureNot revealed                    -9.667      2.622  -3.686        0
sourceAI:disclosureNot revealed           22.233      3.708   5.996        0
sourceHuman + AI:disclosureNot revealed   28.150      3.708   7.591        0
Coefficient Value Meaning (reference cell: Human, Revealed)
(Intercept) 61.8 Mean rating of human designs when the source is revealed
sourceAI −13.5 AI designs, when revealed, vs. human designs
sourceHuman + AI −18.3 Hybrid designs, when revealed, vs. human designs
disclosureNot revealed −9.7 Human designs: not revealed vs. revealed
sourceAI:disclosureNot revealed +22.2 The extra gain of AI designs when not revealed, beyond the two main effects
sourceHuman + AI:disclosureNot revealed +28.2 The same for hybrid designs

Rebuilding a cell: AI, not revealed = 61.8 − 13.5 − 9.7 + 22.2 = 60.8 — the observed cell mean. Any cell mean is the sum of the coefficients that apply to it.

Step 1: is there an interaction at all?

anova(model_ads)
Analysis of Variance Table

Response: creativity
                   Df Sum Sq Mean Sq F value  Pr(>F)    
source              2   1055     527    2.56   0.079 .  
disclosure          1   4572    4572   22.17 3.6e-06 ***
source:disclosure   2  13218    6609   32.04 1.6e-13 ***
Residuals         354  73021     206                    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The ANOVA table tests each factor and the interaction as a whole (two coefficients at once). Interaction highly significant → the effect of the source depends on disclosure → do not interpret the main effects on their own. (Unbalanced cells: car::Anova(model_ads, type = 2).)

Step 2: which cells differ? Estimated marginal means

emm <- emmeans(model_ads, ~ source | disclosure)
pairs(emm, adjust = "bonferroni")       # Tukey instead: pairs(emm), the default
disclosure = Revealed:
 contrast             estimate   SE  df t.ratio p.value
 Human - AI              13.53 2.62 354   5.161  <.0001
 Human - (Human + AI)    18.25 2.62 354   6.960  <.0001
 AI - (Human + AI)        4.72 2.62 354   1.799  0.2187

disclosure = Not revealed:
 contrast             estimate   SE  df t.ratio p.value
 Human - AI              -8.70 2.62 354  -3.318  0.0030
 Human - (Human + AI)    -9.90 2.62 354  -3.775  0.0006
 AI - (Human + AI)       -1.20 2.62 354  -0.458  1.0000

P value adjustment: bonferroni method for 3 tests 

From “there is an interaction” to “where exactly are the differences”: revealed → human beats AI (14 points) and hybrid; not revealed → AI and hybrid beat human by 9–10 points. p-values Bonferroni-adjusted for the three comparisons within each disclosure condition, as in Chapter 4 (Tukey’s HSD gives the same picture with slightly smaller p-values) — the two-step logic of the one-way ANOVA, with one extra dimension.

Your turn (5 min)

  1. Rebuild the cell mean for hybrid designs with the source not revealed from the coefficients of model_ads. Check it against the table of cell means.
  2. Which single number in the regression output answers: “does disclosure change the rating of hybrid designs more than it changes the rating of human designs?”

6.7 Mediation: why does it work?

Total = direct + indirect

  • Indirect effect = a × b: Smart Mix → new artists → hours — the average causal mediation effect (ACME)
  • Direct effect c′: everything else (convenience, habit, curiosity) — the average direct effect (ADE)
  • Total = direct + indirect

Hypothesis of the product team: Smart Mix works because it makes users discover new music. If true, improving discovery improves the effect.

Three regressions

model_m <- lm(new_artists ~ smart_mix + prior_hours + premium, data = wave2)                    # path a
model_y <- lm(hours ~ smart_mix + new_artists + prior_hours + premium + tenure, data = wave2)   # paths b and c'
a <- coef(model_m)["smart_mix"]; b <- coef(model_y)["new_artists"]; c_direct <- coef(model_y)["smart_mix"]
c(a = unname(a), b = unname(b), direct = unname(c_direct), indirect = unname(a * b), total = unname(c_direct + a * b))
       a        b   direct indirect    total 
  3.6185   0.3909   2.3063   1.4146   3.7209 

  • a = 3.6 more new artists with Smart Mix
  • b = 0.39 hours per new artist, holding Smart Mix constant
  • c′ = 2.31 hours direct — down from the total 3.72

Indirect effect a × b = 1.41 hours = 38% of the effect runs through discovery. Discovery is an important mechanism — not the only one.

Uncertainty of the indirect effect: bootstrap

set.seed(1)
boot_indirect <- replicate(2000, {
  d_boot <- wave2[sample(nrow(wave2), replace = TRUE), ]
  coef(lm(new_artists ~ smart_mix + prior_hours + premium, data = d_boot))["smart_mix"] *
    coef(lm(hours ~ smart_mix + new_artists + prior_hours + premium + tenure, data = d_boot))["new_artists"]
})
quantile(boot_indirect, c(0.025, 0.975))
  2.5%  97.5% 
0.9861 1.8632 

A product of two estimates is not normally distributed → no textbook standard error → bootstrap (Chapter 3): resample users, re-estimate both regressions, look at the distribution of a × b. Report total, direct, indirect with uncertainty, plus the share mediated.

The same in one call: the mediation package

library(mediation)                       # install.packages("mediation")
med <- mediate(model_m, model_y, treat = "smart_mix", mediator = "new_artists", boot = TRUE, sims = 1000)
summary(med)
Causal Mediation Analysis
Nonparametric Bootstrap Confidence Intervals with the Percentile Method

               Estimate 95% CI Lower 95% CI Upper p-value
ACME              1.415        0.981        1.848  <2e-16 ***
ADE               2.306        1.628        3.001  <2e-16 ***
Total Effect      3.721        3.151        4.298  <2e-16 ***
Prop. Mediated    0.380        0.261        0.516  <2e-16 ***

Sample Size Used: 1200       Simulations: 1000

ACME = indirect effect (a × b), ADE = direct effect c′, Prop. Mediated = share. Same numbers as our three regressions + bootstrap — the package automates exactly that (and also handles logistic outcomes). Either is fine for your project; the manual version shows what is being computed.

The catch: nobody randomized the mediator

Live demo: book §6.7 — mediation widget, switch on the unobserved confounder of M and Y

https://wu-rds.github.io/MA2026/06-mechanisms.html#sec-mech-mediation

Randomization identifies the total effect. The split needs one more assumption: no unobserved confounder of mediator and outcome (curious users discover more and listen more). Untestable — and the same problem as Chapter 5, one step down the chain.

What helps: measure likely confounders of M before the manipulation; manipulate the mediator (Smart Mix with vs. without discovery).

6.8 Your group project

One moderator and one mediator — with 120 respondents

Your moderator (at least one)

  • With an expected direction stated in advance: “the label works better for environmentally concerned respondents”
  • Measured before the manipulation (so it cannot be affected by it)
  • outcome ~ condition * moderator; report the effect at meaningful values
  • 60 per condition → only large interactions detectable; “no evidence that the effect differs” is a legitimate result

Your mediator (at least one)

  • The mechanism you believe in: perceived quality, trust, authenticity, attention …
  • Measured after the manipulation, before the outcome
  • Three regressions + bootstrap (or mediate()); report total, direct, indirect, share
  • State the assumption — and measure plausible confounders of mediator and outcome before the manipulation

Plan both in the questionnaire now (next session: survey design). In the report: what was planned, what was exploratory.

Coding block: two cases (40 min)

Case 1: the climate-neutral shipping label — green_label.csv: 1,000 customers of an online shop, randomized label at checkout (label 1/0), order value in euros, segment (new/returning), sustainability score 1–7 (eco_score, from an earlier survey).

  1. Mean order value by label × segment, plotted: parallel or not?
  2. order_value ~ label * segment: the label effect for each segment from the coefficients and with emtrends(); do the effects differ?
  3. order_value ~ label * eco_score: the effect at a score of 2, 4, 6; what does the coefficient of label alone mean?

Laptops open — alone or with your neighbor. Section “Coding block” in 06-mechanisms.R.

Case 2: the story behind the coffee — coffee_story.csv: a survey experiment, 320 respondents, randomized product description (version: Facts / Story), perceived authenticity (1–7, after), wtp for a 250 g pack (euros), involvement (1–7, before).

  1. Total effect of the story on willingness to pay, with CI
  2. The three paths a, b, c′ (with involvement as control); indirect effect and share mediated
  3. Bootstrap CI of the indirect effect (or mediate())
  4. Which assumption does the split rely on — and what would you add to the questionnaire?

At the end: one table presents case 1, another case 2 — Menti first: your label effect for new customers (case 1) and your share mediated (case 2).

Learning check

  1. smart_mix = 5.0, smart_mix:premium = −3.1. Effect for free users? For Premium? What does the interaction’s p-value test?
  2. 2 × 2: intercept 40, framingYearly −5, trialYes +8, framingYearly:trialYes +6. The four cell means? Where does the trial help more?
  3. A loyalty program’s effect on annual spending is estimated with “store visits” as a control — visits are a consequence of the program. What does the program’s coefficient estimate now, and what if you want the total effect?
  4. 25 segments tested, “works particularly well for returning customers on tablets” (p = .02). Problem — and what next?

Next session

Module 8 · Survey design — from research question to questionnaire

  • Measuring constructs: items, scales, reliability
  • Embedding your experiment in a Qualtrics survey — including your moderator (before) and mediator (after)
  • Questionnaire structure, pretesting, data collection

Bring your group’s research question and planned manipulation — we will work on your questionnaires in class.