Marketing Analytics

Chapter 5 · Learning from Observational Data

Nils Wlömert

Vienna University of Economics and Business (WU)

November 2026

Part 1 · Observational data I

Before we start

Paper quiz on Chapter 4 (10 min)

  • Individual, closed book, counts toward participation
  • Afterwards: a few leftovers from Chapter 4 and a look at the quiz questions

Assignment 2 is running: deadline Group A Sun, Nov 8 · Group B Wed, Nov 11; 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: correlation and the regression line → reading a regression → adjustment and exogeneity → categorical predictors → prediction vs. explanation → one coding block with two cases at the end.

Today’s session

Observational data I (today)

5.1 Smart Mix without randomization
5.2 Correlation, the line, and least squares
5.3 Reading a regression
5.4 Adjusting for confounders — and exogeneity
5.5 Categorical predictors
5.6 Prediction vs. explanation

Observational data II (next session)

5.7 Functional form and elasticities
5.8 Logistic regression
5.9 Diagnostics that change decisions
5.10 Difference-in-differences

Driving question: What if we cannot randomize?

5.1 Smart Mix without randomization

A different history

  • Chapter 4: A/B test, 400 users → +3.2 hours
  • Now: no experiment. Smart Mix launched as an opt-in feature
  • Four weeks later: data of 2,000 users, 653 adopters

The dashboard says: adopters listen 9.3 hours more — three times the experimental effect. Would you report this number to management?

Adopters were different before Smart Mix existed

Same costume, new villain: music enthusiasm drives adoption and listening. Without a coin flip, we have one tool left: adjustment.

5.2 From correlation to a line

The correlation coefficient

r = \frac{\sum_i (x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_i (x_i - \bar{x})^2}\sqrt{\sum_i (y_i - \bar{y})^2}}

  • Standardized covariance → always between −1 and +1, no units
  • Sign = direction · size = how tightly the cloud hugs a straight line
  • Rules of thumb: 0.1 small · 0.3 medium · 0.5 large
  • Smart Mix: cor(prior_hours, hours) = 0.64

Two caveats: r measures linear association only (a U-shape can have r ≈ 0) — and it is symmetric: nothing about which variable causes which.

Correlation vs. regression

Correlation Regression
Estimated coefficient r, bounded between −1 and +1, no units β₁, a priori not bounded, in units of y per unit of x
Interpretation Linear association between two variables; bidirectional (r of x and y = r of y and x) (Linear) relation of one or more predictors to an outcome; directional (x explains y)
Role of theory Neither required nor testable Required (which variable is the outcome, which predictors belong in the model) — and testable

Correlation: that and how tightly two variables move together. Regression: how much y changes with x — which presupposes a direction, and that is where theory and this chapter’s assumptions come in.

Two variables, one line

\text{hours}_i = \beta_0 + \beta_1 \, \text{prior hours}_i + \varepsilon_i

  • i = one user · \beta_0 intercept · \beta_1 slope · \varepsilon_i error term
  • Correlation: that they move together · regression: how much
coef(lm(hours ~ prior_hours, data = smartmix_obs))
(Intercept) prior_hours 
     6.7849      0.7291 

Each extra hour before the launch goes with 0.73 hours after it — goes with, not causes.

Which line? Least squares

  • Residual = observed − predicted (orange segments)
  • OLS = the line that minimizes the sum of squared residuals:

\min_{\hat{\beta}_0, \hat{\beta}_1} \sum_{i=1}^{n} \left( y_i - \hat{\beta}_0 - \hat{\beta}_1 x_i \right)^2

  • Squaring: big misses count a lot; above and below alike · lm() does exactly this

Live demo: fit the line yourself — course book, §5.2

https://wu-rds.github.io/MA2026/05-observational-data.html#sec-obs-line

5.3 Reading a regression

The full output

model_naive <- lm(hours ~ smart_mix, data = smartmix_obs)
summary(model_naive)

Call:
lm(formula = hours ~ smart_mix, data = smartmix_obs)

Residuals:
   Min     1Q Median     3Q    Max 
-20.88  -7.64  -2.06   4.76 101.22 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   17.541      0.300    58.5   <2e-16 ***
smart_mix      9.341      0.525    17.8   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 11 on 1998 degrees of freedom
Multiple R-squared:  0.137, Adjusted R-squared:  0.136 
F-statistic:  316 on 1 and 1998 DF,  p-value: <2e-16

Reading the coefficients

(Intercept) = 17.5: the predicted hours when all predictors are 0 — here the mean of the non-adopters.

smart_mix = 9.3: the change in hours for a one-unit increase in the predictor. For a 0/1 variable that is the step from 0 to 1: adopters − non-adopters.

Continuous predictor (previous section): prior_hours = 0.73 → one more hour before the launch goes with 0.73 more hours after it.

Several predictors (next section): every coefficient is read “holding the other variables constant”.

The general rule: a coefficient is the change in y when its predictor increases by one unit and nothing else changes. Whether that change is causal is the question of §5.4.

Line by line

Output Meaning
Estimate Intercept = mean of non-adopters (18.4); smart_mix = difference adopters − non-adopters (9.3)
Std. Error Uncertainty of each coefficient (Chapter 3)
t value, Pr(>|t|) t-test of each coefficient against zero (Chapter 4): signal / noise
Residual standard error Typical distance of a user from the line, in hours
Multiple R-squared Share of the variation in hours explained by the model (14%)
F-statistic The whole model against “no predictors”

With one 0/1 predictor, the regression is the comparison of two means — and its t-test is the two-sample t-test. confint(model_naive) gives the confidence intervals.

R²: the share of explained variation

  • Same idea as \eta^2 in the ANOVA: R^2 = SS_M / SS_T — the share of the variation in y that the line explains
  • Smart Mix dummy: 0.14 · prior listening: 0.41

R² says how well the line fits — nothing about whether the slope is causal, and a small R² does not make an effect unimportant (14% explained, but 9 hours).

5.4 Adjusting for confounders

Holding prior listening constant

model_prior <- lm(hours ~ smart_mix + prior_hours, data = smartmix_obs)
round(coef(summary(model_prior)), 3)
            Estimate Std. Error t value Pr(>|t|)
(Intercept)    6.451      0.412   15.65        0
smart_mix      4.901      0.443   11.07        0
prior_hours    0.662      0.020   33.17        0

The Smart Mix coefficient drops from 9.3 to 4.9: now the difference between adopters and non-adopters with the same prior listening. Part of the naive gap belonged to prior listening — and is now attributed to it.

More variables, same logic

model_full <- lm(hours ~ smart_mix + prior_hours + tenure + premium + device, data = smartmix_obs)
round(coef(summary(model_full)), 3)
              Estimate Std. Error t value Pr(>|t|)
(Intercept)      6.255      0.540  11.575    0.000
smart_mix        4.472      0.437  10.223    0.000
prior_hours      0.613      0.021  29.688    0.000
tenure           0.038      0.011   3.344    0.001
premium          2.924      0.426   6.869    0.000
deviceAndroid   -1.475      0.422  -3.493    0.000
deviceDesktop   -2.488      0.576  -4.320    0.000

Reading the table, one line each, “holding the other variables constant”: smart_mix 4.5 = adopters listen 4.5 h more than non-adopters with the same prior listening, tenure, plan and device · prior_hours 0.61 = one more hour before the launch goes with 0.61 h more after it · tenure 0.04 = each month of tenure, +0.04 h · premium 2.9 = Premium users listen 2.9 h more than free users · deviceAndroid / deviceDesktop = difference to iOS (the reference). Tenure, Premium and device change little for Smart Mix: ≈ 4.5 hours.

Naive, adjusted — and the truth

Adjustment removed ~75% of the bias — not all of it. We adjusted for a proxy of enthusiasm, not for enthusiasm. Regression removes exactly the confounding your variables capture.

Live demo: how good must a proxy be?

Course book, §5.4 — set the quality of the proxy and the strength of confounding.

https://wu-rds.github.io/MA2026/05-observational-data.html#sec-obs-adjust

With a 50% proxy, how much of the bias is left? And what happens at 0%?

Two warnings

Adjusting for the wrong variable makes it worse. A mediator lies on the causal path: if Smart Mix works by making users discover new artists, adjusting for new_artists blocks the indirect part and the coefficient shows only the direct part. Only confounders — determined before the treatment, affecting treatment and outcome — belong in the model.

“Enough” is untestable. The assumption of no unobserved confounders cannot be checked in the data. Report what you adjusted for — and what you plausibly could not.

Where the unobserved variable goes

The true model (price and sales; weather raises both):

\text{Sales}_i = \beta_0 + \beta_1 \, \text{Price}_i + \beta_2 \, \text{Weather}_i + \phi_i

Weather is not in the data — so we estimate:

\text{Sales}_i = \beta_0 + \beta_1 \, \text{Price}_i + \underbrace{\varepsilon_i}_{= \, \beta_2 \text{Weather}_i + \phi_i}

  • The omitted variable does not disappear — it moves into the error term
  • Weather also drives price → the error term is correlated with the regressor
  • OLS attributes the weather effect to price: \hat{\beta}_1 is biased, and more data do not help

Smart Mix: replace price by adoption, weather by enthusiasm. Enthusiasm is in \varepsilon_i and drives adoption → 9.3 h instead of 3.

Variation has two components

The observed price variation mixes exogenous variation (price moves for its own reasons → the causal effect, downward) with endogenous variation (weather moves price and demand → upward). OLS on the mix gives a slope that is neither. Adjustment and experiments are ways to isolate the exogenous part.

Exogeneity

y_i = \beta_0 + \beta_1 x_i + \varepsilon_i

  • The most important assumption when the goal is the effect of x on y
  • The error term must not be related to x: \text{Cov}(x_i, \varepsilon_i) = 0 — x is exogenous
  • If \text{Cov}(x_i, \varepsilon_i) \neq 0: x is endogenous, the estimate is biased (and stays biased with more data), and \beta_1 cannot be read as causal
  • Randomization guarantees exogeneity. Opt-in violates it. Each adjustment variable moves a piece of \varepsilon_i into the model: prior_hours took most of the enthusiasm out (9.3 → 4.5); what is left still correlates with adoption (4.5 > 3)

Exogeneity cannot be tested. The residuals of a fitted regression are uncorrelated with the predictors by construction — the data always “look” exogenous. The argument has to come from outside: theory, and how the data came to be (who chose the treatment, and why).

Your turn (5 min)

Add age to the full model. Does the Smart Mix coefficient change? Why (not)?

model_age <- lm(hours ~ smart_mix + prior_hours + tenure + premium + device + age,
                data = smartmix_obs)
round(coef(summary(model_age)), 3)

Then: which variable in the data set should you never adjust for when estimating the effect of Smart Mix on listening — and why?

5.5 Categorical predictors

Dummies and the reference category

coef(model_full)[c("premium", "deviceAndroid", "deviceDesktop")]
      premium deviceAndroid deviceDesktop 
        2.924        -1.475        -2.488 
  • 0/1 variable (premium): coefficient = difference between the two groups, other variables held constant
  • Several categories (device): R picks a reference (first level: iOS) and creates one dummy per other category
  • Each dummy = difference to the reference

Android users: 1.5 hours less than iOS users; Desktop: 2.5 hours less — holding everything else constant. p-values compare each category with the reference; “does device matter at all?” → anova(model_without, model_full) (the ANOVA of Chapter 4).

5.6 Prediction vs. explanation

Predicting listening time for new users

set.seed(42)
train_ids <- sample(nrow(smartmix_obs), 1500)
train <- smartmix_obs[train_ids, ]
test  <- smartmix_obs[-train_ids, ]
model_pred <- lm(hours ~ prior_hours + tenure + premium +
                   device + smart_mix, data = train)
test$predicted <- predict(model_pred, newdata = test)

summary(model_pred)$r.squared        # in-sample R² (training data)
[1] 0.4817
cor(test$predicted, test$hours)^2    # out-of-sample R² (test data)
[1] 0.4235

Fit on the training users, judge on the test users. The in-sample R² flatters the model (it was fitted to these very users); the out-of-sample R² — the squared correlation between predicted and actual values in the test set — is the honest number. Close here (0.48 vs. 0.42): few predictors, many users. With many predictors and small samples, the gap is overfitting made visible.

How far off is a prediction? The RMSE

\text{RMSE} = \sqrt{\frac{1}{n} \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2}

  1. Each test user’s prediction error y_i - \hat{y}_i
  2. Square it: over- and under-predictions do not cancel, big misses count more
  3. Average the squares
  4. Root: back to the original unit (hours)
sqrt(mean((test$hours - test$predicted)^2))
[1] 9.425

The RMSE is the standard deviation of the prediction errors: a typical prediction for a new user misses by about 9.5 hours. For a decision maker, that is more useful than a share of explained variation — it is in the unit of the decision.

Two questions, two rules

Explanation (causal question): include confounders, exclude mediators, state what is unobserved. The coefficient matters; R² is secondary.

Prediction: include whatever predicts; judge by out-of-sample errors. Coefficients are not interpreted; the predictions matter.

A model can be a good predictor and a bad explainer at the same time. Where in your company would each mistake — reading causal effects off a prediction model, or judging a causal model by its R² — cost money?

Coding block: two cases (40 min)

Case 1: podcast promotion — podcast_promo.csv, 400 episodes: promotion spend, host followers, downloads.

  1. Scatter plot of downloads against spend; the correlation; one sentence
  2. lm() + summary(): interpret the slope; read off R²
  3. Is the slope causal? What would you need to argue?

Laptops open — alone or with your neighbor. Section “Coding block” in 05-observational-data.R.

Case 2: a loyalty program — loyalty_program.csv, 1,500 customers, membership is opt-in.

  1. Naive: spending ~ member — interpret; why not causal?
  2. Adjust for spend_prev, tenure, device: how does the coefficient change, what does it mean now? With 95% CI
  3. Interpret the coefficient of device
  4. Is membership exogenous after adjustment? Argue from the data-generating process

At the end: one table presents case 1, another table case 2 — Menti first: enter your slope (case 1) and your adjusted coefficient (case 2).

Learning check (Part I)

  1. Slope of hours on prior hours = 0.73. Interpret — and why is it not causal?
  2. Adding a variable can increase, decrease, or leave the Smart Mix coefficient unchanged. When does each happen?
  3. planFamily = 4.2 with reference “Free”. Interpret. How do you test whether the plan matters at all?
  4. R² = 0.71 for predicting next month’s spending with 25 predictors on 300 customers. What do you ask?

Next session

Observational data II — beyond the straight line, and a quasi-experiment

  • Functional form: when a line is wrong — elasticities
  • Yes/no outcomes: logistic regression
  • The three diagnostics that change decisions
  • Difference-in-differences with real playlist data

Before next session: work through §5.1–5.6 on the course site. Debrief of Assignment 2 at the start of the session.

Part 2 · Observational data II

Before we start

Debrief A2 + quiz Chapter 5, Part I (15 min, one sheet)

  • Page 1: debrief of Assignment 2 (3 assignment points)
  • Page 2: quiz on Chapter 5, §5.1–5.6 (participation)
  • Closed book, no laptop

Assignment 3 is handed out today (end of session).

Devices only when we code — as last time

Today: functional form and elasticities → logistic regression → diagnostics → difference-in-differences → one coding block with two cases → A3.

5.7 Functional form: when the line is wrong

Two assumptions of the linear model

The case. A label runs 500 promotion campaigns for new releases; for each we know the spend (euros), the artist’s followers, the playlist placements, the genre — and the streams in the first four weeks. The chart: streams against spend, one dot per campaign, with the linear regression line.

y_i = \beta_0 + \beta_1 x_{1i} + \beta_2 x_{2i} + \dots + \varepsilon_i

Linearity: a one-unit change in x has the same effect at every level of x — constant marginal returns: 10 → 11 € adds as many streams as 100,000 → 100,001 €. Additivity: the effect of one predictor does not depend on the others.

Relaxed where: linearity → the multiplicative (log-log) model (this section) · additivity → the multiplicative model and interactions (Chapter 6) · detecting a wrong form → the residual plot (§5.9)

Two models for the same data

\text{streams}_i = \beta_0 + \beta_1 \, \text{spend}_i + \varepsilon_i

\text{streams}_i = \beta_0 \cdot \text{spend}_i^{\,\beta_1} \cdot \varepsilon_i

Left: the linear model — a straight line. Right: the multiplicative model — spend enters as a power, and the fitted curve bends: the first euros buy many streams, later euros fewer. Same data, same question, a different assumption about how spend works.

Marginal returns: what one more step buys

  • Constant marginal returns: every extra €6,000 buys the same +34K streams
  • Additive: spend adds a fixed number of streams on top of everything else
  • Reading \beta_1: +1 unit of x → +\beta_1 units of y (5.6 streams per euro)
  • Decreasing marginal returns: +€6,000 buys +45K streams at a small budget, +12K at a large one
  • Multiplicative: spend scales the streams — a percentage of what is already there
  • Reading \beta_1: +1% of x → +\beta_1% of y (0.38% per 1% spend: the elasticity)

Estimating the multiplicative model: take logs

Multiplicative: each predictor scales the outcome

\text{streams}_i = e^{\beta_0} \cdot \text{spend}_i^{\,\beta_1} \cdot \text{followers}_i^{\,\beta_2} \cdot e^{\varepsilon_i}

Take logs on both sides → additive again, a job for lm():

\log(\text{streams}_i) = \beta_0 + \beta_1 \log(\text{spend}_i) + \beta_2 \log(\text{followers}_i) + \varepsilon_i

Three log rules do the work:

  • \log(a \cdot b) = \log a + \log b — a product becomes a sum
  • \log(a^b) = b \log a — a power becomes a factor
  • \log(e^x) = x

Additive model: each euro adds \beta_1 streams, always.
Multiplicative model: each euro adds a percentage of the current streams — diminishing returns built in; and the effect of spend is scaled by the followers.

The same curve on log-scaled axes

\text{streams}_i = \beta_0 \cdot \text{spend}_i^{\,\beta_1} \cdot \varepsilon_i

\log(\text{streams}_i) = \log \beta_0 + \beta_1 \log(\text{spend}_i) + \log \varepsilon_i

Left: the multiplicative model on the original scale — a curve with decreasing marginal returns. Right: the same data with both axes log-scaled (each gridline is ×10 the previous one; the units stay euros and streams): the curve becomes a straight line, and its slope is \beta_1. That is the model lm(log(streams) ~ log(spend)) estimates.

Both models in R: the full output

\text{streams}_i = \beta_0 + \beta_1 \, \text{spend}_i + \varepsilon_i

model_lin_simple <- lm(streams ~ spend, data = campaigns)
summary(model_lin_simple)

Call:
lm(formula = streams ~ spend, data = campaigns)

Residuals:
    Min      1Q  Median      3Q     Max 
-204459  -67186  -34157   27654  694356 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 92600.025   6782.260   13.65   <2e-16 ***
spend           5.589      0.781    7.16    3e-12 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 114000 on 498 degrees of freedom
Multiple R-squared:  0.0932,    Adjusted R-squared:  0.0914 
F-statistic: 51.2 on 1 and 498 DF,  p-value: 3.01e-12

\log(\text{streams}_i) = \beta_0 + \beta_1 \log(\text{spend}_i) + \varepsilon_i

model_loglog_simple <- lm(log(streams) ~ log(spend), data = campaigns)
summary(model_loglog_simple)

Call:
lm(formula = log(streams) ~ log(spend), data = campaigns)

Residuals:
    Min      1Q  Median      3Q     Max 
-2.2804 -0.5076  0.0152  0.5652  2.3720 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   8.2098     0.3094    26.5   <2e-16 ***
log(spend)    0.3841     0.0375    10.2   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.802 on 498 degrees of freedom
Multiple R-squared:  0.174, Adjusted R-squared:  0.173 
F-statistic:  105 on 1 and 498 DF,  p-value: <2e-16

Reading: one more euro → +5.6 streams, at every budget; intercept 92,600 = predicted streams at zero spend.

Reading: +1% spend → +0.38% streams (elasticity), at every budget. R² 0.17 vs. 0.09: the log-log model explains more of the variation — a first hint that its shape fits the data better (the residual plots in §5.9 confirm it).

Why the log transformation straightens the curve

Multiplicative model: equal percentage steps in x → equal percentage steps in y (each doubling of spend adds the same percentage of streams, but ever fewer streams). The logarithm turns percentages into distances — a doubling is always \log 2 — so the curve becomes a line with slope = elasticity.

Elasticity: linear vs. log-log model

Elasticity \eta_x = (\Delta y / y) / (\Delta x / x): the % change in y per % change in x

  • Linear: \eta_x = \beta_1 \, x / y rises with x — advertising gets relatively more effective the more you spend: implausible
  • Multiplicative: \eta_x = \beta_1 constant; the marginal returns fall

Additive in logs = multiplicative in levels: the same percentage effect for every artist; the number of streams it buys scales with the follower base.

After Hanssens, Parsons & Schultz (2001), Market Response Models.

What the elasticity says about the shape

  • \beta_1 < 0: falls, flattening out — price
  • 0 < \beta_1 < 1: diminishing returns — advertising, promotion; most marketing elasticities (< 0.5)
  • \beta_1 = 1: proportional — a line through the origin; the one linear case
  • \beta_1 > 1: increasing returns — each extra euro buys more than the last. Rare: network effects (a messaging app or marketplace gains value with every user), or a promotion that crosses a threshold and spreads by word of mouth

Not defined at x = 0; no minimum level of y. Optimum: zero or infinity in the linear model, finite in the multiplicative one.

The full log-log model: an elasticity per input

model_loglog <- lm(log(streams) ~ log(spend) + log(followers) + placements + genre, data = campaigns)
summary(model_loglog)

Call:
lm(formula = log(streams) ~ log(spend) + log(followers) + placements + 
    genre, data = campaigns)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.5962 -0.2684  0.0284  0.3030  1.4799 

Coefficients:
                   Estimate Std. Error t value Pr(>|t|)    
(Intercept)          2.8815     0.2346   12.28  < 2e-16 ***
log(spend)           0.3310     0.0207   16.00  < 2e-16 ***
log(followers)       0.5071     0.0157   32.28  < 2e-16 ***
placements           0.1203     0.0119   10.07  < 2e-16 ***
genreHipHop/Rap      0.1994     0.0476    4.19 0.000033 ***
genreRock           -0.2555     0.0599   -4.27 0.000023 ***
genreElectro/Dance   0.1026     0.0594    1.73    0.085 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.44 on 493 degrees of freedom
Multiple R-squared:  0.754, Adjusted R-squared:  0.751 
F-statistic:  251 on 6 and 493 DF,  p-value: <2e-16

log(spend) = 0.33: +1% spend → +0.33% streams, at every budget. Elasticities have no units and are comparable: followers (0.51) matter more than the budget. placements = 0.12: a semi-elasticity, +12% per placement.

A marketing mix model in miniature: an elasticity per channel → shift budget to where a euro buys the largest percentage gain. Real MMMs add carryover and saturation — and spend is endogenous, so companies calibrate them with experiments.

Four ways to combine levels and logs

Model Equation Reading \beta_1 Typical use
Level-level y = \beta_0 + \beta_1 x +1 unit x → \beta_1 units of y Constant effects; dummies
Log-level \log y = \beta_0 + \beta_1 x +1 unit x → ≈ 100\beta_1% of y (exact: 100(e^{\beta_1}-1)%): semi-elasticity A placement adds 12%
Level-log y = \beta_0 + \beta_1 \log x +1% x → ≈ \beta_1/100 units of y Diminishing returns, outcome in units
Log-log \log y = \beta_0 + \beta_1 \log x +1% x → \beta_1% of y: elasticity Spend, price: the marketing default

The transformation decides the unit of the coefficient: units, percent, or percent per percent. In our model, log(spend) and log(followers) are elasticities; placements and the genre dummies are semi-elasticities (percent per unit).

Your turn (5 min)

From the log-log model:

  1. genreHipHop/Rap = 0.20. By what percentage do HipHop/Rap campaigns differ from Pop campaigns (the reference) — approximately and exactly?
  2. A marketing manager proposes to raise the promotion budget of every campaign by 10%. By what percentage would streams increase, according to the model? Is this a causal claim?

Live demo: linear or log-log?

Course book, §5.7 — move the true elasticity.

https://wu-rds.github.io/MA2026/05-observational-data.html#sec-obs-form

Elasticity < 1: diminishing returns, the line misses at both ends. = 1: proportional. > 1: increasing returns (rare — network effects).

5.8 Yes/no outcomes: logistic regression

The case: who upgrades to Premium?

Same data as before — the Smart Mix launch — a new question. Among the free users (1,239 of the 2,000), the service recorded whether a user upgraded to Premium within three months after the launch.

  • Outcome: upgraded — 1 if the user upgraded, 0 if not; 22% did
  • Question of the growth team: does listening time predict who upgrades — and how strongly?
  • The answer feeds a targeting decision: which free users should get the upgrade offer first?

A yes/no outcome. Everything so far modeled a number (hours, streams). Now the outcome is a probability — and a probability has to stay between 0 and 1.

What goes wrong if we just run lm(upgraded ~ hours)?

Why not a straight line?

  • Outcome: upgraded to Premium within 3 months — free users, 22% did
  • A line predicts probabilities below 0 and above 1 — and misses the shape
  • The share of upgrades rises slowly, then steeply, then flattens near 100%: an S-curve

We need a function that only takes values between 0 and 1.

The logistic function

P(y_i = 1) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_i)}}

  • \beta_0 + \beta_1 x_i is the familiar line — fed through a function that squeezes it into [0, 1]: line far below 0 → P \approx 0 · line = 0 → P = 0.5 · line far above 0 → P \approx 1
  • Derived from the log-odds: odds = P / (1 - P) (“1 to 4” = 0.25)

\log\left(\frac{P(y_i = 1)}{1 - P(y_i = 1)}\right) = \beta_0 + \beta_1 x_i

  • Exponentiate → the odds: \dfrac{P(y_i = 1)}{1 - P(y_i = 1)} = e^{\beta_0 + \beta_1 x_i}
free_users <- filter(smartmix_obs, premium == 0)
model_upgrade <- glm(upgraded ~ hours, family = binomial,
                     data = free_users)
round(coef(summary(model_upgrade)), 3)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   -4.517      0.244  -18.53        0
hours          0.163      0.011   15.05        0

glm() = generalized linear model: the same predictors, a different link to the outcome. Estimated by maximum likelihood, not least squares (no line, no residuals to square): the coefficients under which the observed 0/1 data are most likely.

Weak vs. strong effects: the slope

  • \beta_1 ≈ 0: almost flat — the predictor hardly discriminates between upgraders and non-upgraders
  • \beta_1 large: an almost vertical step — listening time nearly determines who upgrades
  • \beta_0 shifts the curve; midpoint (P = 0.5) at x = -\beta_0 / \beta_1 ≈ 28 hours

Sign = direction, size = how sharply the outcome responds — on the log-odds scale; “how much” in probabilities: next two slides.

Reading the coefficients: odds ratios

exp(coef(model_upgrade))
(Intercept)       hours 
    0.01093     1.17689 
exp(confint(model_upgrade))
               2.5 %  97.5 %
(Intercept) 0.006661 0.01734
hours       1.152949 1.20296
  • Coefficient 0.163 = change in the log-odds per hour — no intuition
  • e^{0.163} = 1.18: each hour multiplies the odds of an upgrade by 1.18 (+18%) — the same factor everywhere
  • Read sign and significance directly from the output

Odds ratio ≠ probability ratio. “Odds +18%” is not “18% more likely” — unless the event is rare. For managers, translate into probabilities.

Reading the coefficients: probabilities at x and x + 1

predict(model_upgrade, type = "response",
        newdata = data.frame(hours = c(10, 11, 20, 21, 30, 31, 40, 41)))
      1       2       3       4       5       6       7       8 
0.05275 0.06151 0.22111 0.25043 0.59135 0.63005 0.88062 0.89671 
  • 10 → 11 hours: +0.9 points · 20 → 21: +2.9 · 30 → 31: +3.9 · 40 → 41: +1.6
  • Same coefficient, same odds ratio — a different change in probability, largest around 50%

Report effects as predicted probabilities at chosen values (10 vs. 30 hours: 5% vs. 59%) or as the average change across all users — “the effect of one more hour” has no single answer in percentage points.

A second case: who cancels?

Churn. For all 2,000 users, the data record whether the user cancelled the service within three months after the launch: churn = 1 (17% did), 0 otherwise.

  • Question of the retention team: which users are at risk — and does Premium status protect against churn, once listening and tenure are taken into account?
  • Candidates: hours, premium, tenure, smart_mix — the same predictors as in the adjustment models, now for a yes/no outcome
  • The answer feeds a retention decision: whom to contact before they leave

Logistic regression with several predictors: the same logic as multiple regression — each coefficient holds the others constant — but on the log-odds scale.

Several predictors: churn

model_churn <- glm(churn ~ hours + premium + tenure + smart_mix, family = binomial, data = smartmix_obs)
round(coef(summary(model_churn)), 3)
            Estimate Std. Error z value Pr(>|z|)
(Intercept)    0.277      0.161   1.717    0.086
hours         -0.061      0.009  -7.130    0.000
premium       -0.533      0.153  -3.489    0.000
tenure        -0.020      0.004  -5.452    0.000
smart_mix     -0.256      0.162  -1.579    0.114
p_free    <- predict(model_churn, newdata = mutate(smartmix_obs, premium = 0), type = "response")
p_premium <- predict(model_churn, newdata = mutate(smartmix_obs, premium = 1), type = "response")
mean(p_premium - p_free)
[1] -0.06477

Same logic as multiple regression: each coefficient holds the others constant. Premium subscribers: about 9 percentage points less likely to churn than otherwise identical free users. Causal? Exogeneity, again.

5.9 The diagnostics that change decisions

Three checks worth doing every time

1. Is the line the right shape? Curved residuals → change the functional form (log) or add a predictor.

2. Does one observation drive the result? plot(model, which = 5); refit without it — if the conclusion changes, say so.

3. Is the uncertainty right? A funnel (test: bptest(model)) → robust standard errors: coeftest(model, vcov = vcovHC(model)).

5.10 A quasi-experiment: difference-in-differences

The case: what is a playlist listing worth?

Real data from a WU research project. Labels pay a lot of attention to editorial playlists: being listed on a major playlist is supposed to boost a song’s streams. But by how much?

  • 290 songs, weekly streams over 21 weeks (January to June 2018)
  • On March 19, 2018, 53 of them were added to a major playlist (the treated songs); the other 237 were not (the control songs)
  • Question: how much did the listing increase the treated songs’ streams?

No randomization: the curators chose the songs — and they pick songs that are already doing well. A before/after comparison of the treated songs alone would mix the listing effect with the general trend; a treated/control comparison would mix it with the curators’ selection.

What do we need to isolate the effect of the listing?

Playlist listings as a natural experiment

  • Real data: 290 songs × 21 weeks
  • March 19, 2018: 53 songs added to a major playlist; 237 control songs
  • Treated songs start higher → levels not comparable
  • Before the listing: both groups move in parallel
  • At the listing: the treated group jumps

Data: WU-RDS research project (github.com/WU-RDS/did).

Two differences, one estimate

\text{DiD} = (\bar{y}_{T,\text{after}} - \bar{y}_{T,\text{before}}) - (\bar{y}_{C,\text{after}} - \bar{y}_{C,\text{before}})

(10.09 − 9.85) − (9.72 − 9.76) = 0.28 log points

The control group’s change estimates what would have happened to the treated songs without the listing — the counterfactual (dotted).

The DiD regression: the model

\log(\text{streams}_{it}) = \beta_0 + \beta_1 \, \text{treated}_i + \beta_2 \, \text{post}_t + \beta_3 \, (\text{treated}_i \times \text{post}_t) + \varepsilon_{it}

i = song, t = week. What the model predicts for the four cells:

Before (post = 0) After (post = 1) After − before
Control (treated = 0) \beta_0 \beta_0 + \beta_2 \beta_2 — the common time trend
Treated (treated = 1) \beta_0 + \beta_1 \beta_0 + \beta_1 + \beta_2 + \beta_3 \beta_2 + \beta_3
Treated − control \beta_1 — the level difference \beta_1 + \beta_3 \beta_3 — the DiD effect

\beta_3 is the difference of the two differences: the change of the treated songs minus the change of the control songs. In R, treated * post expands to the three terms.

The DiD regression: the estimate

did_data <- playlist |>
  filter(week != as.Date("2018-03-19")) |>          # drop the listing week
  mutate(log_streams = log(streams + 1))
model_did <- lm(log_streams ~ treated * post, data = did_data)
round(coef(summary(model_did)), 3)
             Estimate Std. Error t value Pr(>|t|)
(Intercept)     9.762      0.018 545.865    0.000
treated         0.091      0.042   2.182    0.029
post           -0.046      0.025  -1.803    0.071
treated:post    0.280      0.059   4.727    0.000
Coefficient Meaning
(Intercept) 9.76 Control, before: baseline
treated 0.09 Treated, before: the level difference
post −0.05 Control, after − before: the common time trend
treated:post 0.28 The extra change of the treated songs: the DiD effect → ≈ +32% streams

Your turn (5 min)

Add major_label as a control variable to the DiD regression:

summary(lm(log_streams ~ treated * post + major_label, data = did_data))

Does the effect change? Then: name one situation in which the parallel-trends assumption would fail for playlist listings.

Coding block: two cases (40 min)

Case 3: podcast promotion, revisited — podcast_promo.csv again.

  1. Scatter plot with both axes logged: what has changed?
  2. Log-log model on spend and host followers; interpret both elasticities: what does +10% spend do?
  3. Compare R² with the linear model; which model for the budget advice?

Laptops open — alone or with your neighbor. Section “Coding block” in 05-observational-data.R.

Case 4: winning back users — app_reinstall.csv, 1,200 users, randomized discount 0–60%, reinstalled (1/0), prior sessions.

  1. Share of reinstalls per discount level, plotted: describe the shape
  2. Logistic regression of reinstalled on discount and prior_use: sign and odds ratio of the discount
  3. Predicted probabilities for 10 prior sessions at 10, 11, 40, 41%: points per extra point of discount — why do the two answers differ?

At the end: one table presents case 3, another case 4 — Menti first: your spend elasticity (case 3) and your odds ratio (case 4).

What observational data can and cannot tell you

Two strategies, one honest report

  • Adjustment handles confounders you can measure — only as good as your proxies; “enough” is untestable
  • Difference-in-differences handles confounders constant over time — needs parallel trends, plausible but never proven
  • Prediction needs no causal assumptions — a good predictor is valuable even if no coefficient is an effect

Report effect + uncertainty + assumptions: “Adjusting for prior listening, tenure, Premium and device, adopters listen ≈ 4.5 hours more (95% CI 3.6–5.3), assuming no further differences affect listening — the experiment (3.2) suggests this is not fully met.”

Assignment 3: analyzing observational data

  • Your personal data (based on your student ID): an opt-in feature, promotion campaigns, and a small panel with a listing
  • Tasks: naive vs. adjusted · categorical predictor · elasticity · logistic regression · DiD
  • Deadline: Group A Sun, Nov 22 · Group B Wed, Nov 25
  • Debrief at the start of the following session

10 points: report 7 + debrief 3. State your assumptions — the best answers say what the data cannot show.

Learning check (Part II)

  1. Log-log coefficient of ad spend = 0.15. Interpret. The level model says 0.8 sales per euro — why might the two disagree about a large budget increase?
  2. Log-level model, dummy “promotion week” = 0.35. Percentage difference in sales — approximate and exact?
  3. Residual plot shows a funnel. Consequence for coefficients, for p-values — and the simplest fix?
  4. A DiD of a price promotion in treated stores: which assumption, and how can the pre-period help?

Next session

Module 6 · Mechanisms & heterogeneity — Why, and for whom, does it work?

  • Interaction effects: when the effect differs between groups (moderation)
  • Mediation: through which mechanism an effect works
  • In experiments and observational data — and in your group project