| Title: | Analyze Incrementality Experiments |
|---|---|
| Description: | Tools for calculating commerce metrics, pairing treatment and control results from A/B testing experiments, estimating incremental effects, and quantifying uncertainty with Student's t and nonparametric bootstrap confidence intervals. Includes validation helpers, a high-level analysis workflow, and compatibility functions for the original package interface. |
| Authors: | Vladimer Kobayashi [aut, cre] (ORCID: <https://orcid.org/0000-0001-9285-9274>) |
| Maintainer: | Vladimer Kobayashi <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.1.1 |
| Built: | 2026-10-07 11:47:55 UTC |
| Source: | https://github.com/vkobayashi/incrementalitytest |
A high-level workflow that pairs groups, calculates experiment-level differences, and summarizes the overall effect with t and bootstrap confidence intervals.
analyze_incrementality( data, metric, id_col = "experiment", group_col = "group", control = "control", treatment = "treatment", direction = c("treatment-control", "control-treatment"), na_action = c("error", "omit"), conf_level = 0.95, bootstrap_times = 2000L, seed = NULL )analyze_incrementality( data, metric, id_col = "experiment", group_col = "group", control = "control", treatment = "treatment", direction = c("treatment-control", "control-treatment"), na_action = c("error", "omit"), conf_level = 0.95, bootstrap_times = 2000L, seed = NULL )
data |
A data frame containing experiment, group, and metric columns. |
metric |
Character scalar naming the metric column. |
id_col |
Character scalar naming the experiment identifier column. |
group_col |
Character scalar naming the group column. |
control |
Value identifying the control group. |
treatment |
Value identifying the treatment group. |
direction |
Difference direction: |
na_action |
How to handle missing metric values: |
conf_level |
Confidence level used by both interval estimators. |
bootstrap_times |
Number of bootstrap replicates. |
seed |
Optional bootstrap seed. |
An object of class incrementality_analysis.
results <- data.frame( experiment = rep(LETTERS[1:4], each = 2), group = rep(c("control", "treatment"), 4), revenue_per_user = c(10, 11, 8, 8.8, 12, 13, 9, 10.5) ) analyze_incrementality( results, "revenue_per_user", bootstrap_times = 199, seed = 42 )results <- data.frame( experiment = rep(LETTERS[1:4], each = 2), group = rep(c("control", "treatment"), 4), revenue_per_user = c(10, 11, 8, 8.8, 12, 13, 9, 10.5) ) analyze_incrementality( results, "revenue_per_user", bootstrap_times = 199, seed = 42 )
Uses ordinary nonparametric resampling of experiment-level differences.
bootstrap_incrementality( x, times = 2000L, conf_level = 0.95, type = "percentile", seed = NULL, na_rm = TRUE )bootstrap_incrementality( x, times = 2000L, conf_level = 0.95, type = "percentile", seed = NULL, na_rm = TRUE )
x |
Numeric vector of differences. |
times |
Number of bootstrap replicates. |
conf_level |
Confidence level between 0 and 1. |
type |
Interval type. Currently percentile intervals are supported. |
seed |
Optional integer seed. The caller's random-number state is restored after the function returns. |
na_rm |
Logical; remove missing values? |
An object of class incrementality_bootstrap, represented as a list
with the estimate, standard error, interval, and bootstrap replicates.
bootstrap_incrementality(c(0.4, 0.8, 0.1, 0.6), times = 199, seed = 1)bootstrap_incrementality(c(0.4, 0.8, 0.1, 0.6), times = 199, seed = 1)
Calculates revenue per user (RPU), buyer rate (BR), average order value (AOV), and transactions per buyer (TPB). Inputs are recycled using base R rules, so the function works with individual totals or equally sized vectors.
calculate_metrics( nb_transactions, nb_users, revenue, nb_buyers, zero_denominator = c("na", "allow") )calculate_metrics( nb_transactions, nb_users, revenue, nb_buyers, zero_denominator = c("na", "allow") )
nb_transactions |
Numeric vector. Number of transactions. |
nb_users |
Numeric vector. Number of unique users. |
revenue |
Numeric vector. Revenue. |
nb_buyers |
Numeric vector. Number of buyers. |
zero_denominator |
How to handle division by zero: return |
A data frame with columns RPU, BR, AOV, and TPB.
calculate_metrics( nb_transactions = 11278, nb_users = 297073, revenue = 279480.4, nb_buyers = 10909 )calculate_metrics( nb_transactions = 11278, nb_users = 297073, revenue = 279480.4, nb_buyers = 10909 )
Statistic for the bootstrap (legacy interface)
incrementality_func(datadiff, indices)incrementality_func(datadiff, indices)
datadiff |
Numeric vector of differences. |
indices |
Resampled indices. |
Mean and estimated variance of the mean.
This compatibility wrapper returns the same named list as the original
package API. New code should generally use calculate_metrics().
incrementality_metrics(nb_transactions, nb_users, revenue, nb_buyers)incrementality_metrics(nb_transactions, nb_users, revenue, nb_buyers)
nb_transactions |
Numeric vector. Number of transactions. |
nb_users |
Numeric vector. Number of unique users. |
revenue |
Numeric vector. Revenue. |
nb_buyers |
Numeric vector. Number of buyers. |
A named list containing RPU, BR, AOV, and TPB.
incrementality_metrics(11278, 297073, 279480.4, 10909)incrementality_metrics(11278, 297073, 279480.4, 10909)
These small helpers are retained for compatibility. They return NA when
all values are missing. fnFreqDay() returns the first mode when tied.
fnFreqDay(x) fnMax(x) fnAve(x) fnSum(x)fnFreqDay(x) fnMax(x) fnAve(x) fnSum(x)
x |
A vector. |
fnAve(), fnMax(), and fnSum() return a numeric scalar.
fnFreqDay() returns the name of the most frequent value, as a character
scalar.
For every experiment, pairs one control value with one treatment value and
computes treatment - control by default. Each experiment must contain
exactly one row for each requested group.
metric_differences( data, metric, id_col = "experiment", group_col = "group", control = "control", treatment = "treatment", direction = c("treatment-control", "control-treatment"), na_action = c("error", "omit") )metric_differences( data, metric, id_col = "experiment", group_col = "group", control = "control", treatment = "treatment", direction = c("treatment-control", "control-treatment"), na_action = c("error", "omit") )
data |
A data frame containing experiment, group, and metric columns. |
metric |
Character scalar naming the metric column. |
id_col |
Character scalar naming the experiment identifier column. |
group_col |
Character scalar naming the group column. |
control |
Value identifying the control group. |
treatment |
Value identifying the treatment group. |
direction |
Difference direction: |
na_action |
How to handle missing metric values: |
A data frame with the experiment ID, control and treatment values,
and a difference column.
results <- data.frame( experiment = rep(c("A", "B", "C"), each = 2), group = rep(c("control", "treatment"), 3), RPU = c(10, 11, 8, 9.5, 12, 11.5) ) metric_differences(results, "RPU")results <- data.frame( experiment = rep(c("A", "B", "C"), each = 2), group = rep(c("control", "treatment"), 3), RPU = c(10, 11, 8, 9.5, 12, 11.5) ) metric_differences(results, "RPU")
Requires the suggested boot package and returns a boot object.
res_boot(mydatadiff, statisticfunc = incrementality_func, nb_boot = 2000L)res_boot(mydatadiff, statisticfunc = incrementality_func, nb_boot = 2000L)
mydatadiff |
Numeric vector of differences. |
statisticfunc |
Statistic function accepted by |
nb_boot |
Number of bootstrap samples. |
An object returned by boot::boot().
Student's t confidence interval for a mean effect
t_confidence_interval(x, conf_level = 0.95, na_rm = TRUE)t_confidence_interval(x, conf_level = 0.95, na_rm = TRUE)
x |
Numeric vector of experiment-level differences. |
conf_level |
Confidence level between 0 and 1. |
na_rm |
Logical; remove missing values? |
A one-row data frame with the sample size, mean, standard error, confidence level, and lower and upper confidence limits.
t_confidence_interval(c(0.4, 0.8, 0.1, 0.6))t_confidence_interval(c(0.4, 0.8, 0.1, 0.6))
Student's t confidence interval (legacy interface)
t_test_cf(datawithID, confinter = 0.05)t_test_cf(datawithID, confinter = 0.05)
datawithID |
A data frame whose second column contains differences. |
confinter |
Legacy lower-tail alpha value. For example, |
A list containing the confidence interval, mean, and standard error.
Compatibility wrapper for datasets containing iabtest_id and abt_group,
where control is coded 0 and treatment is coded 1. It preserves the
original convention of control minus treatment.
test_metric(mydata, metric)test_metric(mydata, metric)
mydata |
A data frame containing |
metric |
Character scalar naming the metric. |
A two-column data frame with iabtest_id and inc_<metric>.