Detecting hidden periodicities

Today let's settle the question this periodogram raises: is that tall spike a real cycle, or something pure noise could throw up on its own?

Northside Diner is the same lunch restaurant as before, seventy days of lunch covers, averaging 119.2 a day with a standard deviation of 25.4. Its periodogram has 35 ordinates, and two of them tower over the rest. The tallest sits at frequency 1/7, the exact frequency of a real weekly cycle, with an ordinate of 14,997.4. The next tallest sits at frequency 2/7, a smaller cycle repeating every 3.5 days, with an ordinate of 3,576.7.

Toggle between line and point to look at that periodogram one more time. One ordinate stands forty times taller than the next one down, and the rest sit near the floor. This lesson gives you a real test for how tall is too tall to be chance, and shows what happens to a genuine cycle that runs faster than your data was ever sampled to catch.

Rebuild the data and meet Fisher's g-statistic

Start by rebuilding Northside Diner's series and its periodogram, since every number in this lesson grows out of them.

RInteractive R
# Rebuild Northside Diner's 70 days of lunch covers, then run the periodogram set.seed(2024) day <- 1:70 baseline <- 120 fundamental <- 30 * cos(2 * pi * (day - 5) / 7) harmonic <- 12 * cos(4 * pi * (day - 5) / 7) noise <- rnorm(70, 0, 10) northside_covers <- round(baseline + fundamental + harmonic + noise) pg <- spec.pgram(ts(northside_covers), taper = 0, detrend = FALSE, demean = TRUE, fast = FALSE, plot = FALSE) total_power <- sum(pg$spec) g_obs <- max(pg$spec) / total_power round(total_power, 2) round(max(pg$spec), 1) round(g_obs, 3) #> [1] 22223.06 #> [1] 14997.4 #> [1] 0.675

  

Every ordinate in a periodogram measures a slice of the series' total variation, so adding up all 35 of them, total_power, gives the whole amount of variation there is to explain. The tallest ordinate, 14,997.4, is one slice of that total. Divide one by the other and you get g_obs, 0.675: the tallest ordinate's share of everything the periodogram found. That share is called Fisher's g-statistic, named for the statistician who worked out how to test it.

If Northside Diner's series were pure noise, with no real cycle in it at all, the 35 ordinates would carry roughly equal shares of the total power, about 1/35, or 2.9%, each. g_obs of 0.675 is nowhere near that: one ordinate alone is carrying 67.5% of everything. So here is the real question: is 67.5% actually too much for chance, or could a single noisy ordinate occasionally get that lucky on its own?