GeoLift Market Selection algorithm based on a Power Analysis.
Source:R/pre_test_power.R, R/plots.R
GeoLiftMarketSelection.RdGeoLiftMarketSelection provides a ranking of test markets for a
GeoLift test based on a power analysis.
Usage
GeoLiftMarketSelection(
data,
treatment_periods,
N = c(),
X = c(),
Y_id = "Y",
location_id = "location",
time_id = "time",
effect_size = seq(-0.2, 0.2, 0.05),
lookback_window = 1,
include_markets = c(),
exclude_markets = c(),
holdout = c(),
cpic = 1,
budget = NULL,
alpha = 0.1,
normalize = FALSE,
model = "none",
fixed_effects = TRUE,
dtw = 0,
Correlations = FALSE,
ProgressBar = FALSE,
print = TRUE,
run_stochastic_process = FALSE,
parallel = TRUE,
parallel_setup = "sequential",
side_of_test = "two_sided",
conformal_type = "iid",
ns = 1000
)
# S3 method for class 'GeoLiftMarketSelection'
print(x, ...)
# S3 method for class 'GeoLiftMarketSelection'
plot(
x,
market_ID = 0,
print_summary = TRUE,
actual_values = TRUE,
smoothed_values = TRUE,
show_mde = FALSE,
breaks_x_axis = 10,
...
)Arguments
- data
A data.frame containing the historical conversions by geographic unit. It requires a "locations" column with the geo name, a "Y" column with the outcome data (units), a time column with the indicator of the time period (starting at 1), and covariates.
- treatment_periods
List of treatment periods to calculate power for.
- N
List of number of test markets to calculate power for. If left empty (default) and if no locations are included through
include_locations, it will populate the list of markets with the deciles of the total number of locations. If left empty and a set of markets is provided byinclude_locationsonly the deciles larger or equal thanlength(include_locations)will be used.- X
List of names of covariates.
- Y_id
Name of the outcome variable (String).
- location_id
Name of the location variable (String).
- time_id
Name of the time variable (String).
- effect_size
A vector of effect sizes to test by default a sequence between 0 - 25 percent in 5 percent increments: seq(0,0.25,0.05). Make sure that the sequence includes zero.
- lookback_window
A number indicating how far back in time the simulations for the power analysis should go. For instance, a value equal to 5 will simulate power for the last five possible tests. By default lookback_window = 1 which will only execute the most recent test based on the data.
- include_markets
A list of markets or locations that should be part of the test group. Make sure to specify an N as large or larger than the number of provided markets or locations. Empty list by default.
- exclude_markets
A list of markets or locations that won't be considered for the test market selection, but will remain in the pool of controls. Empty list by default.
- holdout
A vector with two values: the first one the smallest desirable holdout and the second the largest desirable holdout. If left empty (default) all market selections will be provided regardless of their size.
- cpic
Number indicating the Cost Per Incremental Conversion.
- budget
Number indicating the maximum budget available for a GeoLift test.
- alpha
Significance Level. By default 0.1.
- normalize
A logic flag indicating whether to scale the outcome which is useful to accelerate computing speed when the magnitude of the data is large. The default is FALSE.
- model
A string indicating the outcome model used to augment the Augmented Synthetic Control Method. Augmentation through a prognostic function can improve fit and reduce L2 imbalance metrics.
- "None":
ASCM is not augmented by a prognostic function. Defualt.
- "Ridge":
Augments with a Ridge regression. Recommended to improve fit for smaller panels (less than 40 locations and 100 time-stamps.))
- "GSYN":
Augments with a Generalized Synthetic Control Method. Recommended to improve fit for larger panels (more than 40 locations and 100 time-stamps.
- fixed_effects
A logic flag indicating whether to include unit fixed effects in the model. Set to TRUE by default.
- dtw
Emphasis on Dynamic Time Warping (DTW), dtw = 1 focuses exclusively on this metric while dtw = 0 (default) relies on correlations only.
- Correlations
A logic flag indicating whether an additional column with the correlations between the test regions and total control markets will be included in the final output. Set to FALSE by default.
- ProgressBar
A logic flag indicating whether to display a progress bar to track progress. Set to FALSE by default.
A logic flag indicating whether to print the top results. Set to TRUE by default.
- run_stochastic_process
A logic flag indicating whether to select test markets through random sampling of the the similarity matrix. Given that interpolation biases may be relevant if the synthetic control matches the characteristics of the test unit by averaging away large discrepancies between the characteristics of the test and the units in the synthetic controls, it is recommended to only use random sampling after making sure all units are similar. This parameter is set by default to FALSE.
- parallel
A logic flag indicating whether to use parallel computing to speed up calculations. Set to TRUE by default.
- parallel_setup
A string indicating parallel workers set-up. Set to "sequential" by default.
- side_of_test
A string indicating whether confidence will be determined using a one sided or a two sided test.
- "two_sided":
The test statistic is the sum of all treatment effects, i.e. sum(abs(x)). Defualt.
- "one_sided":
One-sided test against positive or negaative effects i.e. If the effect being applied is negative, then defaults to -sum(x). H0: ES >= 0; HA: ES < 0. If the effect being applied is positive, then defaults to sum(x). H0: ES <= 0; HA: ES > 0.
- conformal_type
Type of conformal inference used. Can be either "iid" for Independent and identically distributed or "block" for moving block permutations. Set to "iid" by default.
- ns
Number of resamples for "iid" permutations if
conformal_type = "iid. Set to 1000 by default.- x
GeoLiftMarketSelection()- ...
additional arguments
- market_ID
Numeric value indicating the market to be plotted. This value should reflect a valid ID from the BestMarkets data frame of the
GeoLiftMarketSelectionoutput.- print_summary
Logic flag indicating whether to print model metrics from the latest possible test. Set to TRUE by default.
- actual_values
Logic flag indicating whether to include in the plot the actual values. TRUE by default.
- smoothed_values
Logic flag indicating whether to include in the plot the smoothed values. TRUE by default.
- show_mde
Logic flag indicating whether to include in the plot the positive and negative MDEs. FALSE by default.
- breaks_x_axis
Numeric value indicating the number of breaks in the x-axis of the power plot. You may get slightly more or fewer breaks that requested based on
breaks_pretty(). Set to 10 by default.
Value
A list with three Data Frames.
- "BestMarkets":
Data Frame with a ranking of the best markets based on power, Scaled L2 Imbalance, Minimum Detectable Effect, and proportion of total KPI in the test markets.
- "PowerCurves":
Data Frame with the resulting power curves for each recommended market.
- "parameters;"
List of parameters to plot the results. Includes the data set, model, fixed-effects, and CPIC parameters.
Examples
# \donttest{
geo_pre <- GeoDataRead(GeoLift_PreTest, date_id = "date", location_id = "location",
Y_id = "Y", format = "yyyy-mm-dd")
set.seed(1)
markets <- GeoLiftMarketSelection(data = geo_pre, treatment_periods = 10, N = 2,
effect_size = c(0, 0.1, 0.2), include_markets = "chicago", cpic = 7.5,
alpha = 0.1, side_of_test = "one_sided", parallel = FALSE, ns = 100)
#> Calculating which the best treatment groups are.
#>
#> Deterministic setup with 2 locations in treatment.
#> ID location duration EffectSize Power AvgScaledL2Imbalance
#> 1 1 chicago, portland 10 0.1 1 0.1682310
#> 2 2 atlanta, chicago 10 0.1 1 0.4547538
#> 3 3 chicago, cincinnati 10 0.1 1 0.1806790
#> Investment AvgATT Average_MDE ProportionTotal_Y abs_lift_in_zero Holdout
#> 1 43646.25 300.9401 0.10378014 0.03306537 0.004 0.9669346
#> 2 54878.25 337.6209 0.09157597 0.04195217 0.008 0.9580478
#> 3 44772.75 204.5031 0.06642229 0.03418832 0.034 0.9658117
#> rank
#> 1 1
#> 2 2
#> 3 3
markets
#> ID location duration EffectSize Power AvgScaledL2Imbalance
#> 1 1 chicago, portland 10 0.1 1 0.1682310
#> 2 2 atlanta, chicago 10 0.1 1 0.4547538
#> 3 3 chicago, cincinnati 10 0.1 1 0.1806790
#> Investment AvgATT Average_MDE ProportionTotal_Y abs_lift_in_zero Holdout
#> 1 43646.25 300.9401 0.10378014 0.03306537 0.004 0.9669346
#> 2 54878.25 337.6209 0.09157597 0.04195217 0.008 0.9580478
#> 3 44772.75 204.5031 0.06642229 0.03418832 0.034 0.9658117
#> rank
#> 1 1
#> 2 2
#> 3 3
plot(markets, market_ID = 1)
#> ##################################
#> ##### GeoLift Simulation #####
#> #### Simulating: 10% Lift ####
#> ##################################
#>
#> GeoLift Results Summary
#> ##################################
#> ##### Test Statistics #####
#> ##################################
#>
#> * Average ATT: 300.94
#> * Percent Lift: 10.4%
#> * Incremental Y: 6019
#> * P-value: 0
#>
#> ##################################
#> ##### Balance Statistics #####
#> ##################################
#>
#> * L2 Imbalance: 872.456
#> * Scaled L2 Imbalance: 0.1682
#> * Percent improvement from naive model: 83.18%
#> * Average Estimated Bias: NA
#>
#> ##################################
#> ##### Model Weights #####
#> ##################################
#>
#> * Prognostic Function: NONE
#>
#> * Model Weights:
#> * cincinnati: 0.2377
#> * miami: 0.202
#> * baton rouge: 0.1551
#> * minneapolis: 0.0816
#> * nashville: 0.0699
#> * dallas: 0.0697
#> * honolulu: 0.0608
#> * san diego: 0.0372
#> * houston: 0.0246
#> * new york: 0.0219
#> * austin: 0.0193
#> * reno: 0.0127
#> * los angeles: 0.0075
# }