Skip to content

mixdyn.experiments

Experiments before they run: candidate lift tests, the lift a posterior expects each to read, each one's value to the plan, a geo test's design, power and power audit, a comparator design, and a switchback test's design; and after they run: a geo test read into a lift estimate, and a switchback test read by its own randomisation and its carryover's order tested.

Noise = GroupNoise | PlaceboNoise

When = After | Within

Reader = Callable[[_Array, _Array, int], tuple[float, float]]

A test's reading of its window: the treated and the control geos' KPI, (geos, periods), the first pre periods before the test and the rest its readout, to the effect read and its standard error, the effect 0 where the test changed nothing.

Verdict = Literal['up', 'down', 'inconclusive']

Cost = Gross | Net

Update = Reweight | Gaussian | Refit

After(current) dataclass

A test run after the panel, its periods at current, each channel's spend a period under the plan in place, but for the test's change.

current instance-attribute

Candidate(channel, spend, planned, readout, se, share, label='') dataclass

A lift test of channel before it runs: a LiftEstimate without its lift, and a label to name it by.

Raises:

Type Description
ValueError

on what LiftEstimate refuses of its spend, readout, standard error and share.

channel instance-attribute

spend instance-attribute

planned instance-attribute

readout instance-attribute

se instance-attribute

share instance-attribute

label = '' class-attribute instance-attribute

estimate(lift, se=None)

The estimate the test reports once it has run: lift over the readout, at the market's share the group is, with the candidate's standard error or se where the analysis read another.

GroupNoise(market_sd) dataclass

The standard deviation of the market's KPI noise a period, as it reaches a group's lift.

Raises:

Type Description
ValueError

on a standard deviation not positive and finite.

market_sd instance-attribute

se(readout, share)

The standard error of the lift of a group of share of the market over readout periods, read against the rest scaled to its size.

Raises:

Type Description
ValueError

on a readout not a whole number, at least 1, and a share outside (0, 1).

covariance(readout, share)

The covariance of the lift's errors period by period over readout periods, (readout, readout): each period's variance market_sd^2 s / (1 - s), the periods independent.

Raises:

Type Description
ValueError

on what se refuses.

PlaceboNoise(residuals, pre=26) dataclass

The market's KPI noise a period over the history before a test, residuals, the error a model of the KPI leaves in each period, and the pre periods each placebo window and the test are studentised over; see the module.

Raises:

Type Description
ValueError

on residuals not a one-dimensional series of finite numbers, and pre not a whole number, at least 2.

residuals instance-attribute

pre = 26 class-attribute instance-attribute

se(readout, share)

The standard error of the lift of a group of share of the market over readout periods after the residuals, read against the rest scaled to its size, from the placebo windows of readout periods with pre periods before them.

Raises:

Type Description
ValueError

on a readout not a whole number, at least 1, and a share outside (0, 1); residuals too short for a placebo window; residuals 0 over some window's pre periods before it, or the test's, which nothing studentises; and windows that all sum to 0.

covariance(readout, share)

The covariance of the lift's errors period by period over readout periods after the residuals, (readout, readout): the residuals' own autocorrelation, uncentred, at each lag below readout, as a Toeplitz matrix, scaled so that its sum, the variance of the lift summed over the readout, is se(readout, share) squared.

Raises:

Type Description
ValueError

on what se refuses.

Within(start) dataclass

A test run inside the panel's history from its period start, counted from 0, at the market's spend there but for the test's change.

start instance-attribute

Balance(differences, largest) dataclass

Each feature's standardised difference between the treated and the control geos, differences, and the largest in absolute value.

differences instance-attribute

largest instance-attribute

Blocks(blocks, left_out) dataclass

Geos matched into blocks, each a tuple of rows in the order of the score, and the rows left_out of every block.

blocks instance-attribute

left_out instance-attribute

GeoDesign(treated, control) dataclass

The rows of the treated geos and of their control geos.

Raises:

Type Description
ValueError

on a group empty, a row not a whole number at least 0, and a row named twice.

treated instance-attribute

control instance-attribute

Power(lifts, power, size, mde, windows) dataclass

The power of a design's test at each of lifts, power, its size, the share of replications that read a lift where there is none, the minimum detectable lift at 80 % mde, NaN where no lift reaches it, and the count of windows the history holds.

lifts instance-attribute

power instance-attribute

size instance-attribute

mde instance-attribute

windows instance-attribute

PowerAudit(lifts, power, size, mde, mde_low, mde_high, backtests, disjoint, rejected, flag_p_value, flagged) dataclass

A design's power over every one of its backtests, at a 5 % level: its power at each of lifts; its size, the share of the backtests that read a lift where there is none; the minimum detectable lift at 80 % over them all, mde; and the least and the largest of it read over the first half of the backtests in time and over the second, mde_low and mde_high. A lift no backtest reaches is NaN, and so is mde_high where a half reaches none. The size is tested over the disjoint backtests whose readouts do not overlap, of which rejected read a lift where there is none: flag_p_value is the exact two-sided binomial test's p-value against a size of 5 %, and the audit is flagged where it is at most 0.01.

lifts instance-attribute

power instance-attribute

size instance-attribute

mde instance-attribute

mde_low instance-attribute

mde_high instance-attribute

backtests instance-attribute

disjoint instance-attribute

rejected instance-attribute

flag_p_value instance-attribute

flagged instance-attribute

StratifiedDesign(design, strata, candidates, kept, r2, mde) dataclass

The comparator design stratified_design chose: its design, the strata it was drawn within, the count of distinct candidates drawn and of those kept by the R^2 and the A/A filters, and the chosen one's out-of-sample r2 and its time-based regression's minimum detectable lift by formula, mde, a share of the treated geos' KPI.

design instance-attribute

strata instance-attribute

candidates instance-attribute

kept instance-attribute

r2 instance-attribute

mde instance-attribute

GeoReading(method, lift, se, df, alpha, lower, upper, p_value, verdict, permutation_p=None) dataclass

A geo test's reading by method: the lift over the readout and its standard error se, read as a Student t of df degrees of freedom; the two-sided interval [lower, upper] at level alpha; the p_value of the same t, two-sided, against no lift; and the verdict, "up" when the interval lies above 0, "down" when below and "inconclusive" when it holds 0. permutation_p is the synthetic control's permutation p-value (chc.scm.BlankPeriodInference. p_value), None for the other readers and where its arrangements of the blank and readout periods are too many to enumerate.

method instance-attribute

lift instance-attribute

se instance-attribute

df instance-attribute

alpha instance-attribute

lower instance-attribute

upper instance-attribute

p_value instance-attribute

verdict instance-attribute

permutation_p = None class-attribute instance-attribute

GeoTest(channel, treated, control, start, end, spend, planned, readout) dataclass

A geo test of channel as it ran: in the treated geos against the control geos, the spend changed from the period dated start to the one dated end, both included, and read over the readout periods from start. spend and planned are the treated group's spend on the channel as the test ran it and as planned, over the periods before the readout and the readout, as LiftEstimate holds them.

Raises:

Type Description
ValueError

on no treated or no control geos, a geo named twice or in both groups, dates that are not dates or an end before the start, and what LiftEstimate refuses of the spend and the readout.

channel instance-attribute

treated instance-attribute

control instance-attribute

start instance-attribute

end instance-attribute

spend instance-attribute

planned instance-attribute

readout instance-attribute

SdidFit(effect, unit_weights, time_weights, noise, zeta, kkt) dataclass

Synthetic difference in differences on one panel.

effect is tau, the treated units' effect per unit and post-period. unit_weights are the controls', in their order in the panel, and time_weights the pre-periods'. noise is sigma, zeta the unit weights' regularisation. kkt is the larger of the two weight problems' residuals of the conditions of optimality, relative to each problem's scale.

effect instance-attribute

unit_weights instance-attribute

time_weights instance-attribute

noise instance-attribute

zeta instance-attribute

kkt instance-attribute

SdidReading(method, variance, lift, se, lower, upper, p_value, verdict, alpha, df, effect, replications, controls, unit_weights, pre, time_weights) dataclass

A geo test as synthetic difference in differences read it.

lift is the treated geos' KPI over the readout less its counterfactual, summed over the geos and the readout's periods, so effect times both counts, and se its standard error by variance's method over replications estimates. lower and upper bound the interval at alpha, two-sided, a t's at df degrees of freedom (infinite for the normal), and p_value is the same test's of no lift. verdict is "up" where the interval lies above 0, "down" where below and "inconclusive" where it holds 0. controls and pre name what unit_weights and time_weights weigh.

method instance-attribute

variance instance-attribute

lift instance-attribute

se instance-attribute

lower instance-attribute

upper instance-attribute

p_value instance-attribute

verdict instance-attribute

alpha instance-attribute

df instance-attribute

effect instance-attribute

replications instance-attribute

controls instance-attribute

unit_weights instance-attribute

pre instance-attribute

time_weights instance-attribute

CarryoverOrder(order, statistic, p_value, arrangements, enumerated) dataclass

A switchback test's two-epoch test of its carryover's order: whether the channel still moves the KPI order periods after a switch. statistic is the first epoch less the second over the blocks on after a switch, less the same over the blocks off after one, and p_value the share of the arrangements read whose statistic is at least as far from 0, all of the design's where enumerated. A small p-value says the carryover reaches past order, and a washout or a burn-in of order periods leaves part of it in the reading.

order instance-attribute

statistic instance-attribute

p_value instance-attribute

arrangements instance-attribute

enumerated instance-attribute

SwitchbackDesign(dates, block, washout, on, share, seed) dataclass

A switchback test over the periods dated dates, cut into blocks of block periods, the channel on in the blocks where on is true; the first washout periods of every block after a switch, and of the first block, are left out of the reading. share and seed are those it was drawn at: share turns round_half_up(share * blocks) blocks on, as many as on does, and seed's stream draws the arrangements the randomization reading samples; a design written by hand names its own.

Raises:

Type Description
ValueError

on dates that are not increasing dates, a block or a washout not a whole number, a washout at or above the block, periods that do not cut into whole blocks, fewer than 4 blocks, on not one flag a block, no block on or every block on, a share outside (0, 1) or one that turns another count of blocks on than on, and a seed not a whole number at least 0.

dates instance-attribute

block instance-attribute

washout instance-attribute

on instance-attribute

share instance-attribute

seed instance-attribute

periods property

blocks property

on_blocks property

assignment property

Each period's state, true where the channel is on.

kept property

Each period's place in the reading, false in a washout.

SwitchbackReading(method, lift, se, df, level, lower, upper, p_value, verdict, arrangements, enumerated, carryover) dataclass

A switchback test's reading by method: the lift over the periods on and its standard error se, for "randomization" the standard deviation of the lift over the arrangements, for "hac" Newey and West's and for "jackknife" half the gap between its halves' lifts, read as a Student t of df degrees of freedom (infinite for "randomization", which reads no t); the interval [lower, upper] at level; the p_value against no lift; the verdict, "up" when the interval lies above 0, "down" when below and "inconclusive" when it holds 0; the count of arrangements read, 0 for "hac" and "jackknife", and whether they were all enumerated; and the carryover check, NaN where no block after a switch keeps two periods in each state.

method instance-attribute

lift instance-attribute

se instance-attribute

df instance-attribute

level instance-attribute

lower instance-attribute

upper instance-attribute

p_value instance-attribute

verdict instance-attribute

arrangements instance-attribute

enumerated instance-attribute

carryover instance-attribute

ExperimentChoice(best, single, values, exhaustive, plan, evpi, evpi_error, draws, level) dataclass

The affordable set of tests of the largest net value, and whether to run it.

best is that set's value, None where no set is affordable, and single the best affordable single test's. verdict is to test where best's predicted net value is above 0, read on the outer draws at odd places, which no choice read, and to plan now otherwise: the empty set is always a choice, and the largest of noisy net values overstates the set it picks. values is every set valued, in the order valued: by size and then by the candidates' places where every affordable set was valued, each step's sets in turn where the set was grown greedily; exhaustive is which. plan, evpi, evpi_error, draws and level are as ExperimentValues holds them.

best instance-attribute

single instance-attribute

values instance-attribute

exhaustive instance-attribute

plan instance-attribute

evpi instance-attribute

evpi_error instance-attribute

draws instance-attribute

level instance-attribute

verdict property

To test where the best set's predicted net value is above 0, to plan now otherwise.

ExperimentValue(candidates, reduction, error, predicted, interval, reductions, spend_change, opportunity, gross, net, cost, per_cost, net_value, predicted_net_value, local, model_gap, ess, pareto_k, fallback, refitted) dataclass

The value to the plan of candidates run together, in disjoint groups, and its cost; one candidate's where value_of_tests reads it.

reduction is the regret the tests are expected to remove, in the KPI's units, read on the outer draws at even places, and error its Monte Carlo standard error; predicted and interval are the mean and the central level interval of the realised reduction on those at odd places, which no choice by reduction read. reductions is each outer draw's, in their order. spend_change is the tests' spend less the plan's and opportunity the revenue they are expected to lose; gross and net are the costs they make, each the sum of the tests', and cost the one asked for. per_cost is the revenue the reduction is worth a unit of cost, infinite where the tests cost nothing, and net_value that revenue times the uses, less the net cost; predicted_net_value is the same of predicted. local is the local model's reduction, NaN where it is not read, and model_gap its relative miss against reduction. ess and pareto_k are each outer draw's weights' effective sample size and their weighted fits' largest Pareto shape, and fallback the share of outer draws updated as Gaussian, each NaN under Gaussian. Under Refit, reductions and the update's diagnostics are its then's, refitted is the reduction of the refitted posterior's plan at each outer draw refitted and NaN at the others, and reduction, error, predicted and interval are corrected by the gap, the interval moved by its half's mean; refitted is NaN throughout under the others.

candidates instance-attribute

reduction instance-attribute

error instance-attribute

predicted instance-attribute

interval instance-attribute

reductions instance-attribute

spend_change instance-attribute

opportunity instance-attribute

gross instance-attribute

net instance-attribute

cost instance-attribute

per_cost instance-attribute

net_value instance-attribute

predicted_net_value instance-attribute

local instance-attribute

model_gap instance-attribute

ess instance-attribute

pareto_k instance-attribute

fallback instance-attribute

refitted instance-attribute

ExperimentValues(values, plan, evpi, evpi_error, draws, level) dataclass

Each candidate's value, in the candidates' order, and the plan without a test: plan, its spend a period in the readings' channels' order. evpi is the expected value of perfect information over every outer draw, which no test's reduction passes, and evpi_error its Monte Carlo standard error; draws is the number of outer draws and level the intervals'.

values instance-attribute

plan instance-attribute

evpi instance-attribute

evpi_error instance-attribute

draws instance-attribute

level instance-attribute

ranked property

The values by the revenue each reduction is worth a unit of its cost, the most first, the candidates' order on a tie.

Gaussian() dataclass

Each outer draw's posterior mean worths moved by the Bayes-linear update: each fit's by the covariance of its draws' worths with the lift over the lift's predictive variance.

Gross() dataclass

A test's cost as what it puts at risk: a heavy-up's extra spend and the revenue a cut is expected to lose, each counted where it is positive.

Net(floor) dataclass

A test's cost as its spend change plus the revenue it is expected to lose, held at least at floor: a cut of a channel returning less than it costs pays for itself, and a cost not above 0 ranks nothing.

Raises:

Type Description
ValueError

on a floor not positive and finite.

floor instance-attribute

Refit(draws, fit, then=_REWEIGHT) dataclass

Each set of tests valued by then at every outer draw, and its posterior refitted with the tests' simulated estimates at draws outer draws of each half, evenly spaced: the mean gap between the refitted reductions and then's there corrects then's, a multi-fidelity estimate. fit takes each channel's simulated estimates, to be read beside those the model behind the readings already reads, and returns the readings of the model refitted with them.

Raises:

Type Description
ValueError

on draws not a whole number, at least 2.

draws instance-attribute

fit instance-attribute

then = _REWEIGHT class-attribute instance-attribute

Reweight(ess=100.0) dataclass

Each outer draw's posterior read by weighing the other chains' draws by the test's likelihood, and as Gaussian where the weights' effective sample size falls below ess.

Raises:

Type Description
ValueError

on an ess not positive and finite.

ess = 100.0 class-attribute instance-attribute

designs(panel, geo, channels, noise, *, when, multipliers=(0.0, 0.5, 1.5, 2.0), durations=(2, 4, 8), cooldown=8, shares=(0.05, 0.1, 0.2, 0.3, 0.5))

Each of channels' candidates on geo of panel, in the order of the channels, the multipliers, the durations and the shares: the channel's spend times the multiplier over the duration, then cooldown periods at the spend planned, both read, in a group of the share, its standard error noise's, run as when says. The group's spend is the share's of the market's, the panel's own over its history.

Raises:

Type Description
ValueError

on a geo or a channel the panel does not have; no channels or a channel named twice; a multiplier not finite and at or above 0, or 1, which changes nothing; a duration not a whole number, at least 1; a cooldown not a whole number, at least 0; a share outside (0, 1); a plan in place that misses a channel or spends one below 0 or not finitely; a start from which a test and its cooldown do not end within the history; and a channel that spends nothing over a test's periods, which no multiplier changes.

predicted_lift(readings, candidate)

Each draw's lift of candidate at the market's scale, (draws,), in the KPI's units: the channel's coefficient times the gap in its curve over the readout between the spend as the test runs and as planned, each over the share and carried over by the draw's kernel, nothing spent before the candidate's periods. The kernel is the longer of the readings' and the candidate's periods, as the model that reads the estimate has it.

Raises:

Type Description
ValueError

on a candidate of a channel the readings do not have.

seesaw(panel, geo, channels, noise, *, when, high=1.5, low=0.5, block=2, blocks=8, cooldown=8, shares=(0.05, 0.1, 0.2, 0.3, 0.5))

Each of channels' seesaw candidates on geo of panel, in the order of the channels and the shares: the channel's spend times high and low in turn, block periods each, over blocks blocks from a high one, then cooldown periods at the spend planned, all read, in a group of the share, its standard error noise's, run as when says; see the module. The group's spend is the share's of the market's, the panel's own over its history. At a spend planned alike over the test, multipliers as far above 1 as below it change no spend in all.

Raises:

Type Description
ValueError

on a geo or a channel the panel does not have; no channels or a channel named twice; a high not finite and above 1, or a low not finite, at or above 0 and below 1; a block not a whole number, at least 1; blocks not an even whole number, at least 2; a cooldown not a whole number, at least 0; a share outside (0, 1); what designs refuses of when; and a channel that spends nothing over the test's periods.

assign(blocks, seed, *, share=0.5)

A design treating share of each block's geos, rounded half up, one of a pair and three of a block of five at the default, drawn by seed: the same seed draws the same design. The geos left out of the blocks are in neither group.

Raises:

Type Description
ValueError

on a seed not a whole number at least 0, and a share that treats none of a block or all of it.

audit_power(kpi_history, design, readout, lifts, *, pre, read=_read_did)

The power of design's test of readout periods after pre, at each of lifts, read by read once over every backtest kpi_history, (geos, periods), holds, by default with read_did on the groups' sums, at a 5 % level; see the module.

Raises:

Type Description
ValueError

on a history not finite and positive or of fewer geos than the design's; a readout or a pre-period not a whole number at least 1 and 2; a pre-period shorter than three times the readout; no lifts, or a lift not finite or at or below -1; a history that holds fewer than 8 backtests whose readouts do not overlap; and what read refuses.

balance(design, features)

Each of features' standardised difference over design: the treated geos' mean less the control geos', over sqrt((s_t^2 + s_c^2) / 2), s a group's standard deviation.

Raises:

Type Description
ValueError

on no features, a feature not a finite value a geo, a design's geo past the features', a group of one geo, which has no spread, and a feature constant over both groups.

log_did(treated, control, pre)

The pre/post log-ratio difference in differences of a window and its standard error from placebo windows of the pre-period; see the module.

Raises:

Type Description
ValueError

on a pre-period that holds fewer than two placebo windows of the readout.

match_controls(treated, candidates, features)

Each of treated's control among candidates, one to one, minimising the summed Mahalanobis distance over features, each a value a geo, under the treated and the candidate geos' pooled within-group covariance. The design's control[i] is treated[i]'s. One treated geo and one candidate are the only match there is, and no covariance is read.

Raises:

Type Description
ValueError

on no features, a feature not a finite value a geo, fewer candidates than treated geos, a geo in both or twice, and, over three geos or more, a pooled covariance that is singular, which names the features it cannot tell apart.

pair_geos(score, *, size=2)

The geos matched into blocks of size adjacent in the order of score, one number a geo, minimising the summed range of the blocks; the len(score) % size geos left out are those that minimise it, the later in the order on a tie.

Raises:

Type Description
ValueError

on a score not a one-dimensional finite series, a size not a whole number at least 2, and fewer geos than a block's size.

power(kpi_history, design, readout, lifts, *, pre, reps, seed, alpha=0.05, read=_read_did)

The power of design's test of readout periods after pre at each of lifts, by reps replications drawn from kpi_history, (geos, periods), by seed, each read by read, by default read_did on the groups' sums; see the module.

Raises:

Type Description
ValueError

on a history not finite and positive or of fewer geos than the design's; a readout, a pre-period, a count of replications or a seed not a whole number at least 1, 2, 1 and 0; no lifts, or a lift not finite or at or below -1, which leaves no KPI; an alpha outside (0, 1); a history too short for a window of pre and readout periods; and what read refuses, by default a pre-period that holds fewer than two placebo windows of the readout with 13 periods before each.

stratified_design(kpi_history, readout, *, pre, seed, candidates=200, size=2, share=0.5)

The comparator design over the geos of kpi_history, (geos, periods), for a test of readout periods read after the history's last pre: strata of size geos alike in their series' mean, coefficient of variation and slope, candidates designs drawn within them by seed, each treating share of a stratum, filtered by the time-based regression's out-of-sample R^2 and an A/A test and the least minimum detectable lift chosen; see the module.

Raises:

Type Description
ValueError

on a history not finite and positive; a readout, a pre-period, a count of candidates, a size or a seed not a whole number at least 1, 3, 1, 2 and 0; a pre-period shorter than three times the readout or longer than the history; fewer geos than a stratum's size; what assign refuses of the share; and no candidate that passes the A/A test.

read_did(panel, design, *, alpha=0.05, warmup=13, variance='placebo', pairs=None, seed=0)

design's test on panel read by a difference in differences, its standard error from placebo windows with at least warmup periods before each, or, at variance="unit_placebo", read by unit placebos over the design's matched pairs, drawn by seed where they are too many to enumerate; see the module.

Raises:

Type Description
ValueError

on what _series refuses; alpha outside (0, 1); warmup not a whole number, at least 1; variance neither reading; at "placebo", fewer than warmup plus the readout plus 1 periods before the test, which leave fewer than two placebo windows, a control sum not above 0 over the periods before some window, and placebo windows that all read 0; and at "unit_placebo", what _unit_placebo refuses, a control sum not above 0 over the periods some assignment is fitted on among it.

read_pairs(panel, design, pairs, *, alpha=0.05, seed=0)

design's test on panel read by its matched pairs' own difference in differences and sign-flip randomisation inference, the signs drawn by seed where they are too many to enumerate; see the module.

Raises:

Type Description
ValueError

on what _series refuses; alpha outside (0, 1); pairs that are not each one treated and one control geo of the design, every one of them; a seed not a whole number at least 0; and assignments too few for the test to reject at alpha or at 95 %, the estimate's, which leave its interval unbounded: fewer than 6 pairs.

read_synthetic_control(panel, design, *, alpha=0.05, blank=8)

design's test on panel read by a synthetic control of the treated geos' mean, its weights fitted on the pre-period less its last blank periods, its standard error from the gaps' innovations over those blank periods; see the module.

Raises:

Type Description
ValueError

on what _series refuses; alpha outside (0, 1); blank not a whole number, at least 2; fewer than 3 control geos; what chc.scm.blank_period_inference refuses but too many arrangements of the blank and readout periods to enumerate, where the reading keeps no permutation p-value; an autoregression's coefficient of -1, which reads no variance; and gaps whose innovations over the blank periods are all 0.

read_tbr(panel, design, *, alpha=0.05, warmup=13, variance='placebo', pairs=None, seed=0)

design's test on panel read by Kerman, Wang and Vaver's (2017) time-based regression, its standard error from placebo windows with at least warmup periods before each, at variance="iid" their predictive variance under independent errors, or, at variance="unit_placebo", read by unit placebos over the design's matched pairs, drawn by seed where they are too many to enumerate; see the module.

Raises:

Type Description
ValueError

on what _series refuses; alpha outside (0, 1); warmup not a whole number, at least 3; variance none of the readings; at "placebo", fewer than warmup plus the readout plus 1 periods before the test, which leave fewer than two placebo windows; a control sum constant over the periods before some window, which fits no regression; placebo windows that all read 0; at "iid", a fit with no residual; and at "unit_placebo", what _unit_placebo refuses, a control sum constant over the periods some assignment is fitted on among it.

read_sdid(panel, treated, start, end, *, spend, planned, alpha=0.05, variance='placebo', quantile='t', replications=200, seed=0, control=None)

A geo test in panel read by synthetic difference in differences: the geos in treated treated from the date start to the date end, both read, the geos in control the controls (every other geo where it is None) and every period before start the pre-period. The periods after end and the geos in neither group are not read.

spend and planned are the treated geos' spend on the tested channel as the test ran and as planned, LiftEstimate's, the readout their last periods. replications caps the placebos drawn, from a child of seed's stream. The estimate's standard error is the reading's widened to its t at quantile="t", se t_df(0.975) / z(0.975), and the reading's at "normal". At variance="unit_placebo" the placebos are read by their studentised distribution, its interval's half at 95 % over z(0.975) the estimate's error, and quantile is not read.

Raises:

Type Description
ValueError

on an alpha outside (0, 1), fewer than 2 replications, a treated or control geo not in the panel, a geo both treated and a control, dates not the panel's or end before start, a KPI missing over the geos and periods read, what synthetic_did refuses, a placebo with no more controls than treated geos, a jackknife with fewer than two treated geos or fewer than two control geos, unit placebos with a pre-period under the post-period plus 2, an assignment whose gaps over its pseudo post-period are all 0 or too few placebos to reject at alpha or at 5 %, an unknown variance or quantile, and what LiftEstimate refuses, a standard error of 0 among it.

synthetic_did(y, treated, post, *, weights='sdid')

Synthetic difference in differences on y, units by periods, the units flagged in treated treated over the last post periods.

weights="did" holds every control's and every pre-period's weight equal, which is plain difference in differences.

Raises:

Type Description
ValueError

on a y not finite and two-dimensional, flags not one a unit, no treated unit, no control, a post-period not within the periods, or a pre-period under 2 periods.

RuntimeError

on weights that miss the conditions of optimality by more than 1e-10.

carryover_order(kpi, design, *, order=None)

The two-epoch test that design's channel moves kpi no further than order periods after a switch, order the design's washout by default, kpi a value a period of the design or a row a geo of them, summed over the geos; see the module.

Its power reaches 0.8 only where the carryover past order is large or the blocks many. Read at order 1 on ADR 0056's world (blocks of 4, a washout of 1, an AR(1) noise of variance 1 at rho), with a carryover of order 2 that reaches the second period after a switch at c noise standard deviations, over 1000 worlds a cell: over 24 blocks it reaches 0.8 at c = 1.33 for rho 0, 0.5 and 0.8 (0.914 to 1.000), and at c = 1 where rho is 0.5 or 0.8 (0.843, 0.997); over 12 blocks only at c = 1.33 and rho = 0.8 (0.926), and at c = 1.33 and rho = 0 it is 0.500. A test of few blocks that does not reject has not shown the carryover short.

Raises:

Type Description
ValueError

on an order not a whole number at least 0, or one that leaves a block's second epoch empty, at block - 1 periods or more; and a KPI not the design's periods long or not finite.

read_switchback(kpi, spend, design, *, level=0.95, method='randomization', bandwidth='newey-west', burn_in=None)

design's test read from kpi and the channel's spend as run, each a value a period of the design or a row a geo of them, summed over the geos; see the module.

bandwidth names the "hac" error's, "newey-west" or "lag-0"; the other methods read none. burn_in leaves out the first burn_in periods of every block after a switch in place of the design's washout; None, the default, reads the washout.

Raises:

Type Description
ValueError

on level outside (0, 1); method none of the readings; bandwidth neither bandwidth; a burn-in not a whole number, shorter than the washout or at or above the block; a KPI or a spend not the design's periods long or not finite; a KPI whose kept periods are all alike; for "randomization", arrangements too few for the test to reject at level or at 95 %, which leave its interval unbounded; for "hac", block means each at their state's mean; for "jackknife", a half that keeps no period on or none off, and two halves that read the same difference; and what LiftEstimate refuses of the spend, a spend the same on and off among them.

switchback_design(periods, block, washout, *, seed, share=0.5)

A switchback test over the periods dated periods, in blocks of block periods, the channel on in round_half_up(share * blocks) of them, in an order drawn by seed from numpy.random.SeedSequence(seed).spawn(1)[0]: the same seed draws the same design. The first washout periods of every block after a switch are left out of the reading.

Raises:

Type Description
ValueError

on what SwitchbackDesign refuses, and a share that turns no block on or every block on.

choose_tests(panel, geo, readings, candidates, budget, periods, limits, *, test_budget, seed, cost=_GROSS, update=_REWEIGHT, draws=1024, exhaustive=256, level=0.9, revenue_per_kpi=1.0, uses=1.0, grid=512)

The set of candidates to run together, in disjoint groups of at most half the market between them, whose cost is at most test_budget and whose net value is the largest, valued as value_of_tests values one test, its tests' likelihoods multiplied: each candidate's lift read with its own standard normals, the same in every set it is in, drawn from a stream apart from seed's own. Every affordable set is valued where there are at most exhaustive of them; otherwise the set grows from none by the test whose value adds the most a unit of the cost it adds, while that addition is worth more than the net cost it adds, and is kept where it is worth more than the best affordable single test, else that test is. The values are read on the outer draws at even places, so the best set's prediction, on those at odd places, is not the largest of noisy estimates.

Raises:

Type Description
ValueError

as value_of_tests; and on a test budget not finite and at least 0, or an exhaustive not a whole number, at least 0.

RuntimeError

as value_of_tests.

value_of_tests(panel, geo, readings, candidates, budget, periods, limits, *, seed, cost=_GROSS, update=_REWEIGHT, draws=1024, level=0.9, revenue_per_kpi=1.0, uses=1.0, grid=512)

Each candidate's value to the plan of geo's channels that spends budget over periods periods within limits, over draws outer draws of readings, each candidate's lift read with the same standard normals, drawn from a stream apart from seed's own, and each outer draw's posterior updated by update; each channel's mean worth is read at grid spends across its range.

Raises:

Type Description
ValueError

on no candidates or a candidate of a channel the readings do not have; a draws not a whole number, at least 4, or more than a fit holds of its share; a level not in (0, 1); a revenue per unit of the KPI or a number of uses not positive and finite; a seed not a whole number, at least 0; a fit with draws of one chain, whose outer draws would leave no draw of it; a Refit of more draws than an outer half holds, or whose fit returns readings of other channels or of the channels in another order; and as plan_posterior on the panel, the ranges, the periods, the grid and the budget.

RuntimeError

on three fits or more whose weights, solved again, do not converge.