YearlyFourier.apply#

YearlyFourier.apply(dayofperiod, sum=True)[source]#

Apply fourier seasonality to day of year.

Must be used within a PyMC model context.

Parameters:
dayofperiodXTensorLike

Day of year or weekday

sumbool, default True

Whether to sum the fourier contributions.

Returns:
XTensorVariable

Fourier seasonality

Examples

Save the per-component result before summing through the prefix dimension by passing sum=False and registering a Deterministic on the un-summed tensor.

import pandas as pd

import pymc as pm
import pymc.dims as pmd

from pymc_marketing.mmm import YearlyFourier

fourier = YearlyFourier(n_order=3)

dates = pd.date_range("2023-01-01", periods=52, freq="W-MON")

coords = {"date": dates}
with pm.Model(coords=coords) as model:
    dayofyear = pmd.Data(
        "dayofyear", dates.dayofyear.to_numpy(), dims=("date",)
    )
    components = fourier.apply(dayofyear, sum=False)
    pmd.Deterministic(
        "fourier_trend", components, dims=("date", fourier.prefix)
    )