Skip to main content
Version: Latest (3.20.2)

uam

R​

This example shows how to use uam with aggregate marketing data and, optionally, customer journey paths. The aggregate baseline uses measure-level aggregation weights before computing channel attribution.

D_variables maps each raw input variable to a final channel and measure. It must contain only variable, channel, and measure.

D_measures is optional. When provided, the recommended user-facing structure is one row per measure with measure and aggregation_weight:

measureaggregation_weight
direct_searches0.45
clicks0.45
impressions0.10

Several variables can map to the same channel: for example, Facebook impressions and Facebook clicks are both assigned to facebook_ads. aggregation_weight is used to combine those variable-level attributions into the final channel-level attribution. The internal signal scaling is estimated automatically from the data.

library(ChannelAttributionPro)

token <- "yourtoken"

# data_mmm_3.csv includes aggregate signals in addition to digital journey data.
df_aggr <- read.csv("https://app.channelattribution.io/data/data_mmm_3.csv")

D_variables <- data.frame(
variable = c(
"direct_searches",
"facebook_impressions",
"facebook_clicks",
"google_impressions",
"google_clicks",
"tv"
),
channel = c(
"direct",
"facebook_ads",
"facebook_ads",
"google_ads",
"google_ads",
"tv"
),
measure = c(
"direct_searches",
"impressions",
"clicks",
"impressions",
"clicks",
"impressions"
),
stringsAsFactors = FALSE
)

D_measures <- data.frame(
measure = c("direct_searches", "clicks", "impressions"),
aggregation_weight = c(0.45, 0.45, 0.10),
stringsAsFactors = FALSE
)

target <- "conversions"

Aggregated-data attribution without customer journey paths​

Use this mode when you only have aggregate time-series data. In this case, uam estimates channel attribution directly from the aggregate signals and the target variable.

res <- uam(
df_aggr = df_aggr,
D_variables = D_variables,
D_measures = D_measures,
target = target,
df_paths = NULL,
baseline_model = "linear", # "reward", "copula", or "linear"
max_p = 12,
nsim = 1000,
seed = 1234567,
verbose = 1,
password = token
)

attribution <- res$attribution
print(head(attribution))

UAM with already aggregated customer journey paths​

Use this mode when customer journeys are already represented as one row per path, with the number of conversions and null outcomes associated with each path.

df_paths_agg <- read.csv("https://app.channelattribution.io/data/data_uam_paths_t.csv")

res <- uam(
df_aggr = df_aggr,
D_variables = D_variables,
D_measures = D_measures,
target = target,
df_paths = df_paths_agg,
baseline_model = "linear", # "reward", "copula", or "linear"
var_path = "path",
var_conv = "total_conversions",
var_null = "total_null",
order = 1,
sep = ">",
verbose = 1,
password = token
)

attribution <- res$attribution
print(head(attribution))

UAM with event-level customer journey paths​

Use this mode when each row is a single touchpoint event. The conversion event is identified by channel_conv and the path is reconstructed internally.

df_paths_events <- read.csv("https://app.channelattribution.io/data/data_uam_paths.csv")

res <- uam(
df_aggr = df_aggr,
D_variables = D_variables,
D_measures = D_measures,
target = target,
df_paths = df_paths_events,
baseline_model = "linear",
channel_conv = "((CONV))",
order = 1,
sep = ">",
verbose = 1,
password = token
)

attribution <- res$attribution
print(head(attribution))