Each table lists tasks in the order a media mix or attribution
project meets them, with the function that does each one and, where it
is the part that does the job, the argument. mm_weekly, a
simulated weekly media panel, and mm_events, a simulated
event log, are there to try each one on.
Check the data
| Task | Function |
|---|---|
| Find channels that move together |
diagnose_media(), its collinearity
table |
| Measure that collinearity after adstock, as the model sees it |
diagnose_media() with decay
|
| Find channels that barely vary or are mostly dark |
diagnose_media(), its variation table |
| Check spend against impressions for join errors |
diagnose_media() with spend and
impressions, its cpm table |
| Find missing, repeated or out-of-order weeks |
diagnose_media() with date, its
dates table |
| Check each geography on its own |
diagnose_media() with by
|
| Plot the checks |
plot() on the result; see
plot.mm_diagnosis()
|
Transform media
Carryover
| Task | Function |
|---|---|
| Spread spend forward with a constant decay | adstock_geometric() |
| Let the effect peak a few periods after the spend |
adstock_delayed() with peak, or
adstock_weibull() with type = "pdf"
|
| Use a Weibull kernel | adstock_weibull() |
| Apply a kernel you already have as weights |
adstock_filter() with weights
|
| Look at a kernel’s weights |
adstock_weights(),
adstock_weights_weibull(),
adstock_weights_delayed()
|
| Turn a half-life into a decay, and back |
decay_from_half_life(), half_life();
period converts between daily and weekly data |
| Decide how many lags a kernel needs | effective_window() |
| Keep the coefficient per unit of spend, or match Robyn’s scale |
normalise = TRUE, the default, or
normalise = FALSE as in Robyn |
| Adstock several geographies at once |
by in the adstock functions and in
media_transform()
|
| Treat missing spend as no spend |
na_action = "zero" in the adstock functions, the
default in step_adstock()
|
| Continue a series from where an earlier chunk stopped |
adstock_state(), passed as state
|
| Remove the low first weeks of a long carryover |
adstock_steady_state(), passed as
state
|
Saturation
| Task | Function |
|---|---|
| Saturate with a Hill curve, concave or S-shaped |
saturate_hill() with half_max and
shape
|
| Saturate with another curve |
saturate_exponential(),
saturate_michaelis_menten(), saturate_power();
saturate() picks one by type
|
Both, channel by channel
| Task | Function |
|---|---|
| Adstock then saturate one channel | media_transform() |
| Transform every channel of a data frame, each with its own parameters |
transform_plan() with spec
|
| Reproduce a Robyn model’s transforms |
from_robyn(), then media_transform()
|
| Transform inside a tidymodels recipe |
step_adstock(), then
step_saturation()
|
| Give each channel its own decay in a recipe |
step_adstock_channels(), with
decay = c(tv = 0.85, search = 0.15)
|
| Keep the raw spend beside the adstocked column in a recipe |
step_adstock() with
keep_original_cols = TRUE
|
| Start each series in a recipe at its steady state |
step_adstock() with start = "steady"
|
Choose carryover
| Task | Function |
|---|---|
| Choose one channel’s decay against the KPI | tune_carryover() |
| Choose every channel’s decay inside one model | tune_carryover_joint() |
| Hold trend, price and seasonality fixed while choosing |
controls in either tuner |
| Tune a panel of geographies |
by and index in either tuner |
| Remove the start-up bias of long carryover while tuning | warm_start = TRUE |
| Take the shortest carryover the data cannot rule out | the best_1se element of the result |
| See how sharply the data identifies each decay |
plot() on the result; see
plot.mm_carryover()
|
| Score candidates with your own model or metric |
fit_fn, predict_fn and
metric_fn; rmse() is the default metric and
mae() the alternative supplied |
| Keep the out-of-sample forecasts | save_pred = TRUE |
| Tune carryover, saturation and a model penalty together |
step_adstock() or step_adstock_channels()
with step_saturation(), marked with tune() and
searched by the tune package |
| Set the ranges a tidymodels search covers |
carryover_decay(), carryover_max_lag(),
carryover_shape(), carryover_scale(),
carryover_peak(), saturation_half_max(),
saturation_shape()
|
Add controls such as seasonality
| Task | Function |
|---|---|
| Model a smooth yearly cycle |
fourier_terms() with harmonics
|
| Flag the weeks that contain a holiday |
holiday_flags(), with align = "end" for
week-ending dates |
| Use them while choosing carryover |
controls in tune_carryover() or
tune_carryover_joint()
|
For a trend, a column counting the weeks is enough.
Fit a model
mediamix has no model of its own. The transformed columns are
ordinary numeric vectors, so lm(),
glmnet::glmnet(), a brms or Stan model, or a tidymodels
workflow can take them. fit_ols(), a one-regressor
least-squares fit, is there as tune_carryover()’s default
model.
Report contributions and returns
| Task | Function |
|---|---|
| Split the model’s predictions into channel contributions and a baseline | contributions() |
| Decompose a holdout or reporting period |
contributions() with newdata
|
| Decompose each geography |
contributions() with by
|
| Plot contributions over time, or in total |
plot() on the result, with type; see
plot.mm_contributions()
|
| Average return per channel | roi() |
| Average return per geography or per year |
roi() with by, or with index
and periods
|
| Return on the next unit of spend | marginal_roi() |
| Marginal return for every channel in one call |
marginal_roi() on a data frame of spend, with
spec
|
| Count the carryover that falls after the last week |
marginal_roi() with extend
|
| Raise spend only in a planning window |
marginal_roi() with rows
|
| Slope of a saturation curve at one level | mroi() |
| A channel’s response across spend levels |
response_curve(); plot.mm_response_curve()
shades the levels outside observed
|
| Spend that reaches a target response | spend_for() |
Measure uncertainty
| Task | Function |
|---|---|
| Intervals on coefficients, contributions or returns | block_bootstrap() |
| Choose how many weeks a resampled block holds |
block_length in block_bootstrap(), at
least the longest effective_window()
|
| Resample a panel so shocks shared by every geography stay together |
by in block_bootstrap(), with
panel = "shared", the default |
| Spread the replicates over several cores |
cores in block_bootstrap()
|
| Plot the intervals |
plot() on the result, with reference; see
plot.mm_bootstrap()
|
| Intervals on attribution shares |
attribute() with times
|
Plan budgets
| Task | Function |
|---|---|
| Predict each channel’s response to a spend plan | simulate_plan() |
| Compare one plan with another |
simulate_plan() with baseline
|
| Move spend between two channels, keeping each one’s flighting | reallocate() |
| Set up a move in one region only, as a geo test |
reallocate() with by, and
amount named by region |
| Split a total budget to maximise the predicted response |
allocate_budget() with total
|
| Keep each channel’s spend within limits |
allocate_budget() with lower and
upper
|
| Plot an allocation |
plot() on the result; see
plot.mm_allocation()
|
Build journeys
| Task | Function |
|---|---|
| Turn a raw event log into customer journeys | build_paths() |
| Start a new journey after each conversion or a quiet spell |
build_paths() with split_on and
gap
|
| Drop touches older than a window |
build_paths() with lookback
|
| Choose that window from your own data | conversion_lag() |
| Keep, drop or relabel direct and missing channels |
build_paths() with direct
|
| Carry campaign, device or cost columns into the journeys |
build_paths() with keep
|
| Stop counting a checkout page as a touch |
build_paths() with
conversion_touch = "drop"
|
| Read text timestamps in a format other than ISO 8601 |
build_paths() with timestamp_format
|
| Count events in, journeys out and conversions lost | path_summary() |
| Describe the journeys |
path_lengths(), channel_positions(),
assisted_conversions(), top_paths(); all of
them at once with path_diagnostics()
|
| Combine journeys built in separate batches | bind_paths() |
| Subset journeys and keep their touch ranks valid |
[ or dplyr verbs on the journey table; see [.mm_paths
|
Credit conversions
| Task | Function |
|---|---|
| Credit by a fixed rule |
credit_first(), credit_last(),
credit_linear(), credit_position(),
credit_time_decay()
|
| Credit by a rule of your own |
credit_custom() with fn
|
| Credit by Markov removal effects | markov_removal() |
| Inspect the fitted Markov chain | the transitions and p_conversion
attributes of the result of markov_removal()
|
| Run several rules side by side |
attribute() with rules
|
| See how much each channel’s share depends on the rule | attribution_spread() |
| Credit each segment, such as device, separately |
attribute() with by
|
| Plot shares across rules |
plot() on the result; see
plot.mm_attribution() and
plot.mm_attribution_intervals()
|
Export
| Task | Function |
|---|---|
| Hand journeys to ChannelAttribution for higher-order chains |
as_channel_paths(), with the same sep on
both sides |
| Get a tuner, diagnosis, bootstrap or allocation result as a plain table |
as.data.frame() or tidy() on it |
| Read a recipe step’s fitted state and parameters |
tidy() on the prepared recipe |
| Match your own charts to the package’s | mm_palette() |