Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Fourier Series (Spectral) Analysis. 2 Fourier Series Analysis Suitable for modelling seasonality and/or cyclicalness Identifying peaks and troughs.

Similar presentations


Presentation on theme: "1 Fourier Series (Spectral) Analysis. 2 Fourier Series Analysis Suitable for modelling seasonality and/or cyclicalness Identifying peaks and troughs."— Presentation transcript:

1 1 Fourier Series (Spectral) Analysis

2 2 Fourier Series Analysis Suitable for modelling seasonality and/or cyclicalness Identifying peaks and troughs

3 3 A sine wave is a repeating pattern that goes through one cycle every 2  (i.e. 2  3.141593 = 6.283186) units of time. For example, X01.573.144.716.28 Y = sin (x)010– 10

4 4 So sin (6.283186 + x) = sin (x)

5 5 Since Wave Phase Shifts Y = sin (x) Z = sin (x + 1.5708) 0.5  (phase shift)

6 6 Amplitude Y = 25 sin (x) Amplitude

7 7 Combining Amplitude, Phase, Frequency and Wavelength Y t = A*sin(2  ft +  ) where t=Time (i.e., 1, 2, 3, …, n) Y t =Value of time series at time t A=Amplitude f=Number of cycle per observation n=Number of observations in time series 2  =one complete cycle  =Phase shift

8 8 Amplitude determines the heights of peaks and depths of troughs Phase shift determines where the peaks and troughs occur Let be the wavelength, i.e. the number of periods from the beginning of one cycle to the next.

9 9 0 0n n 

10 10 SeriesAfPnL Z3004/481.57084812 Y2004/4804812

11 11

12 12 How to fit a single sine wave to a time series? Consider the following data set: Year Quarter 1234 20021.520.81 20030.631.061.460.80 20040.710.981.500.85 20050.651.041.470.85 20060.720.951.370.91 20070.740.98 n = 20 Assume one cycle completes itself every year, then f = 5/20 and L = 4

13 13 So the model is : This equation cannot be estimated by standard techniques.

14 14 But note that

15 15

16 16 So the model becomes: tYtYt 11.5210 20.810– 1 200.9801

17 17 data fourier1; input y @@; cards; 1.52 0.81 0.63 1.06 1.46 0.80 0.71 0.98 1.50 0.85 0.65 1.04 1.47 0.85 0.72 0.95 1.37 0.91 0.74 0.98 ;run; data fourier2; set fourier1; pi=3.1415926; t+1; s5=sin(pi*t/2); c5=cos(pi*t/2); run; proc reg data=fourier2; model y = s5 c5; output out=out1 predicted=p residual=r; run; proc print data=out1; var y p r; run;

18 18 The SAS System The REG Procedure Model: MODEL1 Dependent Variable: y Number of Observations Read20 Number of Observations Used20 Analysis of Variance SourceDFSum of SquaresMean SquareF ValuePr > F Model21.560100.7800584.52<.0001 Error170.156900.00923 Corrected Total191.71700 Root MSE0.09607R-square0.9086 Dependent Mean1.00000Adj R-Sq0.8979 Coeff Var9.60698 Parameter Estimates VariableDFParameter EstimateStandard Errort Value Pr >  t  Intercept11.000000.0214846.55<.0001 S510.387000.0303812.74<.0001 C510.079000.030382.600.0187

19 19 The SAS System Obsyp r 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1.52 0.81 0.63 1.06 1.46 0.80 0.71 0.98 1.50 0.85 0.65 1.04 1.47 0.85 0.72 0.95 1.37 0.91 0.74 0.98 1.38700 0.92100 0.61300 1.07900 1.38700 0.92100 0.61300 1.07900 1.38700 0.92100 0.61300 1.07900 1.38700 0.92100 0.61300 1.07900 1.38700 0.92100 0.61300 1.07900 0.13300 –0.11100 0.01700 –0.01900 0.07300 –0.12100 0.09700 –0.09900 0.11300 –0.07100 0.03700 –0.03900 0.08300 –0.07100 0.10700 –0.12900 –0.01700 –0.01100 0.12700 –0.09900 MAPE = 8.525%

20 20

21 21 Fitting a set of sine waves to a time series Amplitudes of peaks and troughs are rarely equal General Fourier series model: So, the general model is a linear combination of cycles at the “harmonic” frequencies, each with its amplitude (A j ) and phase shift (P j )

22 22 Assume n is even The highest harmonic, h, is if n is even and (n-1)/2 if n is odd. Harmonic, j Harmonic Frequency, Wavelength,

23 23 Note that when, and So,

24 24 The General Fourier series model contains n unknowns to be estimated with n observations, i.e. no degree of freedom !! The idea is NOT to use the General Fourier Series model for forecasting, but to use it for identifying significant cycles.

25 25 data fourier3; set fourier1; pi=3.1415926; t+1; s1=sin (pi*t/10); c1=cos (pi*t/10); s2=sin (pi*t/5); c2=cos (pi*t/5); s3=sin (3*pi*t/10); c3=cos (3*pi*t/10); s4=sin (2*pi*t/5); c4=cos (2*pi*t/5); s5=sin (pi*t/2); c5=cos (pi*t/2); s6=sin (3*pi*t/5); c6=cos (3*pi*t/5); s7=sin (7*pi*t/10); c7=cos (7*pi*t/10); s8=sin (4*pi*t/5); c8=cos (4*pi*t/5); s9=sin (9*pi*t/10); c9=cos (9*pi*t/10); s10=sin (pi*t); c10=cos (pi*t); run;

26 26 proc reg data=fourier3; model y = s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 s8 c8 s9 c9 c10; output out=out1 predicted=p residual=r; run; proc print data=out1; var y p r; run; proc spectra data=fourier1 out=out2; var y; run; data out2; set out2; sq=p_01; if period=. or period=4 then sq=0; if round (freq,.0001)=3.1416 then sq=.5*p_01; run; proc print data=out2; sum sq; run;

27 27 The SAS System The REG Procedure Model: MODEL1 Dependent Variable: y Number of Observations Read 20 Number of Observations Used 20 Analysis of Variance SourceDFSum of SquaresMean SquareF ValuePr > F Model191.717000.09037.. Error00. Corrected Total191.71700 Root MSE.R-Square1.0000 Dependent Mean1.00000Adj R-Sq. Coeff Var.

28 28 Parameter Estimates VariableDFParameter Estimate Standard Errort Value Pr > ︳ t ︱ Intercept11.00000... s11-0.000681000... c11-0.00026440... s210.00339... c210.01208... s31-0.00723... c310.01673... s41-0.02540... c410.00964... s510.38700... c510.07900... s610.00974... c61-0.02258... s710.03026... c71-0.03044... s81-0.00781... c81-0.00714... s910.00672... c91-0.00002737... c101-0.07700...

29 29 The SAS System Obsypr 11.52 2.1684E - 18 20.81 4.944E - 17 30.63 1.6534E - 16 41.06 4.944E - 17 51.46 1.4637E - 16 60.80 2.0914E - 16 70.71 2.6563E - 17 80.98 6.1908E - 17 91.50 1.03E - 16 100.85 6.0011E - 17 110.65 1.3623E - 16 121.04 2.7625E - 16 131.47 1.7445E - 16 140.85 2.7934E - 16 150.72 1.912E - 16 160.95 1.165E - 16 171.37 2.5013E - 16 180.91 2.2503E - 16 190.74 1.4246E - 16 200.98 5.8059E - 17

30 30 The SAS System ObsFREQPERIODP_01sq 10.00000.40.00000.00000 20.3141620.00000.00000.00001 30.6283210.00000.00160.00157 40.942486.66670.00330.00332 51.256645.00000.00740.00738 61.570804.00001.56010.00000 71.884963.33330.00600.00605 82.199112.85710.01840.01842 92.513272.50000.00110.00112 102.827432.22220.00050.00045 113.141592.00000.23720.11858 0.15690

31 31 So,

32 32 The Line Spectrum (Periodogram) To identify significant cyclical patterns. The Line Spectrum is the amount of total sums of squares explained by the specific frequencies.

33 33 Line Spectrum can be computed as The plot of P j ’s versus the wave length is called the periodogram. It measures the “intensity” of the specific cycles. The “P_01” column in SAS output gives the line spectrums for all harmonics, except for the last harmonic, where the correct line spectrum is P_01/2.

34 34

35 35 SourceSSdfFDecision 5 th harmonic Other harmonics 1.5601 0.1569 2 17 84.52Significant 10 th harmonic Other harmonics 0.11858 0.03832 1 16 49.51Significant 7 th harmonic Other harmonics 0.01842 0.0199 2 14 6.48Significant at 5% ; not significant at 1% 4 th harmonic Other harmonics 0.00738 0.01252 2 12 3.54not significant ANOVA test

36 36 Thus, the 5 th & 10 th harmonics (or equivalently, the 4- period & 2-period cycles) are significant which means a suitable model would be or equivalently,

37 37 Note: since and

38 38 The SAS System The REG Procedure Model: MODEL1 Dependent Variable: y Number of Observations Read 20 Number of Observations Used 20 Analysis of Variance SourceDFSum of SquaresMean SquareF ValuePr > F Model31.678680.55956233.64<.0001 Error160.038320.00239 Corrected Total191.71700 Root MSE0.04894R-Square0.9777 Dependent Mean1.00000Adj R-Sq0.9735 Coeff Var4.89387 Parameter Estimates VariableDFParameter EstimateStandard Errort Value Pr > ︳ t ︱ Intercept11.000000.0109491.38<.0001 s510.387000.0154825.01<.0001 c510.079000.015485.100.0001 c101-0.077000.01094-7.04<.0001

39 39 The SAS System Obsypr 11.521.464000.056000 20.810.84400-0.034000 30.630.69000-0.060000 41.061.002000.058000 51.461.46400-0.004000 60.800.84400-0.044000 70.710.690000.020000 80.981.00200-0.022000 91.501.464000.036000 100.850.844000.006000 110.650.69000-0.040000 121.041.002000.038000 131.471.464000.006000 140.850.844000.006000 150.720.690000.030000 160.951.00200-0.052000 171.371.46400-0.094000 180.910.844000.066000 190.740.690000.050000 200.981.00200-0.022000 MAPE = 4.113%

40 40 Out-of-Sample forecasts

41 41 Example: U.S./New Zealand foreign Exchange Rate (1986 Q2 to 2008 Q2) Quarterly average

42 42 data Nzea; set Nzea; D_USNEWZD =USNEWZD - lag(USNEWZD); if Date = “Q2 1986” then delete; run; data Nzea; set Nzea; t+1; pi=3.1415926; s1= sin(pi*t/44*1); c1= cos(pi*t/44*1);. c43= cos(pi*t/44*43); s44= sin(pi*t/44*44); c44= cos(pi*t/44*44); run;

43 43 proc reg data= Nzea; model D_USNEWZD = s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 s8 c8 s9 c9 s10 c10 s11 c11 s12 c12 s13 c13 s14 c14 s15 c15 s16 c16 s17 c17 s18 c18 s19 c19 s20 c20 s21 c21 s22 c22 s23 c23 s24 c24 s25 c25 s26 c26 s27 c27 s28 c28 s29 c29 s30 c30 s31 c31 s32 c32 s33 c33 s34 c34 s35 c35 s36 c36 s37 c37 s38 c38 s39 c39 s40 c40 s41 c41 s42 c42 s43 c43 c44 ; output out=out1 predicted=p residual=r; run; quit; proc spectra data= Nzea out=out2; var D_USNEWZD; run; data out2; set out2; sq=p_01; if period=. then sq=0; if round (freq,.0001)=3.1416 then sq=.5*p_01; run; proc reg data= Nzea outest=outtest3; model D_USNEWZD = c31 s31 c3 s3 c8 s8 ; output out=out3 predicted=p residual=r; run; quit;

44 44 ANOVA test SourceSSdfFDecision 31st harmonic0.009024.8804Significant Other harmonics0.078885 3rd harmonic0.006623.7920Significant Other harmonics0.072283 8th harmonic0.006223.8210Significant Other harmonics0.066081 9th harmonic0.003922.4908Insignificant Other harmonics0.062079

45 45 Fitted model equation Forecasts


Download ppt "1 Fourier Series (Spectral) Analysis. 2 Fourier Series Analysis Suitable for modelling seasonality and/or cyclicalness Identifying peaks and troughs."

Similar presentations


Ads by Google