mixdyn.models¶
Models fitted to a MediaPanel.
BayesGeoFit(spec, dates, geos, population, y, fitted, draws, log_likelihood, contributions, estimated, diagnostics, divergent, e_bfmi, length)
dataclass
¶
The posterior of the model fitted to every geo of a panel over a window of its calendar.
Arrays run over the geos, then the window's periods; fitted marks the cells the likelihood
read. draws holds each parameter's draws in the panel's units, (chains, draws) leading:
each channel's roi over every geo, retention, half_saturation in spend per head, a Hill's
slope where it is sampled, and spread, the log-SD of its effect over the geos;
coefficient, (geo, channel), a channel's contribution per head of a geo per unit of
saturated spend; base, a geo's KPI per head before media and calendar, its controls at their
means; calendar, each column's coefficient as a share of the base, and control, per head
per unit of the control, where the model has them; sigma, the noise's scale per head at the
mean population; and nu where the model has it.
log_likelihood is each draw's log density of each observation in the panel's units,
(chains, draws, observations): each fitted cell's KPI, geo by geo, then each lift estimate's
lift over its share, channel by channel in the model's order and each channel's in the order
given. contributions and estimated are posterior means in the panel's totals, each (geo,
period): a channel's; a control's, its coefficient times its value; and a calendar column's,
the base it moves. The base's is the rest of estimated.
diagnostics, divergent, e_bfmi and length are as BayesFit's; population is each
geo's, one where the panel has none.
spec
instance-attribute
¶
dates
instance-attribute
¶
geos
instance-attribute
¶
population
instance-attribute
¶
y
instance-attribute
¶
fitted
instance-attribute
¶
draws
instance-attribute
¶
log_likelihood
instance-attribute
¶
contributions
instance-attribute
¶
estimated
instance-attribute
¶
diagnostics
instance-attribute
¶
divergent
instance-attribute
¶
e_bfmi
instance-attribute
¶
length
instance-attribute
¶
channels(geo)
¶
Each channel in geo as chc.response reads it in the panel's totals, at its
parameters' posterior medians: the half-saturation point and the coefficient per head,
each times the geo's population.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a geo the fit does not have. |
channel_draws(geo, count)
¶
Each channel in geo as channels reads it, at count of the posterior's draws
evenly spaced over the chains' draws in order from the first to the last, as
BayesFit.channel_draws reads them.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a geo the fit does not have, and a count below 1 or above the fit's draws. |
BayesGeoSpec(media, controls=(), trend=None, season=None, likelihood=Normal(), saturation=HillCurve(), spread=1.0, centred=frozenset(), noise_prior='half-normal', base_prior='log-normal', slope='sampled')
dataclass
¶
The model over geos: the one-geo model's channels, controls, calendar, noise and curves; the
scale of the half-normal prior on each channel's log-SD of its effect over the geos; the
channels whose deviations are centred, sampled on the scale of that log-SD; and three opt-in
choices, the noise scale's prior, "half-normal" or "log-normal", the geos' bases',
"log-normal", above 0, or "normal", and a Hill's slope, "sampled" or "fixed" at 1.
Raises:
| Type | Description |
|---|---|
ValueError
|
on what |
media
instance-attribute
¶
controls = ()
class-attribute
instance-attribute
¶
trend = None
class-attribute
instance-attribute
¶
season = None
class-attribute
instance-attribute
¶
likelihood = field(default_factory=Normal)
class-attribute
instance-attribute
¶
saturation = field(default_factory=HillCurve)
class-attribute
instance-attribute
¶
spread = 1.0
class-attribute
instance-attribute
¶
centred = frozenset()
class-attribute
instance-attribute
¶
noise_prior = 'half-normal'
class-attribute
instance-attribute
¶
base_prior = 'log-normal'
class-attribute
instance-attribute
¶
slope = 'sampled'
class-attribute
instance-attribute
¶
one_geo()
¶
fit_bayes' spec of the same channels, controls, calendar, noise and curves.
BayesFit(spec, dates, y, fitted, draws, log_likelihood, contributions, estimated, diagnostics, divergent, e_bfmi, length, spend, cadence)
dataclass
¶
The posterior of the model fitted to one geo over a window of the panel's calendar.
Arrays run over the window's periods; fitted marks those the likelihood read. draws holds
each parameter's draws in the panel's units, (chains, draws) leading: roi, retention,
half_saturation, a Hill's slope, and coefficient of each channel, its contribution per
unit of saturated spend; intercept; calendar and control, its coefficient per unit of the
column, where the model has them; sigma, the log's scale under log-normal noise; and nu and
test_sigma where the model has them.
log_likelihood is each draw's log density of each observation in the panel's units,
(chains, draws, observations): the KPI at each fitted period, then each test's gap at its
readout periods, then each lift estimate's lift, then each lift series' gaps jointly, the tests,
the estimates and the series channel by channel in the model's order and each channel's in the
order given. contributions and estimated are
posterior means, a control's contribution its coefficient times its column, the intercept's the
rest of estimated. diagnostics reads each parameter's draws; divergent counts each
chain's divergent transitions, and e_bfmi is each chain's. length is the kernels' length,
which channels hands on. spend is each channel's spend from the panel's first period to the
window's last, which a forecast carries over into the plan's, and cadence the panel's.
spec
instance-attribute
¶
dates
instance-attribute
¶
y
instance-attribute
¶
fitted
instance-attribute
¶
draws
instance-attribute
¶
log_likelihood
instance-attribute
¶
contributions
instance-attribute
¶
estimated
instance-attribute
¶
diagnostics
instance-attribute
¶
divergent
instance-attribute
¶
e_bfmi
instance-attribute
¶
length
instance-attribute
¶
spend
instance-attribute
¶
cadence
instance-attribute
¶
channels()
¶
Each channel as chc.response reads it at its parameters' posterior medians.
channel_draws(count)
¶
Each channel as chc.response reads it at count of the posterior's draws, evenly
spaced over the chains' draws in order from the first to the last: a return's posterior is
mixdyn.decisions.returns read at each.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a count below 1 or above the fit's draws. |
BayesMedia(channel, roi=RoiPrior())
dataclass
¶
BayesSpec(media, controls=(), trend=None, season=None, likelihood=Normal(), saturation=HillCurve(), kernel=None)
dataclass
¶
The model: its channels, its controls, its trend and season if any, its noise, the
family every channel's curve is of, and its kernels' length in periods, kernel: by default
the longest series the model reads, the panel's calendar or a test's, and otherwise the
periods stated, the weights normalised over them and a spend's carryover cut after them
(ADR 0082).
Raises:
| Type | Description |
|---|---|
ValueError
|
on a column named twice, a model with no channel, a control held to a bound other than its sign, or a kernel's length that is not a whole number of periods, at least 1. |
media
instance-attribute
¶
controls = ()
class-attribute
instance-attribute
¶
trend = None
class-attribute
instance-attribute
¶
season = None
class-attribute
instance-attribute
¶
likelihood = field(default_factory=Normal)
class-attribute
instance-attribute
¶
saturation = field(default_factory=HillCurve)
class-attribute
instance-attribute
¶
kernel = None
class-attribute
instance-attribute
¶
calendar_terms()
¶
The trend's and the season's columns' names.
calendar(periods, *, ahead=0)
¶
The trend's columns over the window's length and the season's, over periods, then
over the ahead periods after them.
DlmFit(spec, dates, cadence, y, x, filtered, smoothed, signed, base, seasonality, contributions, estimated, spend, lifted=None, baselines=(lambda: MappingProxyType({}))())
dataclass
¶
The model fitted to one geo's calendar.
filtered and smoothed are chc.dlm's outputs. The decomposition is from the smoothed
means: base (None without a trend), seasonality (None without a season), one contribution
per effect, and estimated, their sum.
With a signed effect, signed holds the draws of the posterior truncated to the signs and
the decomposition is from their mean; smoothed stays the model's without the signs.
signed.mixed says whether the draws can be read.
x holds the effects' columns as the model reads them, a transformed effect's its channel's
saturated adstock, and channels hands the transformed effects to a planner. spend holds each
transformed effect's spend as the panel gave it, which a forecast carries over into the plan's.
lifted, where the fit read lift tests, is the posterior given them too
(mixdyn.models.dlm_lift.Lifted): smoothed, the decomposition and signed are then that
posterior's, and filtered stays the KPI's filter, whose one-step errors the tests are not.
baselines holds each effect the panel declares a lever at its counterfactual level, in the
control's units: its contribution is its coefficient times its departure from that level and
the base holds the coefficient times the level, here and in a forecast's decomposition.
spec
instance-attribute
¶
dates
instance-attribute
¶
cadence
instance-attribute
¶
y
instance-attribute
¶
x
instance-attribute
¶
filtered
instance-attribute
¶
smoothed
instance-attribute
¶
signed
instance-attribute
¶
base
instance-attribute
¶
seasonality
instance-attribute
¶
contributions
instance-attribute
¶
estimated
instance-attribute
¶
spend
instance-attribute
¶
lifted = None
class-attribute
instance-attribute
¶
baselines = field(default_factory=lambda: MappingProxyType({}))
class-attribute
instance-attribute
¶
log_likelihood
property
¶
The KPI filter's one-step log-likelihood, and with tests their log density given the KPI: the spec's log-likelihood of everything the fit read.
last()
¶
The state at the last period given every period and every test the fit read, without the signs: Student t with the third's degrees of freedom about the first, its scale matrix the second, stated at the fourth, the variance's estimate. Without tests it is the filter's.
channels(at=-1)
¶
Each effect with a transform as chc.response reads it, by its column: its transform's
kernel and curve, and its coefficient at period at of the fit, the last by default.
The coefficient is the state's posterior mean given the periods up to at, the filter's,
so that a channel run over the panel's spend up to at returns there the coefficient times
the effect's column. With a signed effect it is the mean of the draws of the posterior
truncated to the signs, which read every period, and with tests the posterior's mean given
them, which read their readouts' periods: only the last period is offered of either. A
negative coefficient is handed on as it is; chc.allocation refuses to plan on it.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a fit with no transformed effect, a period outside the fit, a period other than the last with a signed effect or tests, or JAX in single precision. |
DlmForecast(dates, mean, scale, dof, base, seasonality, contributions)
dataclass
¶
The KPI over the periods after a fit's data, forecast 1 to horizon steps ahead.
Each period's KPI is Student t with location mean, squared scale scale and dof degrees
of freedom. base, seasonality and contributions split mean as DlmFit's
decomposition splits estimated.
dates
instance-attribute
¶
mean
instance-attribute
¶
scale
instance-attribute
¶
dof
instance-attribute
¶
base
instance-attribute
¶
seasonality
instance-attribute
¶
contributions
instance-attribute
¶
interval(level)
¶
Each period's central predictive interval holding level of its probability.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a level outside (0, 1). |
DlmForecastDraws(dates, kpi, acceptance)
dataclass
¶
Draws of the KPI over the periods after a fit's data, kpi (draws, horizon), and the
share of the paths drawn whose signed coefficients kept their signs at every period forecast,
acceptance: how hard the signs bind over the horizon, 1 for a fit without them.
DlmSpec(effects, trend=None, season=None, form='additive', variance_discount=1.0)
dataclass
¶
The model's structure. form and variance_discount are chc.dlm's.
Raises:
| Type | Description |
|---|---|
ValueError
|
on an effect named twice, a block |
effects
instance-attribute
¶
trend = None
class-attribute
instance-attribute
¶
season = None
class-attribute
instance-attribute
¶
form = 'additive'
class-attribute
instance-attribute
¶
variance_discount = 1.0
class-attribute
instance-attribute
¶
signs()
¶
Each signed effect's sign, keyed by its column of the design: chc.dlm's signs.
season_observed()
¶
Per season coordinate, whether the observation reads it: the first of each harmonic's pair, and the single coordinate of a harmonic at the Nyquist frequency.
blocks()
¶
The chc.dlm blocks, in state order.
Effect(column, discount, hold_when_idle=True, sign=None, transform=None)
dataclass
¶
A channel or control of the panel, with a random-walk coefficient and its discount.
While its column is zero the coefficient is held, not discounted (hold_when_idle), so a
channel that goes dark does not come back with its variance grown by discount ** -steps.
sign holds the coefficient to "positive" or "negative" at every step. The fit is then
the posterior truncated to the sign, not a clipped one: what the data pull against the sign
moves into the other states, the base first.
transform, on a channel, carries its spend over and saturates it before the coefficient
multiplies it: the column is the transform's (Transform.column), and the coefficient times
it is the channel's response at the period.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a sign that is neither, or a transform that is not a |
Season(period, harmonics, discount)
dataclass
¶
Trend(order, discount)
dataclass
¶
Bounds(lower, upper)
dataclass
¶
ComponentBounds(base, seasonality, contributions)
dataclass
¶
DiscountGrid(trend=(), season=(), effects=())
dataclass
¶
The discounts to try, per family of blocks: the trend's, the season's, and the effects',
one shared by every effect or with PerEffect each effect's own. An empty family keeps the
spec's own discount and is not a parameter.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a grid with no family, or a family that names a discount twice. |
trend = ()
class-attribute
instance-attribute
¶
season = ()
class-attribute
instance-attribute
¶
effects = ()
class-attribute
instance-attribute
¶
parameters(spec)
¶
How many discounts the grid varies in spec, one a family it sets and with PerEffect
one an effect: its likelihood ratio's degrees of freedom.
specs(spec)
¶
spec at every combination of the grid's discounts, the last family varying fastest,
and with PerEffect the last effect's fastest of the effects'.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a family the grid varies that |
blocks(spec)
¶
The grid about spec in the blocks a search moves one at a time (search_media): the
whole of specs(spec) as one; with PerEffect, every pair of the discounts it varies,
the trend's, the season's and each effect's, at every combination of the pair's values
with the rest held, or the one alone where it varies one. The product over the effects
grows as the values to the power of their count and the pairs as its square; a pair
moves together two discounts that trade off, where one at a time can stop short.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a family the grid varies that |
edges(kept, best)
¶
Each end of the grid that a spec of kept reaches where the discount goes on past it:
a family's lowest discount, and its highest where that is below 1, the discount's own
bound, of a family of more than one; with PerEffect each effect's. best is the
likelihood's best spec.
DlmChoice(specs, filtered, best, kept, edges=(), lifts=())
dataclass
¶
Every spec of a grid filtered on one geo, the one-step likelihood's best, and the specs the
likelihood ratio keeps, each with its fit. fit gives the point estimates; bounds and
coefficient_bounds the intervals; channels and readings what a planner reads.
filtered holds each spec's filter, in the order of specs; kept maps the index of each
kept spec to its fit. A spec the test rejects is not smoothed, and with a signed effect its
posterior is not drawn; a kept spec's signed chains that have not mixed are drawn again at
twice the draws, at most twice. A media search (mixdyn.models.dlm_media.search_media) holds
only the specs it kept, and fits every one of them or a sample of them stratified by
likelihood (ADR 0023): kept maps the index of each fitted spec to its fit.
edges names each end of a grid that a kept spec reaches where the parameter goes on past it
(Edge): there the set, and every interval over it, may stop short of the data's.
lifts, where the choice read lift tests, is each spec's tests' log density given its KPI, in
the order of specs, and empty where it read none: a spec's log-likelihood is its filter's
plus its tests' (log_likelihoods).
specs
instance-attribute
¶
filtered
instance-attribute
¶
best
instance-attribute
¶
kept
instance-attribute
¶
edges = ()
class-attribute
instance-attribute
¶
lifts = ()
class-attribute
instance-attribute
¶
fit
property
¶
The fit whose log-likelihood is the highest.
log_likelihoods
property
¶
Each spec's log-likelihood, in the order of specs: its filter's one-step, plus its
tests' log density given its KPI where the choice read tests.
bounds(view, *, draws, seed, level=0.9)
¶
Each component's interval at level for a view of the decomposition, such as
lambda d: d.window(start, end): the union of the kept fits' intervals, each from
draws of its posterior's draws, as decompose_dlm takes them.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a |
coefficient_bounds(level=0.9)
¶
Each effect's coefficient at the last period, by its column: the union of the kept
fits' central intervals holding level. A fit's interval is its Student t at the last
period (DlmFit.last), the coefficient's posterior given every period and every test, or
with a signed effect the quantiles of its draws of the posterior truncated to the signs
there.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a |
channels(at=-1)
¶
The best fit's channels, DlmFit.channels: the plan at the likelihood's best point.
Raises:
| Type | Description |
|---|---|
ValueError
|
on what |
readings(draws, seed)
¶
draws readings of the channels at the last period, as chc.allocation reads a
posterior's draws: each a tuple of every transformed effect's channel, in the order of
channels(), at one draw of their coefficients. allocate takes one reading at a time.
The draws are spread over the fitted specs (kept) evenly, a mixture in which no spec the
likelihood ratio keeps is ranked above another: each takes draws // len(kept), and the
rest go one each to specs drawn at random from seed. Each reading's kernels and curves
are its spec's. A spec's coefficients are drawn from their posterior at the last period
given every period and every test, its multivariate Student t there (DlmFit.last), or
with a signed effect from its fit's draws of the posterior truncated to the signs, without
replacement; each spec from a stream of seed and its index of its own. The readings come
in an order drawn from seed, so any of them are a sample of the rest. Their quantiles are
the mixture's, not the wider union of the kept fits' intervals that bounds and
coefficient_bounds give.
Raises:
| Type | Description |
|---|---|
ValueError
|
on |
forecast(horizon, plan, draws, seed)
¶
draws draws of the KPI over the horizon periods after the data, the effects' columns
taken from plan, each a draw of one fitted spec's forecast (forecast_draws), spread
over the fitted specs as readings spreads its draws and in an order drawn from seed. A
transformed effect's plan is its spend, which each spec carries over and saturates by its
own transform. Each spec draws from a stream of seed and its index, apart from those
readings takes for the same seed. acceptance is over every spec's paths.
Raises:
| Type | Description |
|---|---|
ValueError
|
on |
Edge(parameter, end, best)
dataclass
¶
An end of a grid that a kept spec reaches where the parameter goes on past it, so the set
the likelihood ratio keeps may stop there short of the data's: parameter names it, such as
"trend discount", "tv discount" or "tv half-saturation", end is the grid's value
there, a half-saturation point's as a multiple of the channel's mean positive spend, and
best says whether the likelihood's best spec sits there too.
PerEffect(values, held=())
dataclass
¶
Discounts each effect takes on its own: a grid tries every combination of values over the
effects, the last effect's varying fastest, and counts one parameter an effect. The effects
whose columns held names keep the spec's own discount, are no parameter and no block, as a
calendar event's static coefficient (ADR 0069).
Raises:
| Type | Description |
|---|---|
ValueError
|
on no value, or a value named twice. |
Components(base, seasonality, contributions)
dataclass
¶
DlmDecomposition(dates, draws)
dataclass
¶
A fit's components over its periods, (draws, periods) each, from the posterior of its
states. A draw's components add up to its mean; their averages over the draws are the fit's
smoothed decomposition, up to Monte Carlo error.
dates
instance-attribute
¶
draws
instance-attribute
¶
window(start, end)
¶
Each component's total over the periods from start to end, both included: the
waterfall's steps, which add up to the window's total mean draw by draw.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a window that holds no period of the fit. |
change(before, after)
¶
Each component's change in its mean per period from the window before to the window
after, each given as its first and last date: the period-over-period view. Means per
period let windows of different lengths compare.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a window that holds no period of the fit. |
CheckCode
¶
Bases: Enum
NEGATIVE_BASE = 'negative_base'
class-attribute
instance-attribute
¶
The base is below zero.
BASE_ABOVE_KPI = 'base_above_kpi'
class-attribute
instance-attribute
¶
The base is above the observed KPI, so the effects sum below zero there.
EFFECT_ABOVE_TWICE_MAX = 'effect_above_twice_max'
class-attribute
instance-attribute
¶
An effect's contribution is above twice the KPI's largest observed value.
UNMIXED = 'unmixed'
class-attribute
instance-attribute
¶
The chains that drew the posterior truncated to the signs have not mixed, so no period's decomposition can be read.
DlmDiagnostics(dates, scores, lags, ljung_box, normality, durbin_watson, log_likelihood, arl, drift, findings)
dataclass
¶
A fit's checks.
dates are the observed periods and scores their one-step errors as normal scores.
ljung_box tests the scores for autocorrelation over lags lags, pairing periods by the
calendar, so a missing period breaks a pair rather than closing up the gap; normality tests
them for the standard normal law (Cramér-von Mises), which a forecast that is too narrow, too
wide or biased fails as surely as a skewed one; durbin_watson is their lag-one statistic,
near 2 when they are uncorrelated.
log_likelihood sums the one-step log predictive densities: the criterion to compare models
by. drift holds the dates where a Shiryaev-Roberts alarm sounded, against one-step errors
shifted by two scales either way or of twice the scale, with a false alarm every arl periods
on average. findings holds the decomposition's failed plausibility checks.
Finding(code, message, effect, dates)
dataclass
¶
Statistic(value, p_value)
dataclass
¶
Lifted(reading, log_density, mean, covariance, dof, scale, smoothed, units, kpi, cross, factor)
dataclass
¶
A fit's posterior given its KPI and its tests.
log_density is the tests' log density given the KPI, multivariate Student t, so a spec's
log-likelihood is its KPI filter's plus it. At the last period the state is Student t with
dof degrees of freedom about mean, its scale matrix covariance stated at scale, the
variance's estimate; smoothed holds every period's, as chc.dlm.smooth holds the KPI's.
reading is the tests, units each one's variance in units of V, kpi the KPI's smoothed
means, cross each state's covariance with each test given the KPI in units of V, and
factor the Cholesky factor of the tests' covariance in those units: what a draw of the path
given the tests reads.
reading
instance-attribute
¶
log_density
instance-attribute
¶
mean
instance-attribute
¶
covariance
instance-attribute
¶
dof
instance-attribute
¶
scale
instance-attribute
¶
smoothed
instance-attribute
¶
units
instance-attribute
¶
kpi
instance-attribute
¶
cross
instance-attribute
¶
factor
instance-attribute
¶
LiftReading(channels, coordinates, weights, lift, se)
dataclass
¶
The tests a fit reads, each an observation of one coordinate of the state path: test j
reads coordinate coordinates[j] at period t with weight weights[j, t], zero outside its
readout, and its lift lift[j] has standard error se[j], both at the market's scale.
channels names each test's channel.
TransformGrid(retentions, half_saturations, shapes)
dataclass
¶
The transforms a search tries for each channel: retentions, half_saturations as
multiples of the channel's mean positive spend on the geo, the Bayesian model's unit for them,
and shapes.
Raises:
| Type | Description |
|---|---|
ValueError
|
on an axis with no value; retentions not ascending within |
retentions
instance-attribute
¶
half_saturations
instance-attribute
¶
shapes
instance-attribute
¶
parameters
property
¶
How many of a channel's parameters the grid varies, one for each axis of more than one value: a channel's degrees of freedom in a likelihood ratio.
refined(level)
¶
The grid with each interval between neighbouring values cut into 2 ** level equal
parts, the half-saturation's on a log scale; the shapes as they are. A value of a coarser
level is the same number at every finer one.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a level that is not a whole number at or above 0. |
GeoDlmFit(spec, dates, cadence, geos, y, x, spread, smoothed, base, seasonality, contributions, estimated)
dataclass
¶
The model fitted to every geo of a panel.
spread is chc.dlm.fit_geo_spread's: the deviations' spread, its intervals and draws, and
the filter at the spread chosen; smoothed is the smoothed states mixed over its draws, each
step's mean and covariance those of the mixture, a covariance the variance, and its degrees of
freedom the draws' mean. Its marginals are mixtures of Student t, so it is not exact. The
decomposition is from its means, each array (geo, period) in the panel's orientation: base
(None without a trend), seasonality (None without a season), one contribution per effect, and
estimated, their sum.
spec
instance-attribute
¶
dates
instance-attribute
¶
cadence
instance-attribute
¶
geos
instance-attribute
¶
y
instance-attribute
¶
x
instance-attribute
¶
spread
instance-attribute
¶
smoothed
instance-attribute
¶
base
instance-attribute
¶
seasonality
instance-attribute
¶
contributions
instance-attribute
¶
estimated
instance-attribute
¶
GeoDlmSpec(effects, trend=None, season=None, form='additive', variance_discount=1.0)
dataclass
¶
The model's structure over geos. An effect's discount is its national coefficient's, and a
geo's deviation from it is static; trend and season are each geo's own. form and
variance_discount are chc.dlm's.
Raises:
| Type | Description |
|---|---|
ValueError
|
on what |
effects
instance-attribute
¶
trend = None
class-attribute
instance-attribute
¶
season = None
class-attribute
instance-attribute
¶
form = 'additive'
class-attribute
instance-attribute
¶
variance_discount = 1.0
class-attribute
instance-attribute
¶
one_geo()
¶
The structure of one geo's model: fit_dlm's spec of the same blocks.
national()
¶
The national blocks: a coefficient for each effect.
regional()
¶
Each geo's blocks: its trend, its deviations from the national coefficients, and its season, in that order.
deviations()
¶
The deviations' coordinates within a geo's regional state.
GeoEffects(effects, level, mean, lower, upper)
dataclass
¶
CellResponse(history, scale, length, weights, retentions, curvatures, coefficients)
dataclass
¶
A cell's expected response to its weekly spend over a plan: a mixture of curves, one a kept
grid point, each of its weights, retentions, curvatures and coefficients.
A plan spends w a week over its periods; with the cell's history, its spend before them,
the kernel's adstock at each of the plan's periods and the length - 1 after them is
a_h = carry_h + w reach_h, and a point's worth is b s sum_h F(a_h / s), s the cell's
scale (the module's). worth is the mixture's, and slope its derivative in w.
Raises:
| Type | Description |
|---|---|
ValueError
|
on component arrays of different shapes, a history shorter than the kernel's
|
history
instance-attribute
¶
scale
instance-attribute
¶
length
instance-attribute
¶
weights
instance-attribute
¶
retentions
instance-attribute
¶
curvatures
instance-attribute
¶
coefficients
instance-attribute
¶
slope(weekly, periods)
¶
The expected worth's derivative at each weekly spend of weekly over periods.
worth(weekly, periods)
¶
The expected worth at each weekly spend of weekly over periods and the kernel's
tail after them, the history's carryover counted in.
Mixture(points, weights, coefficients)
dataclass
¶
A channel's posterior over its grid, the other channels at their points: points, the
kept points as indices into POINTS; weights, theirs, summing to 1; and coefficients,
the posterior mean of the channel's coefficient in each geo under each point,
(points, geos).
PooledGeoFit(geos, channels, national, length, selected, mixtures, shares, scale, spend, sigma, margin, prior_sd, rows, tests)
dataclass
¶
The fit of a panel over geos (the module).
channels and geos are the panel's, national its channels bought nationally, length the
kernel's. selected is each channel's grid point at the end of the coordinate ascent, an index
into POINTS, and mixtures each channel's posterior over its grid. shares are the geos'
population shares, scale each geo's channel's s_gc, (geos, channels), and spend the
panel's, (geos, weeks, channels). sigma is each geo's noise standard deviation, margin
each channel's m_c and prior_sd its margin's prior standard deviation. rows are the weeks
read after the burn-in, and tests the lift estimates read.
geos
instance-attribute
¶
channels
instance-attribute
¶
national
instance-attribute
¶
length
instance-attribute
¶
selected
instance-attribute
¶
mixtures
instance-attribute
¶
shares
instance-attribute
¶
scale
instance-attribute
¶
spend
instance-attribute
¶
sigma
instance-attribute
¶
margin
instance-attribute
¶
prior_sd
instance-attribute
¶
rows
instance-attribute
¶
tests
instance-attribute
¶
cell(geo, channel)
¶
The expected response of a geo's own channel in geo, or, at geo None, of a
channel bought nationally as one cell of its national spend (the module).
Raises:
| Type | Description |
|---|---|
ValueError
|
on a channel or a geo the fit does not have, a geo named for a channel bought nationally, or none for one that is not. |
DegenerateFitError
¶
Bases: ValueError
The data leave the margin regression degenerate; the message says how.
MarginFit(mean, cov, retention, top, top_weight, phi, phases, rows, burn_in, columns, prior_share, spanned, share=1.0, promoted=1.0)
dataclass
¶
The margins' posterior, the mixture over the retention combinations.
mean is each channel's margin, the KPI a unit of weekly spend returns over the kernel, and
cov their covariance, (channels, channels). retention is each channel's posterior mean
retention and top the combination of the most evidence, top_weight its weight. phi is
the AR(1) coefficient's mean over the combinations, by weight. phases are the promoted
phases, t mod 52, each a dummy. rows are the weeks the regression read, after burn_in,
and columns its design's. prior_share is each channel's evidence weight of the
combinations in which the prior's precision on its coefficient exceeds the data's (the module).
spanned are the channels whose columns the nuisance columns span under a noise mixture, their
margin exactly 0 (the module); without one, none.
Under a noise mixture the weights run over the error models too: phi is the posterior mean
of rho, share that of omega, the AR(1)'s share of the errors' variance, and promoted
that of h, the promoted weeks' variance over the other weeks'; without one the errors are
the AR(1) alone on every week, and both are 1.
mean
instance-attribute
¶
cov
instance-attribute
¶
retention
instance-attribute
¶
top
instance-attribute
¶
top_weight
instance-attribute
¶
phi
instance-attribute
¶
phases
instance-attribute
¶
rows
instance-attribute
¶
burn_in
instance-attribute
¶
columns
instance-attribute
¶
prior_share
instance-attribute
¶
spanned
instance-attribute
¶
share = 1.0
class-attribute
instance-attribute
¶
promoted = 1.0
class-attribute
instance-attribute
¶
NoiseMixture(knot_every=MIXTURE_KNOT_EVERY, persistence=PERSISTENCE, share=SHARE, promoted=PROMOTED, white=True)
dataclass
¶
The regression's settings under a mixture of error models (the module): the weeks between
the trend's interior knots, knot_every; the AR(1) coefficients persistence and the AR(1)'s
shares of the errors' variance share, each pair of them an error model, with white errors
once more where white; and the promoted weeks' variance ratios promoted, each crossed with
every one of those.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a knot spacing below a week, a coefficient outside (0, 1), a share outside (0, 1], a ratio that is not positive and finite, or no error model. |
knot_every = MIXTURE_KNOT_EVERY
class-attribute
instance-attribute
¶
persistence = PERSISTENCE
class-attribute
instance-attribute
¶
share = SHARE
class-attribute
instance-attribute
¶
promoted = PROMOTED
class-attribute
instance-attribute
¶
white = True
class-attribute
instance-attribute
¶
pairs()
¶
Each error model's (rho, omega): white errors first where white, then every
coefficient with every share.
models()
¶
Every error model's (rho, omega, h), in the order the fits are stacked.
NestedFit(spec, stage_one, stage_two, mediated_log_likelihood)
dataclass
¶
Both stages' posteriors over one geo's window: stage_one the mediator's, its returns in
the mediator's units per currency unit, its spec's priors those it was drawn under, and
stage_two the KPI's, the mediator's coefficient among its controls'. Their draws pair index
by index.
mediated_log_likelihood is each draw's log density of each lift on the KPI of a channel of
stage one, which reads both stages, in the KPI's units, (chains, draws, lifts): channel by
channel in stage one's order, and each channel's in the order given. Where the fit read such a
lift, the stages were drawn as one model, and each stage's divergent and e_bfmi are its
sampler's.
spec
instance-attribute
¶
stage_one
instance-attribute
¶
stage_two
instance-attribute
¶
mediated_log_likelihood
instance-attribute
¶
mediator_coefficient()
¶
The KPI's rise per unit of the mediator at each draw, (chains, draws).
roi()
¶
Each channel's return on the KPI over the window at each draw, (chains, draws): its
direct return, where stage two has the channel, plus the mediator's coefficient times its
return on the mediator, where stage one has it.
channels()
¶
Each channel's return on the KPI as chc.response reads it, at its parameters'
posterior medians: a channel of stage two as that stage reads it, and one of stage one as
stage one reads it, its coefficient times the mediator's.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a channel in both stages, whose return is a sum of two curves, which the planner does not read. |
channel_draws(count)
¶
Each channel's return on the KPI as channels composes it, at count draws of both
stages, evenly spaced as BayesFit.channel_draws reads them and paired index by index: a
stage-one channel's coefficient times the mediator's at the same draw.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a channel in both stages, and a count below 1 or above the fit's draws. |
NestedSpec(mediator, stage_one, stage_two)
dataclass
¶
The two stages and the control of the panel that mediates between them. A stage-one
channel left at the engine's default return prior, RoiPrior(), or at HalfNormalRoi(),
reads it at the mediator's scale, as the module states. The default is told apart by
equality, so RoiPrior() or HalfNormalRoi() stated by hand is moved too; a prior meant in
the mediator's own units is stated with numbers of its own.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a stage one that reads the mediator, as a channel or a control, on a stage two that does not read it as a control held at or above 0, on a return prior that counts the carried return, and on a stage that states its kernels' length, since each stage's kernels are as long as the longest series either reads. |
Calibration(estimates, weight)
dataclass
¶
Control(column, lower=-math.inf, upper=math.inf)
dataclass
¶
FourierSeason(period, harmonics)
dataclass
¶
Harmonics 1 to harmonics of a season period periods long (52.18 weeks to a year is
allowed), counted from the window's first period: season_cos_h and season_sin_h each.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a period of 2 or less, or a harmonic at or past half the period, which the periods cannot tell from a slower one. |
LinearTrend(knots=0)
dataclass
¶
A line through the window's periods, bent at knots points spaced evenly inside it: the
period's place t in the window, trend, and a hinge max(0, t - knot) for each knot,
trend_bend_1 on.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a negative number of knots. |
Media(channel, adstock, hill)
dataclass
¶
RidgeFit(spec, dates, y, fitted, design, intercept, coefficients, bound, half_saturation, contributions, estimated, spend, length, calibration=None)
dataclass
¶
The model fitted to one geo over a window of the panel's calendar.
Arrays run over the window's periods. fitted marks those the regression read, where the KPI
was observed. design holds the terms' columns, each channel's saturated, and contributions
each term's coefficient * column; estimated is their sum with the intercept, NaN where a
control is missing. half_saturation is each channel's K,
bound whether each coefficient sits on a bound, and spend each channel's spend over the
window. length is the panel's number of periods, the length of the kernels channels hands
on. calibration is how geo tests entered the fit, if any did.
spec
instance-attribute
¶
dates
instance-attribute
¶
y
instance-attribute
¶
fitted
instance-attribute
¶
design
instance-attribute
¶
intercept
instance-attribute
¶
coefficients
instance-attribute
¶
bound
instance-attribute
¶
half_saturation
instance-attribute
¶
contributions
instance-attribute
¶
estimated
instance-attribute
¶
spend
instance-attribute
¶
length
instance-attribute
¶
calibration = None
class-attribute
instance-attribute
¶
nrmse()
¶
Robyn's NRMSE: the root mean square error over the KPI's range, on the fitted periods.
decomp_rssd()
¶
Robyn's DECOMP.RSSD with its penalty on channels of no effect.
channels()
¶
Each channel as chc.response reads it, for the decisions.
RidgeSpec(media, controls, penalty, trend=None, season=None)
dataclass
¶
The model: its channels, its controls, its trend and season if any, and the ridge
penalty > 0.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a column named twice, a model with no channel, or a penalty that is not positive and finite. |
media
instance-attribute
¶
controls
instance-attribute
¶
penalty
instance-attribute
¶
trend = None
class-attribute
instance-attribute
¶
season = None
class-attribute
instance-attribute
¶
terms()
¶
The design's columns: the channels, the controls, the trend's and the season's.
calendar(periods)
¶
The trend's and the season's columns over a window of periods periods.
fit_bayes_geo(panel, spec, *, seed, window=None, estimates=None, chains=4, warmup=1000, draws=1000, start=_UNIFORM_START)
¶
Draw the posterior of spec on every geo of panel over window, its first and last
dates, by default the whole calendar, its likelihood holding estimates, each channel's lift
estimates, if given. Each of chains starts as start says, drawn from seed.
Raises:
| Type | Description |
|---|---|
ValueError
|
on what |
fit_bayes(panel, geo, spec, *, seed, window=None, tests=None, estimates=None, series=None, chains=4, warmup=1000, draws=1000, start=_PATHFINDER_START, coordinates=_NATURAL)
¶
Draw the posterior of spec on one geo of panel over window, its first and last dates,
by default the whole calendar, its likelihood holding tests, each channel's geo tests,
estimates, each channel's lift estimates, and series, each channel's lift series, if given.
Each of chains starts as start says, drawn from seed, on the sampler's coordinates.
Raises:
| Type | Description |
|---|---|
ValueError
|
on JAX in single precision; a geo or column the panel does not have, a window
off its calendar, a channel that spends nothing over it, fewer than two observed
periods or a mean KPI not above 0 over them, a KPI not above 0 at one of them under
log-normal noise, a control that does not vary over it; tests, estimates or series of a
channel the model does not have, or of none; estimates or series in a geo other than
|
fit_dlm(panel, geo, spec, prior=None, *, draws=1000, seed=0, estimates=None)
¶
Filter and smooth one geo of panel through the model spec describes.
prior is on the state in the order of spec.blocks(); by default it is vague_prior's.
With a signed effect, four chains of draws each, after as many of warm-up, are drawn from
the posterior truncated to the signs from seed; draws and seed are not read otherwise.
estimates, each channel's lift tests, each placed by its readout's end, condition the
posterior on their lifts as mixdyn.models.dlm_lift reads them; with a signed effect a test
reads a signed channel. An empty mapping reads none.
A control the panel declares a lever is read against its counterfactual level in the
decomposition (DlmFit.baselines); the states are those of the same fit without the
declaration.
Raises:
| Type | Description |
|---|---|
ValueError
|
on what |
forecast_dlm(fit, horizon, plan)
¶
Forecast the horizon periods after fit's data, every effect's column taken from plan.
The effects' future columns are given, not forecast: spend is a decision. A transformed
effect's plan is its spend, carried over from the spend the fit read and saturated, as its
column was. The first step's evolution variance is held for every later step, so a state's
variance grows linearly with the horizon rather than as discount ** -horizon. A coefficient
whose planned column is zero is held, as in the fit. A fit read with tests starts from the
state given them (DlmFit.last) and evolves as the KPI's filter does, each step's evolution
variance the filter's in units of the variance.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a fit with a signed effect, whose future coefficients keep their signs,
which a Student t forecast does not ( |
forecast_draws(fit, horizon, plan, draws, seed)
¶
draws draws of the KPI over the horizon periods after fit's data, the effects'
columns taken from plan as forecast_dlm takes them.
Each draw starts from the states and the variance at the last period given every period: the
filter's normal-gamma posterior there, or with a signed effect one of the fit's draws of the
posterior truncated to the signs, taken with replacement. It is carried through the horizon
by the model's evolution, the first step's evolution variance held for every later step as
forecast_dlm holds it, and the KPI drawn about each period's mean at the draw's variance. A
signed fit's path is kept only where every signed coefficient keeps its sign at every period
forecast, so the draws are the model's with the signs held over the horizon too, a start the
signs make unlikely to persist weighed down by just that chance. Without signs the draws
follow forecast_dlm's Student t.
A start meets the signs and a signed coefficient walks on its own, so it keeps its sign over
h periods with probability at least C(2h, h) / 4^h (Sparre Andersen), 0.155 at 13: the
paths drawn for each one kept number at most 6.5 in expectation with one signed effect at 13
periods, and 269 with three.
Raises:
| Type | Description |
|---|---|
ValueError
|
on |
vague_prior(panel, geo, spec)
¶
The engine's default prior: weakly informative, on the series' own scale.
Every coordinate has mean zero but the level, which starts at the KPI's mean. Each standard
deviation is ten times the scale of its coordinate's part of the forecast: the KPI's standard
deviation s for the level and the season, s / T for the slope over T periods, and
s / rms(x) for an effect. The variance is learned from one degree of freedom at s². The
KPI's mean and standard deviation are the only numbers the data supply twice.
Raises:
| Type | Description |
|---|---|
ValueError
|
on fewer than two observed periods, or a KPI that does not vary. |
choose_dlm(panel, geo, spec, grid, *, level=0.95, estimates=None)
¶
Filter spec on one geo at every discount of grid and choose by one-step likelihood;
fit the specs a likelihood-ratio test at level does not reject, for DlmChoice.bounds.
With a signed effect the likelihood is the model's without the signs, and only a kept spec's
fit draws its posterior truncated to them. Each end of the grid that a kept spec reaches where
the discount goes on past it is named in DlmChoice.edges and logged as a warning.
estimates, each channel's lift tests, enter each spec's likelihood, its tests' log density
given its KPI added to the filter's (DlmChoice.lifts), and each kept fit's posterior, as
fit_dlm reads them. The kept specs are those within chi2_p(level) / 2 of the best, as
chc.dlm.confidence_set keeps them, on that likelihood.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a |
RuntimeError
|
on a kept spec's sampler that stops from every seed it starts from. |
decompose_dlm(fit, *, draws, seed)
¶
Draw fit's states given all its data, draws times, and split each draw's mean into the
base, the seasonality and each effect's contribution.
With a signed effect the draws are draws of the fit's own (fit.signed), chosen without
replacement from seed: the decomposition and its point estimate then come from one run,
the one diagnose_dlm checks for mixing. A fit read with tests draws its posterior given them.
A lever's contribution is each draw's coefficient times its departure from its level
(DlmFit.baselines), and the base takes the coefficient times the level.
Raises:
| Type | Description |
|---|---|
ValueError
|
on |
diagnose_dlm(fit, arl=1000.0)
¶
Test fit's one-step errors, watch them for drift, and check its decomposition.
Ljung-Box runs over min(10, n // 5) lags for n observed periods.
Raises:
| Type | Description |
|---|---|
ValueError
|
on fewer than ten observed periods, or an |
search_media(panel, geo, spec, grid, discounts, *, refinements=1, level=0.95, fitted=None, estimates=None, half_saturation_prior=None)
¶
Choose each transformed effect's transform on grid and the discounts on discounts by
the one-step log-likelihood on one geo, and fit every spec filtered that a likelihood-ratio
test at level does not reject, or with fitted at most that many of them.
With half_saturation_prior, each channel's half-saturation point is given a log-normal prior
of that scale and median the channel's mean positive spend, the grid's unit, as the static
Bayesian model's K_m (mixdyn.models.bayes_mmm): its log density on the log of the multiple,
-(log m)^2 / (2 s^2), is added to every spec's score, so the search, its best and its kept
set read the posterior's mode and not the likelihood's where the likelihood is flat (ADR 0085).
The grid is even in log m, so the density is that of log m and needs no Jacobian.
estimates, each channel's lift tests, enter every spec's likelihood, their log density given
the KPI added to its one-step log-likelihood (DlmChoice.lifts), so the search, its best and
its kept set read them, and every fitted spec's posterior is given them (fit_dlm).
Each effect that carries a transform in spec is a channel the search moves; its kernel keeps
the transform's length. The search starts at the grid point nearest each channel's transform,
the nearest retention, the nearest half-saturation point by ratio and the transform's shape if
the grid has it, else the grid's first; and it moves in blocks, each to its best spec:
- the discounts, over the whole discount grid or with
PerEffectin its blocks (DiscountGrid.blocks), then each channel in turn over the grid's product of retentions, half-saturations and shapes, the rest held, until a pass moves nothing; refinementstimes, each interval of the grid halved again (TransformGrid.refined), and the passes repeated with each channel's block the three retentions and three half-saturation points about its point, nine at every shape.
A move raises the likelihood and a level's grid is finite, so each stage ends, at a point no
block improves. The kept specs are the filtered ones within chi2_p(level) / 2 of the best
log-likelihood, p counting each axis the grid varies once a channel and each discount the
discount grid varies (DiscountGrid.parameters). A spec the search did not filter is not
kept, however near the best. Each end of either grid that a kept spec reaches where the
parameter goes on past it, a discount's, a retention's or a half-saturation point's, is named
in DlmChoice.edges and logged as a warning.
With fitted, the kept specs fitted are those at evenly spaced ranks of their log-likelihood,
rank floor(i (N - 1) / (fitted - 1)) of the N kept for i from 0, the best first and the
last kept last (ADR 0023): the choice holds every kept spec and its filter, and its readings
are a sample of their mixture, stratified by likelihood.
Each move is logged at debug level with the log-likelihoods it goes between; each stage's end
and the kept set at info.
Raises:
| Type | Description |
|---|---|
ValueError
|
on refinements that are not a whole number at or above 0, a |
RuntimeError
|
on a fitted spec's sampler that stops from every seed it starts from. |
transforms_from_bayes(fit)
¶
Each channel's transform at its parameters' posterior medians, by channel, as
BayesFit.channels reads them: its retention, its half-saturation point, its curve, a Hill's
slope at its median, and the fit's kernel length.
fit_geo_dlm(panel, spec, prior=None, *, draws=64, seed=0, level=0.9)
¶
Fit spec to every geo of panel, the geos' spread chosen by the marginal likelihood.
prior is on the stacked state, the national coefficients and then each geo's regional
coordinates in the order of spec.regional(); by default it is vague_geo_prior's. draws
spreads are drawn from their posterior with seed, and each spread's interval is at level.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a panel of one geo, which has nothing to pool, and on what
|
geo_effects(fit, level=0.9)
¶
Each geo's coefficients at the last period, the national one plus its deviation, with the spread's uncertainty: their mixture over the spread's draws, read as one Student t with the mixture's variance and the last step's degrees of freedom.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a level outside (0, 1). |
vague_geo_prior(panel, spec)
¶
The engine's default prior over geos: weakly informative, on each geo's own scale.
A geo's level starts at its KPI's mean, and every other coordinate at zero. Each standard
deviation is ten times the scale of its coordinate's part of the forecast, as vague_prior's:
the geo's KPI standard deviation s_g for its level and season, s_g / T for its slope, and
s / rms(x) for a national coefficient and for every geo's deviation from it, s the geos'
root mean square s_g and rms(x) over every geo. The deviations' variance is the vaguest
spread fit_geo_spread considers.
The variance is learned from one degree of freedom, its guess each geo's least-squares residual variance over its relative weight, averaged over the geos. A prior's covariance is stated at that guess, so a guess of the KPI's whole variance would tighten every coordinate's prior by the noise's share of it once the variance is learned, and with it the vaguest spread.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a geo whose KPI does not vary over two observed periods, or no geo observed in more periods than its least-squares design has columns. |
fit_pooled_geos(panel, estimates, length)
¶
The model over geos (the module) fitted to panel with each channel's lift estimates,
its kernel length weeks long.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a panel without populations, with controls, events, filled steps or a KPI
that is not finite, a channel split nationally other than by population, a kernel
shorter than a week or one that leaves no residual degree of freedom, a channel whose
spend no geo's nuisance leaves |
FloatingPointError
|
on a marginal likelihood that is not finite, as where the KPI's squares overflow. |
fit_margins(sales, spend, promotion, price, kernel, *, noise=MIXTURE)
¶
Each channel's margin over the weekly history: sales (weeks,), spend
(weeks, channels), the promotion flag and the price (weeks,), either None where the
history holds none, and the adstock's kernel length in weeks; under the mixture of error
models noise, MIXTURE by default, and with None as the research code fitted it, whose
margins the sales' level moves. See the module.
Raises:
| Type | Description |
|---|---|
ValueError
|
on arrays of other shapes, a value that is not finite, or a kernel shorter
than a week; under |
DegenerateFitError
|
where the data leave the fit degenerate (the module). |
MemoryError
|
under |
fit_nested(panel, geo, spec, *, seed, window=None, estimates=None, mediator_estimates=None, chains=4, warmup=1000, draws=1000, start=_PATHFINDER_START)
¶
Draw both stages' posteriors on one geo of panel over window, its first and last dates,
by default the whole calendar, as nested_model reads estimates, each channel's lift
estimates on the KPI, and mediator_estimates, each channel's on the mediator: apart, each
stage from a seed spawned from seed, or, where a lift on the KPI is of a channel of stage
one, as one model from a third. The models are built before anything is drawn, so what either
refuses is refused before any sampling.
Raises:
| Type | Description |
|---|---|
ValueError
|
on what |
fit_ridge(panel, geo, spec, window=None, tests=None)
¶
Fit spec to one geo of panel over window, its first and last dates, by default the
whole calendar, calibrated by tests, each channel's geo tests, if given.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a geo or column the panel does not have, a window off its calendar, a channel dark over the whole window, or fewer than two fitted periods; tests of a channel the model does not have, tests that move no saturated spend, or tests with no noise left to weigh them by. |