レッスン
理論 — フィルタとしての移動平均
M項移動平均は、時系列データの各値を連続するM個の値の平均に置き換えます。これは 1/M の重みを持つ長さ M の箱型関数との畳み込みです。したがって畳み込み定理により、1サンプルあたり f サイクルの周期に与える影響は、箱型関数のフーリエ変換である利得 H(f) = sin(πfM)/(M sin πf) との掛け算になります。H は f = 1/M, 2/M, … でゼロとなり、最初のゼロ点から次のゼロ点までの間ではマイナスになります。各平均値を区間の中央に配置したとき、H は実数となります。区間の最後に配置した場合は、同じ値であっても (M − 1)/2 サンプル分の遅れが生じます。
各記号の意味
M- 各区間で平均する日数
f- 周期の周波数(サイクル/日)。0 から ½ まで
H(f)- 利得:平均化によって周波数 f の周期が何倍になるか。マイナスは反転を意味する
- 前提
- 欠測のない1日1値のデータ。これにより、区間は常に暦日でのM日間にまたがります。周期を打ち消すには、報告された値そのものが7日ごとに繰り返される必要があります。常に一定の報告の遅れであれば、週ごとの繰り返しは保たれるため何も変わりません。しかし、欠測日や祝日、あるいは週ごとに変動する遅れがあると、この前提は崩れます。
全プロセスの詳細解説
-
平均の平均 4 ステップ
7日平均は5日の変動を上下逆さまにします。そこで同僚が、7日平均に対してさらに7日平均をとることを提案してきました。このとき5日の波はどうなるでしょうか。週周期はどうなりますか。また、2回目の平均をかける代償は何でしょうか。 まずは5日の波を押してください。ページには1回目の処理での利得が表示されています。
-
ページから読み取れる1回目の処理での利得:
-
2回目の処理では、同じ利得を波にもう一度掛け合わせます。マイナスとマイナスを掛けるとプラスになります:
-
これら2回の処理を合わせると、箱型関数をそれ自身と畳み込んだ、三角形の重みを持つ13日間の平均になります:
-
電力が半減する点は、1回処理時の H² = ½ から、2回処理時の H⁴ = ½ へと移動します:
解答
5日の波は元の大きさの0.0534倍になり、反転せずに現れます。週周期は 0 × 0 = 0 なので引き続き消去されたままです。 その代償は、より遅い周期の波まで鈍らせてしまう平滑化フィルタになることです。電力が半減する周期は15.66日から21.74日へと延びます。また、中心化するためには片側3日ではなく6日必要になるため、データの6日前に途切れてしまいます。ヒンドマンとアサナソプロスはこうした処理を「移動平均の移動平均」と呼んでおり、彼らの例では3×3-MAでしたが、ここでは7×7-MAとなります。
-
学習の道すじ
フーリエ変換の実際
参考文献 (3)
- The source of the page's real series: the daily difference of Germany's cumulative confirmed cases in the JHU CSSE COVID-19 Data Repository, licensed CC BY 4.0, with the dashboard paper its terms of use ask users to cite: COVID-19 Data Repository by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University, time_series_covid19_confirmed_global.csv (archived 10 March 2023). E. Dong, H. Du and L. Gardner, An interactive web-based dashboard to track COVID-19 in real time. The Lancet Infectious Diseases 20(5), 533–534 (2020). doi:10.1016/S1473-3099(20)30120-1
- The moving average as a convolution with a rectangular pulse, the centred and one-sided forms, and its frequency response H[f] = sin(πfM)/(M sin πf) (equation 15-2), with the verdict the second insight quotes: "an exceptionally good smoothing filter", "an exceptionally bad low-pass filter": S. W. Smith, The Scientist and Engineer's Guide to Digital Signal Processing. California Technical Publishing (online edition, © 1997–2011). Chapter 15, Moving Average Filters.
- The m-MA of a time series, why symmetric moving averages have odd order, the 2×m-MA for an even seasonal period, the statement that "a 7-MA can be used to estimate the trend-cycle of daily data with a weekly seasonality" while other orders leave the estimate contaminated by the seasonality, and moving averages of moving averages (the 3×3-MA), which the worked problem extends to 7×7: R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice, 3rd edition. OTexts, Melbourne, 2021. Section 3.3, Moving averages.