Lesson 2.3Module 2: Seeing patterns35 minBeginner

Additive or multiplicative? Letting the data decide

Does a season add a fixed amount, or multiply by a fixed factor? Learn to tell the two apart, why logs turn one into the other, and how to test which fits. Then test it on the Christmas song, where the answer is a surprise.

Part of the free course Music as Data: Time Series with Python · taught by Terence D. Agbeyegbe and Tone Agbeyegbe

In lesson 2.2 you split a series into trend, season and noise. But there are two different ways those parts can fit together. A season can add a fixed amount (every December brings 20,000 extra views), or it can multiply (every December brings three times the usual views). The choice changes every number your analysis produces. This lesson shows how to tell them apart, and then tests the Christmas song from lesson 2.2. The answer isn't what we assumed.

Two recipes

An additive series adds its parts together:

views = trend + season + noise

A multiplicative series multiplies them:

views = trend × season × noise

The difference shows up as the trend grows. In an additive series, the season always adds the same amount, so the seasonal spikes stay the same height while the trend climbs. In a multiplicative series, the season is a percentage of the trend, so the spikes grow as the trend grows. Here are both, built from the same trend:

Python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

months = pd.date_range("2020-01-01", periods=72, freq="MS")          # six years, monthly
trend = np.linspace(10_000, 40_000, 72)                              # steady growth
bump = np.select([months.month == 12, months.month == 11], [1.0, 0.4], default=0.0)

additive = pd.Series(trend + 20_000 * bump, index=months)            # December adds 20,000
multiplicative = pd.Series(trend * (1 + 2.0 * bump), index=months)   # December triples the trend

fig, ax = plt.subplots(1, 2, figsize=(10, 3.4), sharey=True)
ax[0].plot(additive, linewidth=1.5)
ax[0].plot(months, trend, ":", color="C2")
ax[0].set_title("Additive: December always adds 20,000")
ax[1].plot(multiplicative, linewidth=1.5, color="C1")
ax[1].plot(months, trend, ":", color="C2")
ax[1].set_title("Multiplicative: December triples the trend")
ax[0].set_ylabel("Views per month")
plt.tight_layout()
plt.show()
Two charts with the same dotted trend line rising from 10,000 to 40,000. On the left, the December spikes stay the same height above the trend. On the right, they grow taller every year.
Two charts with the same dotted trend line rising from 10,000 to 40,000. On the left, the December spikes stay the same height above the trend. On the right, they grow taller every year.

In the first December the two are already apart (about 35,000 against 44,000), and by the sixth the gap is huge: about 60,000 for the additive series, about 120,000 for the multiplicative one.

Music data is often multiplicative. If a song gets 12% more streams on Fridays, that's 12% whether it's getting 1,000 streams a day or a million. But it isn't always, which is why it's worth testing.

Logs turn multiplying into adding

There's a neat trick for multiplicative series. The logarithm turns multiplication into addition: log(a × b) = log(a) + log(b). So if

views = trend × season × noise

then

log(views) = log(trend) + log(season) + log(noise)

A multiplicative series becomes additive on the log scale. That's why lesson 2.2 worked with np.log(monthly): all the additive tools (moving averages, subtracting seasonal averages) then work unchanged.

Python
fig, ax = plt.subplots(1, 2, figsize=(10, 3.2))
ax[0].plot(np.log(additive), linewidth=1.5)
ax[0].set_title("log(additive): spikes shrink as the trend grows")
ax[1].plot(np.log(multiplicative), linewidth=1.5, color="C1")
ax[1].set_title("log(multiplicative): spikes stay the same height")
plt.tight_layout()
plt.show()
Two charts of the logged series. On the left, the December spikes get smaller each year. On the right, they stay the same height.
Two charts of the logged series. On the left, the December spikes get smaller each year. On the right, they stay the same height.

The trick cuts both ways. Logging a multiplicative series makes the spikes even. Logging an additive series makes the spikes shrink, which turns a correct additive model into a wrong multiplicative one. Logs aren't automatically right. They encode an assumption.

You've met this before without knowing it. Decibels are a log scale. When lesson 2.1 said loudness rose by 4.5 dB, that was a difference of logs, which means a ratio of sound levels. Adding in decibels is multiplying in sound.

A test: does the season scale with the level?

So how do you decide? Measure the size of the season each year in both ways, as a difference and as a ratio, and see which one stays constant while the level changes. Here's a function that compares each year's peak month with its quiet summer months:

Python
def season_size(monthly, peak=12, quiet=(6, 7, 8)):
    """For each year: the quiet-season level, and the peak month as a difference and as a ratio."""
    y = monthly.index.year
    peak_value = monthly[monthly.index.month == peak].groupby(y[monthly.index.month == peak]).sum()
    quiet_level = monthly[monthly.index.month.isin(quiet)].groupby(y[monthly.index.month.isin(quiet)]).mean()
    return pd.DataFrame({"quiet_level": quiet_level,
                         "difference": peak_value - quiet_level,
                         "ratio": peak_value / quiet_level}).round(1)


print("Additive series:")
print(season_size(additive))
print("Multiplicative series:")
print(season_size(multiplicative))

For the additive series, the difference is exactly the same every year (22,113: the 20,000 December bump plus the trend's rise between summer and December) while the ratio falls from 2.8 to 1.6. For the multiplicative series, the ratio stays nearly constant (3.5 down to 3.2, again nudged by the trend's rise within each year) while the difference more than doubles. Whichever measure stays put tells you which recipe you're looking at.

Testing the Christmas song

Now the real data. Load the daily Wikipedia page views from lesson 2.2 (download christmas_pageviews.csv if you don't have it) and run the same test:

Python
views = pd.read_csv("christmas_pageviews.csv", index_col="date", parse_dates=True)["views"]
monthly = views.resample("MS").sum()

real = season_size(monthly)
print(real.astype({"quiet_level": int, "difference": int}))

Look at the table before reading on. Which column stays steadier?

Python
fig, ax = plt.subplots(1, 2, figsize=(10, 3.6))
ax[0].scatter(real["quiet_level"], real["difference"] / 1000, color="C0", s=36)
ax[0].set_title("December minus summer (additive)")
ax[0].set_ylabel("Thousands of views")
ax[1].scatter(real["quiet_level"], real["ratio"], color="C1", s=36)
ax[1].set_title("December ÷ summer (multiplicative)")
ax[1].set_ylabel("Ratio")
for a in ax:
    a.set_xlabel("Summer level (views per month)")
    for year, r in real.iterrows():
        a.annotate(str(year)[2:], (r["quiet_level"], r["difference"] / 1000 if a is ax[0] else r["ratio"]),
                   xytext=(4, 3), textcoords="offset points", fontsize=7)
plt.tight_layout()
plt.show()

print("Correlation of summer level with the difference:", round(real["quiet_level"].corr(real["difference"]), 2))
print("Correlation of summer level with the ratio:     ", round(real["quiet_level"].corr(real["ratio"]), 2))
Two scatter plots against the summer level. On the left, the December difference ranges from about 260,000 to 470,000, rising only loosely with the summer level. On the right, the December ratio falls steeply from about 49 to about 19 as the summer level rises.
Two scatter plots against the summer level. On the left, the December difference ranges from about 260,000 to 470,000, rising only loosely with the summer level. On the right, the December ratio falls steeply from about 49 to about 19 as the summer level rises.

The result: the season does not scale with the level. Over the decade, the summer baseline more than doubled, but December views stayed in roughly the same range. So the ratio fell, from about 49 times the summer level in 2016 to about 19 to 30 times in recent years: it falls steadily as the baseline rises (a correlation of −0.8). The difference rises a little with the baseline, but only loosely (a correlation of 0.31). So the truth lies between the two recipes, much closer to additive: the Christmas peak grew a little as the song's year-round audience grew, but nowhere near in proportion.

What could explain it? This data can't say for certain, but one reading fits. The song's year-round fame grew, so more people looked it up in July. Christmas interest, though, may already have been close to its ceiling: there's only so much attention one song can get in December, however famous it becomes.

What this means for lesson 2.2

Lesson 2.2 decomposed the logged series, which assumes a multiplicative season: December multiplied by the same factor every year. If that assumption is wrong, the mistake has to show up somewhere, and the place to look is the noise. A correct model leaves noise with no pattern. Compare December's leftover noise under each model:

Python
weights = np.array([0.5] + [1] * 11 + [0.5]) / 12

def decompose(series):
    trend = series.rolling(13, center=True).apply(lambda w: np.dot(w, weights), raw=True)
    detrended = series - trend
    season = detrended.groupby(detrended.index.month).mean()
    season = season - season.mean()
    return detrended - season.reindex(detrended.index.month).values      # the noise

december = monthly.index.month == 12
noise_log = decompose(np.log(monthly))[december].dropna()
noise_add = decompose(monthly)[december].dropna()

fig, ax = plt.subplots(1, 2, figsize=(10, 3.4))
ax[0].bar(noise_log.index.year, noise_log.values, color="C1")
ax[0].set_title("Multiplicative (log) model: December leftovers")
ax[1].bar(noise_add.index.year, noise_add.values / 1000, color="C0")
ax[1].set_title("Additive model: December leftovers (thousands)")
for a in ax:
    a.axhline(0, color="grey", linewidth=0.8)
plt.tight_layout()
plt.show()
Two bar charts of December's leftover noise by year. On the left, the bars drift down from clearly positive in 2016 to negative from 2020 onwards. On the right, the bars are negative for 2016–18 and mostly positive after, with 2019 the largest.
Two bar charts of December's leftover noise by year. On the left, the bars drift down from clearly positive in 2016 to negative from 2020 onwards. On the right, the bars are negative for 2016–18 and mostly positive after, with 2019 the largest.

Under the multiplicative model, December's leftovers drift downward: clearly positive in the early years, negative from 2020 on. That's not noise, it's a pattern, and a pattern in the leftovers means the model is missing something. The model insists December is always the same multiple of the trend, so it overestimates recent Decembers and underestimates early ones. The additive model's leftovers are bigger and messier (2019, the year of the number one, stands out), and they lean the other way: below zero in the first three years, mostly above since. That's the small amount of growth in the Christmas peak that the additive model, with its fixed December bump, can't capture. Neither model is perfect, but the multiplicative one's error is larger and more systematic.

So lesson 2.2's decomposition got the broad picture right: the trend, the shape of the season and the big surprises. But its seasonal factors are an average over a decade in which the real factor was shrinking. When neither fixed recipe fits, as here, there's a third option: let the season itself change over time. Module 3 introduces a method that does exactly that.

A practical checklist

  • Plot first. Do the seasonal swings grow with the level? Then test it, as above, rather than assuming.
  • Logs need positive numbers. A series with zeros (like lesson 1.4's fading song) can't be logged directly. Drop the zeros or use np.log1p (log of 1 + x), and say so.
  • Read log changes as percentages. A change of 0.1 in a log is about a 10% change. A seasonal factor of 1.42 means 42% above the trend.
  • Check the leftovers. Whatever model you choose, its noise should have no pattern. If it does, the model is wrong.

Key ideas

  • Additive: the season adds a fixed amount. Multiplicative: it multiplies by a fixed factor, so seasonal swings grow with the trend.
  • Logs turn multiplicative into additive, which is why analysts log so often. But logging an additive series makes it wrong. Logs are an assumption, not a default.
  • Test it: measure the season each year as a difference and as a ratio. Whichever stays constant as the level changes tells you which model fits.
  • For the Christmas song, the baseline more than doubled but the Christmas peak barely grew: the truth lies between the two recipes, much closer to additive.
  • A wrong model shows up as a pattern in the leftovers.

Try it yourself

  1. Change the simulation's multiplicative December to 1 + 0.5 * bump. How much harder is it to tell the two recipes apart by eye? Does the season_size test still work?
  2. Run season_size on another seasonal song from lesson 2.2's exercises, such as "Last_Christmas". Additive or multiplicative?
  3. Use November instead of December as the peak (season_size(monthly, peak=11)). Does November tell the same story?
  4. Decibels are logs. If one track is 6 dB louder than another, how many times larger is its waveform? (Hint: decibels for waveform size are 20 × log10 of the ratio.)

Next: Module 3 begins with Decomposition: classical and STL, and a season that changes, where the Christmas season is finally allowed to shrink.

The course

Music as Data: Time Series with Python

Course home
  1. 1Music as a time series

  2. 2Seeing patterns

  3. 3Decomposition and stationarity

  4. 4Testing a time series

  5. 5Missing values

    • 5.1Handling missing values in music data coming soon
  6. 6Autocorrelation and forecasting

    • 6.1Autocorrelation: finding the beat coming soon
    • 6.2Partial autocorrelation and lag plots coming soon
    • 6.3How forecastable is a hit? coming soon
  7. 7Smoothing and Granger causality

    • 7.1Smoothing: moving averages and loudness envelopes coming soon
    • 7.2Granger causality: does social-media buzz predict streams? coming soon
  8. 8From time series to AI music

    • 8.1From forecasting to generating: how AI music models predict what comes next coming soon