This R Markdown shows that quality metrics for any T/C market combination are reproducible as long as the same R package and configuration are used, eliminating ambiguity in the basic setup and parameters.
knitr::opts_knit$set(root.dir = "/Users/bytedance/Desktop/GeoLift") # Set the directory
# Set library
library(GeoLift)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
meli_df <- read_csv("data/tiktok_geolift_sales_by_region_market_selection_blackout_removed.csv", show_col_types = FALSE)
geo_data <- GeoDataRead(
data = meli_df,
date_id = "date",
location_id = "region_id",
Y_id = "count",
format = "yyyy-mm-dd"
)
sprintf("Regions: %d | Time periods: %d", length(unique(geo_data$location)), length(unique(geo_data$time)))
## [1] "Regions: 32 | Time periods: 222"
# T and C Combination KPI share
markets_tt <- c("3515359", "3527115", "3531730", "3995955", "4014336", "4017698", "4017700")
sprintf("Treatment share of total %s: %.01f%%", "count", 100 * sum(geo_data$Y[geo_data$location %in% markets_tt]) / sum(geo_data$Y))
## [1] "Treatment share of total count: 17.0%"
# specify the BAU markets as the excluded markets
bau_markets <- setdiff(unique(geo_data$location), markets_tt)
MarketSelections <- GeoLiftMarketSelection(data = geo_data,
treatment_periods = c(21),
N = c(7),
exclude_markets = bau_markets,
Y_id = "Y",
location_id = "location",
time_id = "time",
effect_size = seq(0, 0.3, 0.001),
lookback_window = 7,
Correlations = TRUE,
fixed_effects = TRUE,
side_of_test = "two_sided")
## Setting up cluster.
## Importing functions into cluster.
## Attempting to load the environment 'package:augsynth'
## Calculating which the best treatment groups are.
##
## Deterministic setup with 7 locations in treatment.
## ID location duration
## 1 1 3515359, 3527115, 3531730, 3995955, 4014336, 4017698, 4017700 21
## EffectSize Power AvgScaledL2Imbalance Investment AvgATT Average_MDE
## 1 0.03 0.8571429 0.2009757 170548.7 862.1779 0.02212476
## ProportionTotal_Y abs_lift_in_zero Holdout rank correlation
## 1 0.1695043 0.008 0.8304957 1 0.9747485
# specify the BAU markets as the excluded markets
bau_markets <- setdiff(unique(geo_data$location), markets_tt)
MarketSelections <- GeoLiftMarketSelection(data = geo_data,
treatment_periods = c(21),
N = c(7),
exclude_markets = bau_markets,
Y_id = "Y",
location_id = "location",
time_id = "time",
effect_size = seq(-0.3, 0, 0.001),
lookback_window = 7,
Correlations = TRUE,
fixed_effects = TRUE,
side_of_test = "two_sided")
## Setting up cluster.
## Importing functions into cluster.
## Calculating which the best treatment groups are.
##
## Deterministic setup with 7 locations in treatment.
## ID location duration
## 1 1 3515359, 3527115, 3531730, 3995955, 4014336, 4017698, 4017700 21
## EffectSize Power AvgScaledL2Imbalance Investment AvgATT Average_MDE
## 1 -0.015 0.8571429 0.2009757 85274.35 -878.1149 -0.02253118
## ProportionTotal_Y abs_lift_in_zero Holdout rank correlation
## 1 0.1695043 0.008 0.1695043 1 0.9747485