Skip to content

mixdyn.decisions

Decisions on a panel's media: each channel's returns and costs per incremental KPI, and budget plans over every geo's channels, or for a posterior's expected return, its worst share or its least over effects off by a common factor, and the factor that erases a plan's gain; a plan read as a table of channels, spend scenarios compared with their carry-out, and a flighted schedule scored at every draw.

Recommendation = Literal['flighted', 'continuous'] module-attribute

Goal = ReturnTarget | MarginalReturnTarget | ReturnOnSpendTarget

MarginalReturnTarget(per_unit) dataclass

The budget at which one more currency unit returns per_unit: below it a unit returns more, past it less. On revenue, per_unit = 1 is where spend stops paying for itself.

per_unit instance-attribute

ReturnOnSpendTarget(per_unit) dataclass

The most budget whose plan gains per_unit for each currency unit it spends: a target return on ad spend, read on the gain.

per_unit instance-attribute

ReturnTarget(amount) dataclass

The least budget whose plan gains amount, in the channels' units.

amount instance-attribute

FlightPlan(channels, periods, budget, reading, level, schedule, continuous, current, gains, expected, intervals, edge, edge_interval, worth, bound, stopped, limit, tolerance, recommendation, unidentified=()) dataclass

A schedule of one geo's channels over periods, the best rate a period beside it, and how each and the status quo score over a posterior's draws.

schedule is (periods, channels) spend in each period, continuous and current are (channels,) spend a period, the channels in the readings' order: the schedule's, the best rate a period's, both planned at reading, "median" or a draw's index, and each channel's mean over the panel's last periods observed periods. gains is (3, draws), each draw's gain of the schedule, the continuous plan and the status quo in that order, each what its spend adds to the KPI over the periods and the kernel's length after them against spending nothing in the plan, the history carried into all three. expected is their weighted means, (3,), and intervals their weighted central level intervals, (3, 2). edge is each draw's gain of the schedule over the continuous plan, (draws,), and edge_interval its interval. worth, bound, stopped, limit and tolerance are the schedule's search's at the reading, as chc.allocation.Allocation reads them; where the search's schedule returns less than the best rate a period at the reading, the schedule is that rate in every period and worth its worth. recommendation is "flighted" where the lower end of edge_interval is above tolerance, else "continuous". An interval's ends are weighted quantiles, each the least draw whose cumulative weight reaches its share; a draw of weight 0 enters neither them nor the median. unidentified names each channel the schedule, in any period, or the continuous plan moves off its current spend whose spend the panel flags as never moving in the geo (IssueCode.CONSTANT), its worth there read from its prior alone.

channels instance-attribute

periods instance-attribute

budget instance-attribute

reading instance-attribute

level instance-attribute

schedule instance-attribute

continuous instance-attribute

current instance-attribute

gains instance-attribute

expected instance-attribute

intervals instance-attribute

edge instance-attribute

edge_interval instance-attribute

worth instance-attribute

bound instance-attribute

stopped instance-attribute

limit instance-attribute

tolerance instance-attribute

recommendation instance-attribute

unidentified = () class-attribute instance-attribute

GeoLimits(cells, geos=(lambda: MappingProxyType({}))(), channels=(lambda: MappingProxyType({}))(), national=(lambda: MappingProxyType({}))()) dataclass

What a plan may spend, by name.

cells holds each geo's channel's range a period, and every cell needs one with a finite most: a response is read where it was seen, not past it by default. A channel the panel bought nationally has no cell ranges: national holds its national spend's range a period, with a finite most. geos bounds what a geo spends over the plan, its channels together, a national channel's share among them, and channels what a channel spends over it, its geos together; a geo or a channel with no entry is bounded by its cells alone.

cells instance-attribute

geos = field(default_factory=lambda: MappingProxyType({})) class-attribute instance-attribute

channels = field(default_factory=lambda: MappingProxyType({})) class-attribute instance-attribute

national = field(default_factory=lambda: MappingProxyType({})) class-attribute instance-attribute

GeoPlan(geos, channels, periods, spend, current, budget, gain, current_gain, shortfall, price, geo_prices, channel_prices, unidentified=()) dataclass

A plan of every geo's channels, and the current spend it changes.

spend and current are (geo, channel) in the panel's order, in spend a period: the plan's, and each cell's mean over the panel's last periods observed periods. A national channel's column holds each geo's share of its national spend, which the column sums to.

gain is what the plan's spend adds to the KPI over its periods and the carryover after them, and current_gain what the current spend adds run the same way, each against spending nothing in the plan, so the history's carryover counts in neither. shortfall bounds how far gain is below the best plan's within the limits, 0 on concave curves. price is what one more currency unit of budget returns; geo_prices and channel_prices are what one more unit of room in a geo's or a channel's total returns, positive where it binds at its most, negative at its least, 0 where it does not bind. A national channel's price is its national spend's over the plan. unidentified names each cell, (geo, channel) in the panel's order, the plan moves off its current spend whose spend the panel flags as never moving in that geo or in every geo (IssueCode.CONSTANT).

geos instance-attribute

channels instance-attribute

periods instance-attribute

spend instance-attribute

current instance-attribute

budget instance-attribute

gain instance-attribute

current_gain instance-attribute

shortfall instance-attribute

price instance-attribute

geo_prices instance-attribute

channel_prices instance-attribute

unidentified = () class-attribute instance-attribute

return_on_spend property

The gain a currency unit of the budget returns: a ROAS where the KPI is revenue, NaN on a budget of nothing.

Range(least=0.0, most=math.inf) dataclass

At least least and at most most, in the panel's currency; most may be infinite.

Raises:

Type Description
ValueError

unless 0 <= least <= most, with least finite.

least = 0.0 class-attribute instance-attribute

most = math.inf class-attribute instance-attribute

PlanTable(channels, periods, level, margin, breakeven, current, spend, change, revenue_per_kpi, kpi, revenue, marginal_current, marginal_planned, diminishing, total_kpi, total_revenue, factor, factor_low, factor_high) dataclass

A plan of one geo's channels against the current spend, one row a channel.

current and spend are (channels,) in the readings' order, in spend a period: the reference's and the plan's. change is the plan's change in percent of the current spend, 0 where both are 0 and NaN where only the current is. kpi is each channel's change in the KPI from the current spend to the plan's over its periods and the carryover after them, the history's carried in, and revenue that change times the channel's revenue_per_kpi. marginal_current and marginal_planned are each draw's returns(...).marginal_roi at the current and at the planned spend, in revenue a currency unit, NaN at a spend of 0, where the window spends nothing. diminishing is each channel's spend a period at which the posterior-mean marginal return falls to breakeven within its range, or None.

total_kpi and total_revenue are the channels' changes summed at each draw; total_kpi's mean is the plan's expected gain over the reference. factor is the plan's breakdown factor for the expected gain, and factor_low and factor_high the quantiles of the draws' own.

channels instance-attribute

periods instance-attribute

level instance-attribute

margin instance-attribute

breakeven instance-attribute

current instance-attribute

spend instance-attribute

change instance-attribute

revenue_per_kpi instance-attribute

kpi instance-attribute

revenue instance-attribute

marginal_current instance-attribute

marginal_planned instance-attribute

diminishing instance-attribute

total_kpi instance-attribute

total_revenue instance-attribute

factor instance-attribute

factor_low instance-attribute

factor_high instance-attribute

rows()

The table's rows, one a channel in its order, each column by name.

Spread(draws, mean, low, high) dataclass

A quantity over a posterior's draws: draws, (draws, ...), each draw's value; mean their mean by the draws' weights; low and high their weighted quantiles at (1 - level) / 2 and (1 + level) / 2, each (...). A quantity NaN at any draw is NaN in each.

draws instance-attribute

mean instance-attribute

low instance-attribute

high instance-attribute

Breakdown(channels, periods, spend, against, gains, expected, factor, draws) dataclass

How far a plan's effects may be off before its gain over a reference is gone.

spend and against are (channels,) in the readings' order, in spend a period: the plan's and the reference's. gains is each draw's change in each channel's worth from the reference's spend to the plan's, (draws, channels), over the plan's periods and the carryover after them, and expected its mean over the draws by their weights, (channels,). factor is breakdown of expected, the plan's breakdown factor for the posterior's expected gain, and draws breakdown of each draw's gains, (draws,).

channels instance-attribute

periods instance-attribute

spend instance-attribute

against instance-attribute

gains instance-attribute

expected instance-attribute

factor instance-attribute

draws instance-attribute

CvarPlan(channels, periods, spend, against, budget, level, gain, cvar, bound, unidentified=()) dataclass

A plan of one geo's channels for the most mean gain over a reference in the worst level share of a posterior's draws, and that reference.

spend and against are (channels,) in the readings' order, in spend a period: the plan's and the reference's. gain is each draw's gain of the plan over the reference, (draws,): what the plan's spend adds to the KPI over its periods and the carryover after them less what the reference's adds, both on the draw's concave envelopes. cvar is the mean of the worst level share of gain, never below 0, the reference's own; no split within the ranges that spends the budget has a cvar above bound. unidentified names each channel the plan moves off the reference whose spend the panel flags as never moving in the geo (IssueCode.CONSTANT), its worth there read from its prior alone.

channels instance-attribute

periods instance-attribute

spend instance-attribute

against instance-attribute

budget instance-attribute

level instance-attribute

gain instance-attribute

cvar instance-attribute

bound instance-attribute

unidentified = () class-attribute instance-attribute

PosteriorPlan(channels, periods, spend, current, budget, gain, current_gain, grid, unidentified=()) dataclass

A plan of one geo's channels for a posterior's expected return, and the current spend it changes.

spend and current are (channels,) in the readings' order, in spend a period: the plan's, and each channel's mean over the panel's last periods observed periods. gain is what the plan's spend adds to the KPI over its periods and the carryover after them, and current_gain what the current spend adds run the same way, each the posterior's expected value against spending nothing in the plan, so the history's carryover counts in neither. grid is how many spends across each channel's range its mean worth was read at. unidentified names each channel the plan moves off its current spend whose spend the panel flags as never moving in the geo (IssueCode.CONSTANT), its worth there read from its prior alone.

channels instance-attribute

periods instance-attribute

spend instance-attribute

current instance-attribute

budget instance-attribute

gain instance-attribute

current_gain instance-attribute

grid instance-attribute

unidentified = () class-attribute instance-attribute

Readings(channels, retention, half_saturation, slope, coefficient, tanh, fit, chain, stacking, pointwise, length) dataclass

A posterior's draws as a planner reads them, each draw weighted.

retention, half_saturation, slope and coefficient are (draws, channels), the channels in channels' order, each in the panel's units as BayesFit.draws holds it; slope is NaN at a draw whose curve is a tanh, as tanh marks it. fit is the index of the fit each draw comes from and chain its chain in that fit. stacking is each fit's weight, which its draws share evenly, weights. pointwise holds each fit's leave-one-out log predictive density of each observation, (fits, observations), where the weights were solved from them, so that they can be solved again, and is None where they were given. length is the kernels' length.

Raises:

Type Description
ValueError

on no channels or a channel named twice; parameters of other shapes, a retention outside [0, 1], a half-saturation point not positive and finite, a slope not positive and finite where the curve is a Hill or not NaN where it is a tanh, a coefficient not finite; draws' marks of other shapes or kinds, a negative chain, a fit with no draw or with draws of both curves; weights not one a fit, at or above 0 and summing to 1; leave-one-out densities of another shape or not finite; and a length that is not a whole number of periods, at least 1.

channels instance-attribute

retention instance-attribute

half_saturation instance-attribute

slope instance-attribute

coefficient instance-attribute

tanh instance-attribute

fit instance-attribute

chain instance-attribute

stacking instance-attribute

pointwise instance-attribute

length instance-attribute

weights property

Each draw's weight, (draws,): its fit's weight over the fit's number of draws.

RobustPlan(channels, periods, spend, against, budget, scale, gain, worst, grid, unidentified=()) dataclass

A plan of one geo's channels for the least expected gain over a reference when each channel's effect may be off by a factor in [1/scale, scale], and that reference.

spend and against are (channels,) in the readings' order, in spend a period: the plan's and the reference's. gain is the plan's expected gain over the reference as the posterior reads it, and worst its least over the factors, each channel's expected change in worth x counted as x / scale where it is positive and scale x where not, both on the means' interpolants at grid spends across each channel's range, the reference's spend one of them. unidentified names each channel the plan moves off the reference whose spend the panel flags as never moving in the geo (IssueCode.CONSTANT), its worth there read from its prior alone.

channels instance-attribute

periods instance-attribute

spend instance-attribute

against instance-attribute

budget instance-attribute

scale instance-attribute

gain instance-attribute

worst instance-attribute

grid instance-attribute

unidentified = () class-attribute instance-attribute

Worths(rates, table) dataclass

Each draw's worth of each channel at spends a period across its range: rates, (channels, grid), the spends, and table, (draws, channels, grid), the worths, the channels in the readings' order.

rates instance-attribute

table instance-attribute

Costs(spend, incremental, cost_per_kpi, marginal_cost_per_kpi) dataclass

One channel's costs per incremental KPI over a window: spend in currency; incremental, the KPI the window's spend earns wherever it falls, its carryover counted, roi in the KPI's units times the spend; cost_per_kpi, CPIK, the spend over that KPI; and marginal_cost_per_kpi, the cost of one more incremental KPI at the window's spend. Each cost is in currency per KPI, or Undefined.

spend instance-attribute

incremental instance-attribute

cost_per_kpi instance-attribute

marginal_cost_per_kpi instance-attribute

Returns(spend, contribution, roi, marginal_roi, steady_state_marginal_roi, carryover) dataclass

One channel's returns over a window: spend in currency, contribution in revenue, the returns in revenue per currency unit and carryover a share.

spend instance-attribute

contribution instance-attribute

roi instance-attribute

marginal_roi instance-attribute

steady_state_marginal_roi instance-attribute

carryover instance-attribute

Undefined(reason) dataclass

A cost with no value, and why.

reason instance-attribute

ResponseCurves(channels, level, rates, mean, low, high, current, at_current) dataclass

Each channel's worth at each spend a period, (channels, grid), the channels in the readings' order: rates, the spends; mean, the posterior mean worth over the draws at their weights; and low and high, the weighted central level band. current is each channel's current spend a period and at_current the mean worth there, linear between the grid's points, or both None where no current spend was given.

channels instance-attribute

level instance-attribute

rates instance-attribute

mean instance-attribute

low instance-attribute

high instance-attribute

current instance-attribute

at_current instance-attribute

Scenario(name, spend, controls=(lambda: MappingProxyType({}))()) dataclass

A named spend path over a forecast's horizon: spend, each channel's spend at each period, and controls, each control's value at each, a control it does not name held at the baseline's.

name instance-attribute

spend instance-attribute

controls = field(default_factory=lambda: MappingProxyType({})) class-attribute instance-attribute

ScenarioComparison(names, baseline, horizon, carry_out, level, totals, total_mean, total_low, total_high, differences, difference_mean, difference_low, difference_high) dataclass

Scenarios read against a baseline at the same draws, in the panel's units.

names are the scenarios' in the order given, and baseline the one the others are read against. totals is each scenario's KPI summed over the horizon at each draw, drawn about its mean by the model's noise, (scenarios, draws); total_mean its mean and total_low and total_high the central level interval of its draws. differences is each scenario's mean less the baseline's at each draw, summed over the horizon and the carry_out periods after it, (scenarios, draws); difference_mean, difference_low and difference_high read it as the totals are read. The baseline's differences are 0.

names instance-attribute

baseline instance-attribute

horizon instance-attribute

carry_out instance-attribute

level instance-attribute

totals instance-attribute

total_mean instance-attribute

total_low instance-attribute

total_high instance-attribute

differences instance-attribute

difference_mean instance-attribute

difference_low instance-attribute

difference_high instance-attribute

MarginPlan(channels, periods, spend, current, budget, margins, cov, gain, interval, held, record) dataclass

A plan of one national history's channels by a margin rule (plan_margins, plan_anchored_margins), and the status quo it moves.

spend and current are (channels,) in the panel's order, in spend a week: the plan's, and the status quo. budget is what the plan spends over its periods weeks. margins are the margins the plan ranks, each the KPI a unit of weekly spend returns at the status quo, and cov their covariance: shrunk towards their common level where one is positive, and the fit's own where none is, when the plan is the status quo. gain is what the rule claims the plan adds to the KPI over the status quo's, over the periods and the kernel's tail, at the margins' means, and interval its central GAIN_LEVEL normal interval; both are 0 where the plan is the status quo. held names the channels held at their status quo. record names the arm of the benchmark's records the plan reproduces, None for a setting no run recorded.

channels instance-attribute

periods instance-attribute

spend instance-attribute

current instance-attribute

budget instance-attribute

margins instance-attribute

cov instance-attribute

gain instance-attribute

interval instance-attribute

held instance-attribute

record instance-attribute

PooledGeoPlan(cells, periods, spend, current, budget, price, record) dataclass

A plan of a geo panel's cells by the model over geos (plan_pooled_geos), and the status quo it moves.

cells are each geo's own channels, geo by geo in the panel's order, then each channel bought nationally once, in no geo (None). spend and current are (cells,), in spend a week: the plan's, and the status quo, a national cell's summed over the geos. budget is what the plan spends over its periods weeks, and price the slope of expected worth at which the cells spend it. The rule claims no gain (ADR 0090). record names the arm of the benchmark's records the plan reproduces.

cells instance-attribute

periods instance-attribute

spend instance-attribute

current instance-attribute

budget instance-attribute

price instance-attribute

record instance-attribute

plan_flighting(panel, geo, readings, budget, periods, limits, *, reading='median', level=0.9)

The schedule of geo's channels over periods periods of the panel's cadence that spends budget over them within limits, each channel's range in each period, planned on the readings' channels at reading, and the best rate a period beside it; each scored, with the status quo, at every draw.

reading is "median", each parameter at its weighted median over the draws of weight above 0, which must all be of one curve, or the index of one draw.

Raises:

Type Description
ValueError

on per-period budgets, which the planner does not pace; what plan_posterior refuses; a reading neither "median" nor a draw's index, or "median" over draws of both curves; and a level outside (0, 1).

plan_geos(panel, responses, target, periods, limits)

The joint plan of every geo's channels over periods periods of the panel's cadence that spends target, a budget over the plan, or meets it, a goal in its place.

A goal is chc.allocation's: ReturnTarget(amount), the least budget whose plan gains amount; MarginalReturnTarget(per_unit), the plan at which one more currency unit returns per_unit; ReturnOnSpendTarget(per_unit), the most budget whose plan returns per_unit a currency unit on average.

Raises:

Type Description
ValueError

on a response or a cell's range missing for a cell of the panel, or named for one it does not have; a cell's range with no finite most; a range for a cell of a channel bought nationally; a national range missing for a channel the panel bought nationally, named for one it did not, or with no finite most; a limit for a geo or a channel the panel does not have; a geo with no observed period among the last periods; JAX in single precision; and what chc.allocation refuses, its geos and channels named in the panel's order.

ranges_from_current(current, *, least_share, most_multiple, floors=None)

Each channel's range a period as a planner states it: at least least_share of its current spend a period, or its floor in floors where it has one, and at most most_multiple times its current spend.

Raises:

Type Description
ValueError

on a current spend not finite and at or above 0; a share outside [0, 1]; a multiple below 1 or not finite; a floor for a channel current does not have, not finite or below 0, or above the channel's most.

breakdown(gains)

The breakdown factor of each row of channels' gains over a reference, (..., channels): the common factor r* by which effects must be off, overstated where a channel gains and understated where it loses, for the gains to sum to 0, sqrt(sum g^+ / sum g^-).

The least gain at a factor r, sum g^+ / r - r sum g^-, falls as r grows, so at every factor below r* the gains still sum above 0, and at every one above it below 0. r* is below 1 where the gains sum below 0 as read, inf where no channel loses and one gains, 0 where none gains and one loses, and 1 where every gain is 0. Returns (...), a 0-d array for one row.

Raises:

Type Description
ValueError

on no channels or a gain that is not finite.

pick_by_lift_tests(fits)

Each fit's weight when the lift rows alone choose among fits: 1 on the fit whose leave-one-out log predictive density, by PSIS-LOO, summed over the observations past the KPI's, the geo tests' gaps, the lift estimates and the lift series, is the largest, the first on a tie, and 0 on the others; None where the fits read no such observation. stacked_readings reads the weights as given.

Stacking reads every observation, and over a long panel the KPI's periods outnumber the lift rows tenfold. The tests pin each channel's chord from no spend to the spend tested, and a family that reads the KPI's periods a little better can turn that chord into a margin far from the truth's; the lift rows read the curve where the tests ran it (ADR 0082).

Raises:

Type Description
ValueError

on no fits, or fits that read different observations.

plan_breakdown(panel, geo, readings, spend, periods, *, against=None)

The breakdown factor of spend, a plan of geo's channels a period over periods periods of the panel's cadence, over against, or else each channel's mean spend over the geo's last periods observed periods as plan_posterior reads the current spend: for the posterior's expected gain and for each draw's, the history's carryover counted in.

Raises:

Type Description
ValueError

on a geo or a channel the panel does not have; a periods not a whole number, at least 1; spends not one a channel, finite and at or above 0; and a geo with no observed period among the panel's last periods where against is not given.

plan_cvar(panel, geo, readings, budget, periods, limits, *, against, level=0.1, draws=400)

The plan of geo's channels over periods periods of the panel's cadence that spends budget over them within limits, each channel's range a period, for the most mean gain over against, the plan in place at this budget, in the worst level share of draws of the readings' draws: the gain's conditional value at risk, the history's carryover counted in. The draws weigh alike, each fit giving its weight's share of them. The default level, 0.1, is the one mixdyn plans at where no lift test has been run. unidentified names each channel the plan moves off against that the panel flags as never moving in the geo.

Raises:

Type Description
ValueError

on a geo or a channel the panel does not have; a range missing for a channel, named for one the readings do not have or with no finite most; a periods or draws not a whole number, at least 1; a fit holding fewer draws than its share; and what chc.allocation.cvar_allocate refuses: a level outside (0, 1], a budget the ranges cannot spend over the periods, and a reference of the wrong shape, outside the ranges or not spending the budget.

plan_posterior(panel, geo, readings, budget, periods, limits, *, grid=2048)

The plan of geo's channels over periods periods of the panel's cadence that spends budget over them within limits, each channel's range a period, for the most expected worth over the readings' draws, each channel's mean worth read at grid spends evenly across its range.

budget may be a goal in its place, and the plan's budget is then the one that meets it: MarginalReturnTarget(per_unit), the plan at which one more currency unit returns per_unit in expectation, each channel spent until its mean's slope crosses it or to an end of its range; ReturnOnSpendTarget(per_unit), the most budget whose plan's expected gain is per_unit a currency unit or more. A channel whose range is a point is held there.

Raises:

Type Description
TypeError

on a ReturnTarget, which plan_geos meets.

ValueError

on a geo or a channel the panel does not have; a range missing for a channel, named for one the readings do not have or with no finite most; a periods or grid not a whole number, at least 1 and 2; a budget the ranges cannot spend over the periods; a goal whose value is not finite; a return on spend no budget within the ranges reaches; and a geo with no observed period among the panel's last periods.

plan_robust(panel, geo, readings, budget, periods, limits, *, scale, against=None, grid=2048)

The plan of geo's channels over periods periods of the panel's cadence that spends budget over them within limits for the most expected gain over against when each channel's effect may be off by a factor in [1/scale, scale], its least over the factors: plan_posterior's search on each channel's mean change in worth over the reference's, x, counted as x / scale above 0 and scale x below. against is the plan in place, or else each channel's mean spend over the geo's last periods observed periods.

The count is concave in x and kinks at the reference's spend, which joins each channel's grid of grid spends where it is inside the range, in place of the grid's nearest point inside it. The plan keeps the reference's spend, where that spends the budget, while no channel's marginal expected worth there is above scale^2 times another's, and returns it as given. At a scale of 1 it is plan_posterior's plan, on plan_posterior's grid.

Raises:

Type Description
ValueError

on what plan_posterior refuses; a scale not finite and at least 1; and reference spends not one a channel, finite and at or above 0.

readings(fit, *, draws=None)

fit's posterior as a planner reads it: draws of its draws, evenly spaced over its chains' draws in order from the first to the last, or every draw, each weighted alike.

Raises:

Type Description
ValueError

on a draws not from 1 to the fit's draws.

stacked_readings(fits, *, weights=None, draws=None)

The fits' stacked posterior as a planner reads it: each fit's weight, weights or else stacking's on the fits' leave-one-out log predictive densities of the observations their likelihoods read, spread evenly over draws of its draws, evenly spaced over its chains, or over every draw.

The fits are of one geo of one panel: of the same channels, calendar, KPI and observations, and kernels of the same length.

Raises:

Type Description
ValueError

on no fits; fits of different channels, panels, observations or kernel lengths; weights not one a fit, at or above 0 and summing to 1; and a draws not from 1 to a fit's draws.

RuntimeError

three fits or more whose stacking does not converge.

worths(panel, geo, readings, periods, limits, *, grid=512)

Each draw's worth of each channel of readings over periods periods of the panel's cadence and its kernel's length after them, at grid spends a period evenly across the channel's range in limits, the geo's spend in the panel carried in.

Raises:

Type Description
ValueError

on a geo or a channel the panel does not have; a range missing for a channel, named for one the readings do not have or with no finite most; a periods or grid not a whole number, at least 1 and 2.

costs(channel, spend, window=slice(None))

channel's costs per incremental KPI over window of its (T,) spend series, nothing spent before it: one over returns' roi and marginal_roi in the KPI's units.

A window that spends nothing has neither cost; a spend that earns no incremental KPI, or loses some, has no cost per KPI, and a unit more that earns none, or loses some, no marginal cost. Each is Undefined, with its reason.

Raises:

Type Description
ValueError

on a spend series that is not a vector of finite values at or above 0.

portfolio_roi(returns)

Several channels' revenue over their spend: each channel's roi weighted by its spend.

Raises:

Type Description
ValueError

on channels that spend nothing between them.

compare_scenarios(fit, scenarios, *, baseline, horizon, draws, seed, level=0.9)

Each of scenarios over the horizon periods after the fit's window, read against the one named baseline at draws of the posterior and the noise drawn from seed, both shared by every scenario.

A scenario's total is its KPI over the horizon; its difference from the baseline is its mean less the baseline's over the horizon and the kernel's reach after it, fit.length - 1 periods, in which every scenario spends nothing and holds the baseline's controls at their last value. Totals and differences are read over different windows: a difference counts the carryover the horizon's spend leaves after it, which no total holds. Under log-normal noise a mean must be above 0 over the horizon, where a total draws the KPI about it, and not over the carry-out, which only differences read; the totals then draw their noise over the horizon alone.

Raises:

Type Description
ValueError

on no scenarios, two of one name, or no scenario named baseline; a level not inside (0, 1); a baseline that does not name every control or a scenario that names one the model does not have; and what forecast_bayes refuses of the horizon, the draws and each scenario's spend and controls, a log-normal mean not above 0 over the horizon among it.

media_difference(channel_draws, history, plan_a, plan_b, periods)

What plan_b adds to the KPI over plan_a at each draw, (draws,), read through the channels alone: each draw's channel run over its history and each plan's periods periods of spend and its kernel's reach after them, length - 1 periods of no spend, and the difference summed over the plan's periods and the reach.

The models' non-media terms are additive in the mean and cancel between two plans under the same controls; under log-normal noise the mean is the KPI's expectation (ADR 0017), so the difference is one of expected KPIs there too. channel_draws is any fit's: BayesFit's, BayesGeoFit's for one geo with that geo's history, or NestedFit's.

Raises:

Type Description
ValueError

on JAX in single precision; no draws; a draw, a history or a plan whose channels are not the first draw's; a plan's series that is not periods finite values at or above 0, or a history's that is not finite and at or above 0.

move_between_geos(plan, channel, from_geo, to_geo, amount)

plan, each geo's spend by channel, with amount of channel's spend moved from from_geo's cell to to_geo's, at each period where the cells are series; every other cell as it was.

The move is exact on the two cells: the larger of them after it is rounded to its last bit and the smaller is the two cells' sum less it, so that what leaves the one is what the other gains, and their sum is the same real number before and after. Where the sum's last bit is finer than the smaller cell can hold, as moving 5000 from 9000.37 to 12.34 leaves it, no two floats near the move hold that real number, and their sum in double precision is the same float before and after instead, the real sum within one and a half units in the smaller cell's last place. The amount moved is within a unit in the larger cell's last place of amount; one equal to the source's moves all of it but what lies below that place.

Raises:

Type Description
ValueError

on a geo or channel the plan does not have; the same geo twice; cells of other shapes, or with a value not finite or below 0; an amount that does not fit their shape, or is not finite or below 0; and a move larger than the source holds.

response_curves(worths, readings, *, level, current=None)

Each channel's posterior mean worth and its central level band at each spend a period of worths, the draws at readings.weights: the band's ends are the weighted quantiles, each the least worth whose cumulative weight reaches its share, which at equal weights is numpy.quantile's inverted_cdf. current marks each channel's current spend a period.

Raises:

Type Description
ValueError

on a level not inside (0, 1); a table whose draws or channels are not the readings'; and a current spend missing for a channel, named for one the readings do not have, or off the channel's grid.

plan_anchored_margins(panel, estimates, budget, periods, limits, *, kernel, spend_floor=SPEND_FLOOR)

The plan of the panel's channels over periods weeks that spends budget over them within limits, each channel's range a week, by the margin rule anchored on each channel's lift tests, estimates by channel.

It reads one national weekly history, as plan_margins does, and at least one go-dark test of every channel (the module). Each channel's margin is read off the straight margin regression without its noise mixture, anchored on the tests' returns per euro, its bias read by moments, and shrunk towards the channels' common level (mixdyn.calibration.anchors); where the data leave the regression degenerate, the tests alone are shrunk. The plan is water-filled along each channel's margin curve, a mixture of Michaelis-Menten and logistic curves and the line that the tests and the regression read, or the corner on the margins where no curve is read. A channel whose weekly spend follows the week's number is held at its status quo. With one held, the plan is the status quo where fewer than FREE_LEAST channels are free, where the box holds no plan, and where the tests read a convex curve or a kernel past their readout. Each free channel's floor is raised to spend_floor times its least weekly spend over the history, at most its ceiling, where the raised floors leave a plan; None raises none. A budget of None spends the status quo's weekly total each week.

Its record, as anchored floored: within δ = 0.05 of every rival on 16 of 16 family-rungs (M4 15, M5 1). Every rung it planned was a national one with every channel tested, at the status quo's budget, with the floor at SPEND_FLOOR; only that share was scored, and a share of 1 failed its pre-registered study's bar. With spend_floor=None the plan is anchored held's, which no run claimed.

Raises:

Type Description
ValueError

as plan_margins raises on the panel, the ranges, the periods and the budget; on a channel without a test or a test of a channel the panel does not have; on a test that is not a go-dark of the whole market whose dark weeks open its readout, ends on no date of the panel's or opens before it; on tests that went dark or read for different weeks; on a floor outside (0, 1]; and as the regression, the anchoring and the planners raise.

plan_margins(panel, budget, periods, limits, *, kernel)

The plan of the panel's channels over periods weeks that spends budget over them within limits, each channel's range a week, by the margin rule with no lift test.

It reads one national weekly history, its sales, its spend and the controls promotion and price where the panel holds them, and no lift test. Each channel's margin at the status quo is read off the curved margin regression under its mixture of error models (mixdyn.models.fit_margins reads the straight one), each column a Michaelis-Menten curve of the channel's adstock through a kernel of kernel weeks, half-saturated at 16 times its status quo. The margins are shrunk towards their common level, and the budget is water-filled along each channel's curve, each box cut to the range of spend and adstock the history logged. A channel whose weekly spend follows the week's number, or whose columns the regression's nuisance spans, is held at its status quo (mixdyn.decisions.margin_plan). A budget of None spends the status quo's weekly total each week.

Its record, as margin held: within δ = 0.05 of every rival on 15 of 16 family-rungs (M4 11, M5 4); not within δ on family 4 at k = 0, against PyMC-Marketing and Orbit. Every rung it planned was a national one without lift tests, at the status quo's budget; on family 4, S-curves, the data do not identify a curve past the range its spend was logged in.

Raises:

Type Description
ValueError

on a panel that is not weekly, of more than one geo, with a control other than promotion and price, a filled week or an event; on a range missing for a channel, named for one the panel does not have or with no finite most; on periods not a whole number of weeks, at least 1, or a budget that is not finite; and as the regression and the planner raise, DegenerateFitError and a box that holds no plan at the budget among them.

MemoryError

as fit_margins raises.

plan_pooled_geos(panel, estimates, budget, periods, limits, *, kernel)

The plan of the panel's cells over periods weeks that spends budget over them, each cell within its range a week in limits, by the closed-form model over geos fitted with the geo tests estimates, by channel, if any.

It reads a weekly geo panel with each geo's population and no control, and any geo tests (mixdyn.models.fit_pooled_geos): each channel's curve of spend per head shared by the geos, its margin in each geo pooled about the channel's, each channel's posterior over a grid of its carryover and curvature, a kernel of kernel weeks. Each cell's expected worth under the posterior is water-filled (mixdyn.decisions.geo_plan.plan_mixture). A geo's own channel is one cell of each geo, ranged in limits.cells; a channel bought nationally one cell of its national spend, ranged in limits.national. A budget of None spends the cells' status quo's weekly total each week.

Its record, as geo eb: within δ = 0.05 of every rival on 6 of 6 family-rungs (M3 6). Every rung it planned was a geo family's, with and without geo tests, at the status quo's budget, on M3's worlds alone.

Raises:

Type Description
ValueError

on a panel that is not weekly; on limits that bound a geo's or a channel's total, which the rule does not read, or that miss a cell's range, name one the panel does not have or have no finite most; on periods not a whole number of weeks, at least 1, or a budget that is not finite; and as fit_pooled_geos and the planner raise.

plan_table(panel, geo, readings, spend, periods, *, against=None, revenue_per_kpi=1.0, margin=None, level=0.9, limits=None)

The table of spend, a plan of geo's channels a period over periods periods of the panel's cadence, against against, or else each channel's mean spend over the geo's last periods observed periods, as plan_breakdown reads the current spend.

revenue_per_kpi is one rate for every channel or a rate by channel. margin, a gross margin in (0, 1], sets breakeven at 1 / margin, and at 1 on revenue where it is None. limits holds each channel's range a period for its diminishing-returns point, each with a finite most; where it is None a channel's range runs from 0 to the most it spent a period in the history, the plan or the reference, where its response was seen or is asked for.

Raises:

Type Description
ValueError

as plan_breakdown; a revenue_per_kpi not positive and finite or not one a channel; a margin outside (0, 1]; a level outside (0, 1); and limits as worths's.

returns(channel, spend, window=slice(None), *, revenue_per_kpi=1.0)

channel's returns over window of its (T,) spend series, nothing spent before it.

Raises:

Type Description
ValueError

on a spend series that is not a vector of finite values at or above 0, a window that spends nothing, and a revenue_per_kpi not positive and finite.