Skip to content

mixdyn.calibration

Experiments as the models read them: lift tests in the likelihood, summed or period by period, and lift tests read from the tables other tools take them in.

Estimates = dict[str, tuple[LiftEstimate, ...]]

Lift estimates by channel, as the models take them.

LiftEstimate(spend, planned, readout, lift, se, share=1.0, geos=None, end=None) dataclass

A lift test of one channel as its analysis reported it.

spend is the tested group's spend on the channel as the test ran, over the periods before the readout and the readout, and planned what the group would have spent without the test, over the same periods; the last readout periods are the readout. lift is the group's KPI over the readout less what it would have been at planned, as the analysis estimated it, in the KPI's units, and se that estimate's standard error. geos are the geos the test ran in, and None, the default, the whole market the model reads: every geo of the model over geos, the one geo of a model of one. share is the group's share of those geos' market: the group's spend and lift over it are theirs.

end is the date of the readout's last period in the panel's calendar, so the series' last period: a model whose coefficient moves over time (mixdyn.models.fit_dlm) reads the test at those periods and refuses an estimate without it. A model whose coefficient is one number over the window reads no calendar and passes it by.

Raises:

Type Description
ValueError

on a spend not finite and at or above 0, spend and planned of different lengths or the same, a readout not within them, a lift not finite, a standard error not positive and finite, a share outside (0, 1], no geo named, or an end that is not a date.

spend instance-attribute

planned instance-attribute

readout instance-attribute

lift instance-attribute

se instance-attribute

share = 1.0 class-attribute instance-attribute

geos = None class-attribute instance-attribute

end = None class-attribute instance-attribute

LiftSeries(spend, planned, gaps, covariance, share=1.0, geos=None) dataclass

A lift test of one channel read period by period: LiftEstimate's test with its lift over each period of the readout rather than summed.

spend, planned, share and geos are LiftEstimate's. gaps is the group's KPI in each of the readout's periods less what it would have been at planned, so the readout is its last gaps.size periods, and covariance the covariance of those gaps' errors, in the KPI's units squared: a geo's noise that carries over from one period to the next correlates them (mixdyn.experiments.PlaceboNoise.covariance reads it from the history).

summed is the test as one estimate: the gaps' sum with the error of that sum.

Raises:

Type Description
ValueError

on what LiftEstimate refuses of the spend, the share and the geos; gaps not a non-empty vector of finite numbers or longer than the spend; and a covariance not of the gaps' size, not finite, not symmetric to 1e-12 of its largest entry, or not positive definite. A covariance within that is held as its symmetric part.

spend instance-attribute

planned instance-attribute

gaps instance-attribute

covariance instance-attribute

share = 1.0 class-attribute instance-attribute

geos = None class-attribute instance-attribute

readout property

The periods the gaps cover, the spend's last.

summed property

The test as one estimate: the lift summed over the readout, its standard error the sum's under the covariance.

experiment_table(panel, estimates)

Lift estimates as experiments' records, the columns read_experiments reads with its estimate a lift: each estimate's lift and standard error, the window its spend changed over by its first and last dates, the periods read after it, its spend and planned spend a period over the window, its geo where it ran in one and its share of the market.

Raises:

Type Description
ValueError

on an estimate not placed in the calendar, whose readout does not start where its spend changes, whose planned spend is not one level, whose changed spend is not one level over consecutive periods, or that ran in more than one geo.

lift_table(panel, estimates, *, periods, cooldown=0)

Lift estimates as PyMC-Marketing's lift table, the columns read_lift_table reads: each estimate's lift a changed period and its standard error a changed period, its spend before the test and the change. A geo column where any estimate ran in one geo, and a date column, its first changed period's, where any estimate is placed in the calendar.

Raises:

Type Description
ValueError

on an estimate whose readout is not periods changed periods then cooldown at its planned spend, whose planned spend is not one level, whose changed spend is not one level, that ran in more than one geo or in a share of the market, or that is placed in the calendar beside one that is not.

read_experiments(panel, records, *, per_unit=False)

Geo experiments' records as lift estimates on panel: each record a test of channel whose group spent spend a period against planned over its window, the periods from start to end on the panel's calendar, its lift read over the window and cooldown periods after it at planned, none where the column is absent. Its estimate and standard_error are the lift, or, where per_unit, the incremental KPI a currency unit of the spend the window changed, which they are multiplied by. A geo column names the geo the group is, the whole market where absent, and a share column its share of that market, 1 where absent.

Raises:

Type Description
ValueError

on a column of the seven missing or not one-dimensional, columns of different lengths or no row; a channel or a geo the panel does not have; a start or an end that is not one of the panel's dates, or an end before the start; a cooldown that is not a whole number at least 0; and what LiftEstimate refuses of a record, the row named.

read_lift_table(panel, table, *, periods, cooldown=0, geo='geo', date='date')

PyMC-Marketing's lift table as lift estimates on panel: each row a test that changed the spend from x to x + delta_x a period for periods periods, its lift read over those and cooldown periods after at x, delta_y times periods and its standard error sigma times periods. A geo column names the geo each test ran in, the whole market where absent, and a date column its first changed period, on the panel's calendar.

Raises:

Type Description
ValueError

on a column of the five missing or not one-dimensional, columns of different lengths or no row; periods not a whole number at least 1 or cooldown at least 0; a channel or a geo the panel does not have; a date that is not one of the panel's; and what LiftEstimate refuses of a row, the row named.