6. Dekomposisi Memisahkan dua komponen dasar yang sering
menjadi karakteristik series data ekonomi dan
bisnis
1. Trend-cycle
2. Seasonal factor
Data = Pattern + Error
Data = f(trend-cycle, seasonality, error)
Latar belakang dekomposisi
1. Statistik untuk mempelajari serial correlation within or between
variable(s). Korelasi yang mungkin timbul karena adanya trend harus
dihilangkan.
2. Ekonomi para ekonom khawatir mengenai dampak depresi dan
mencari cara untuk memprediksinya. Mereka merasa kalau elemen
aktivitas ekonomi harus dipisahkan sehingga perubahan business
cycle dapat diisolasi dari seasonal dan perubahan lainnya
7. Decomposition Model
Yt = f(St, Tt, Et)
Assumed equation :
Yt = St + Tt+ Et additive decomposition
Yt = St x Tt x Et multiplicative decomposition
Model additive sesuai jika magnitude fluktuasi
seasonal tidak bervariasi dengan level data
seriesnya.
Model multiplicative sesuai jika fluktuasi
seasonalnya naik dan turun secara proporsional
sejaan dengan kenaikan dan penurunan level data
seriesnya
8. Additive or Multiplicative Decomposition?
Gunakan transformasi agar data yang tadinya tidak additive bisa
dimodelkan secara additive
Yt = St x Tt x Et
logYt = log St + log Tt + log Et
Model dekomposisi lainnya adalah pseudo-additive
decomposition
Yt = Tt(St + Et – 1)
Model ini berguna untuk data dimana ada satu bulan(triwulan)
yang lebih tinggi atau rendah daripada bulan (triwulan) lainnya
11. Prosedur additive decomposition
1. Hitung trend-cycle menggunakan centered moving average
12MA
2. Buat de-trended series dengan megurangi datanya dengan trend-
cycle
Yt – Tt = St + Et
3. Buat seasonal indices, diasumsikan komponen seasonal konstan
dari tahun ke tahun. Jadi hanya perlu menghitung satu nilai saja.
4. Irregular series Et dihitung dengan mengurangi data dengan
seasonality dan trend-cycle
12. Centered moving average
Trend-cycle dapat diestimasi dengan smoothing data series untuk
mengurangi variasi keacakan. Banyak metode smoothing, tetapi yang
paling mudah dan paling tua adalah moving average
16. Seasonal Analysis
Variasi musiman dapat terjadi selama periode satu tahun atau periode
yang lebih pendek (bulan, minggu)
Untuk mengukur pengaruh musiman, kita membangun indeks musiman
(seasonal index).
Seasonal indexes mencerminkan tingkat dimana musim berbeda dari
rata-rata time series secara keseluruhan (across all seasons).
17. Computing Seasonal Indices
Hilangkan pengaruh seasonal dan variasi acak dengan analisis regresi
>
𝑌 = 𝑏0 + 𝑏1𝑡
Untuk setiap periode, hitung rasio 𝑌𝑡 𝑌𝑡 yang akan menghilangkan variasi tren. Ini
berdasarkan multiplicative model
Untuk setiap musim, hitung rata-rata dari 𝑌𝑡 𝑌𝑡 yang akan mengukur musiman
(seasonality
Sesuaikan rata-rata di atas sehingga jumlah rata-rata semua musim = 1 (jika perlu)
18. Computing Seasonal Indices
Example
◦ Calculate the quarterly seasonal indices for
hotel occupancy rate in order to measure
seasonal variation.
Year Quarter Rate
1996 1 0.561
2 0.702
3 0.8
4 0.568
1997 1 0.575
2 0.738
3 0.868
4 0.605
1998 1 0.594
2 0.738
3 0.729
4 0.6
1999 1 0.622
2 0.708
3 0.806
4 0.632
2000 1 0.665
2 0.835
3 0.873
4 0.67
19. Computing Seasonal Indices
Perform regression analysis for the model
y = b0 + b1t + e where t represents the time, and y represents
the occupancy rate.
Time (t) Rate
1 0.561
2 0.702
3 0.800
4 0.568
5 0.575
6 0.738
7 0.868
8 0.605
. .
. .
t
005246
.
639368
.
ŷ
0.561
0.702
0.8
0.568 0.575
0.738
0.868
0.605 0.594
0.738 0.729
0.6
0.622
0.708
0.806
0.632
0.665
0.835
0.873
0.67
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Y
t
Y Predicted Y
20. No trend is observed, but seasonality and randomness still exist.
The Ratios (𝑌𝑡 𝑌𝑡)
t Y
Predicted
Y Ratio
1 0.56 0.640.56/0.64=0.87
2 0.70 0.650.70/0.65=1.08
3 0.80 0.660.80/0.66=1.22
4 0.57 0.660.57/0.66=0.86
5 0.58 0.670.58/0.67=0.86
6 0.74 0.670.74/0.67=1.10
7 0.87 0.680.87/0.68=1.28
8 0.61 0.680.61/0.68=0.89
9 0.59 0.690.59/0.69=0.87
10 0.74 0.690.74/0.69=1.07
11 0.73 0.700.73/0.70=1.05
12 0.60 0.700.60/0.70=0.85
13 0.62 0.710.62/0.71=0.88
14 0.71 0.710.71/0.71=0.99
15 0.81 0.720.81/0.72=1.12
16 0.63 0.720.63/0.72=0.87
17 0.67 0.730.67/0.73=0.91
18 0.84 0.730.84/0.73=1.14
19 0.87 0.740.87/0.74=1.18
20 0.67 0.740.67/0.74=0.90
0.00
0.20
0.40
0.60
0.80
1.00
1.20
1.40
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Y/Predicted
Y
t
21. The Average Ratios by Seasons
Rate/Predicted rate
0
0.5
1
1.5
1 3 5 7 9 11 13 15 17 19
Rate/Predicted rate
0.870
1.080
1.221
0.860
0.864
1.100
1.284
0.888
0.865
1.067
1.046
0.854
0.879
0.993
1.122
0.874
0.913
1.138
1.181
0.900
(.870 + .864 + .865 + .879 + .913)/5 = .878
Average ratio for quarter 1:
Average ratio for quarter 2: (1.080+1.100+1.067+.993+1.138)/5 = 1.076
Average ratio for quarter 3: (1.221+1.284+1.046+1.122+1.181)/5 = 1.171
Average ratio for quarter 4: (.860 +.888 + .854 + .874 + .900)/ 5 = .875
• To remove most of the random variation
but leave the seasonal effects,average
the terms for each season.
t
t y
y ˆ
/
22. Adjusting the Average Ratios
In this example the sum of all the averaged ratios must be 4, such that the
average ratio per season is equal to 1.
If the sum of all the ratios is not 4, we need to adjust them proportionately.
(Seasonal averaged ratio) (number of seasons)
Sum of averaged ratios
Seasonal index =
In our problem the sum of all the averaged ratios is equal to 4:
.878 + 1.076 + 1.171 + .875 = 4.0.
No normalization is needed. These ratios become the seasonal indices.
Suppose the sum of ratios is equal to 4.1. Then each ratio will be
multiplied by 4/4.1.
23. Quarter 2 Quarter 3
Quarter 3
Quarter 2
Interpreting the Seasonal Indices
The seasonal indexes tell us what is the ratio between the time
series value at a certain season, and the overall seasonal
average.
In our problem:
Annual average
occupancy (100%)
Quarter 1 Quarter 4 Quarter 1 Quarter 4
87.8%
107.6%
117.1%
87.5%
12.2% below the
annual average
7.6% above the
annual average
17.1% above the
annual average
12.5% below the
annual average
24. The Smoothed Time Series
The trend component and the seasonality component are recomposed
using the multiplicative model.
0.5
0.6
0.7
0.8
0.9
1 3 5 7 9 11 13 15 17 19
t
t
t
t Ŝ
)
t
0052
.
639
(.
Ŝ
T̂
ŷ
In period #1 ( quarter 1): 566
.
)
878
))(.
1
(
0052
.
639
(.
Ŝ
T̂
ŷ 1
1
1
In period #2 ( quarter 2): 699
.
)
076
.
1
))(
2
(
0052
.
639
(.
Ŝ
T̂
ŷ 2
2
2
Actual series Smoothed series
The linear trend (regression) line
25. Deseasonalized Time Series
By removing the seasonality, we can identify changes in the other
components of the time series, that might have occurred over time.
Seasonally adjusted time series = Actual time series
Seasonal index
26. Deseasonalized Time Series
In period #1 ( quarter 1): 639
.
878
.
/
561
.
/ 1
1
SI
y
In period #4 ( quarter 2): 652
.
076
.
1
708
.
SI
/
y 2
2
0
0.2
0.4
0.6
0.8
1
0 5 10 15 20 25
There was a gradual increase in occupancy rate
In period #5 ( quarter 1): 661
.
878
.
575
.
/ 1
5
SI
y
27. Prosedur multiplicative decomposition
1. Hitung rata-rata bergerak yg panjangnya N sama dgn panjang musiman. Hasil
rata-rata bergeraknya adalah Mt= Tt x Ct
2. Bagi data aktual dengan Mt= Tt x Ct , maka It x Et dapat dipisahkan yaitu
3. Cari indeks musiman St dgn cara memisahkan faktor acak Et dgn cara
a. Gunakan rata-rata bergerak medial yaitu nilai rata-rata untuk setiap periode
setelah dikeluarkan nilai terbesar dan nilai terkecilnya. Ini akan
menghilangkan unsur random Et dan yg tersisa hanya faktor musiman.
b. Indeks musiman diperoleh dari rata-rata medial dikali faktor koreksi.
4. Pisahkan hasil langkah 3 dari langkah 1 untuk mendapatkan faktor siklus
5. Pisahkan Et dan membagi data asli terhadap faktor It, Tt, dan Ct.
6. Lakukan peramalan berdasarkan model yang dibuat
Y
T xC
I xT xC xE
T xC
I xE
t
t t
t t t t
t t
t t
T xC
T
C
t t
t
t
29. Klik OK, maka akan muncul tampilan worksheet berikut:
Klik Analyze > Time Series > Seasonal Decomposition.
Isikan/pilih hal-hal berikut:
• Masukkan peubah kredit ke kotak
Variable(s)
• Pilih model Multiplicative ataupun
Aditive
34. Reading Time Series
Here we use the file http://robjhyndman.com/tsdldata/misc/kings.dat contains data
on the age of death of successive kings of England, starting with William the
Conqueror (original source: Hipel and Mcleod, 1994).
You can read data into R using the scan() function, which assumes that your data
for successive time points is in a simple text file with one column.
The first three lines contain some comment on the data, and we want to ignore
this when we read the data into R.
kings <- scan('http://robjhyndman.com/tsdldata/misc/kings.dat', skip=3)
head(kings)
35. Converting the data into a time
series
Once you have read the time series data into R, the next step is to store the data
in a time series object in R, so that you can use R’s many functions for analysing
time series data.
To store the data in a time series object, we use the ts() function in R.
kings <- ts(kings)
kings
36. However, it is common to come across time series that have been collected at
regular intervals that are less than the one year of the kings dataset, for example,
monthly, weekly or quarterly. In these cases we can specify the number of times
that data was collected per year by using the frequency parameter in the ts( )
function. For monthly data, we set frequency = 12. We can also specify the first
year that the data were collected and the first interval in that year by using the
‘stat’ parameter. For example, the third quarter of 1909 would be `start = c(1909,
3).
Next we load in a dataset of number of births per month in New York city, from
January 1946 to December 1958.
births <- scan("http://robjhyndman.com/tsdldata/data/nybirths.dat")
births <- ts(births, frequency = 12, start = c(1946, 1))
births
37. Next loading data on beach town souvenir shop.
gift <- scan("http://robjhyndman.com/tsdldata/data/fancy.dat")
gift<- ts(gift, frequency=12, start=c(1987,1))
gift
39. Plotting the births data.
plot.ts(births)
We can see from this time series that
there is certainly some seasonal
variation in the number of births per
month; there is a peak every summer,
and a trough every winter. Again the it
seems like this could be described
using an additive model, as the
seasonal fluctuations are roughly
constant in size over time and do not
seem to depend on the level of the time
series, and the random fluctuations
seem constant over time.
40. plot.ts(gift)
In this case, an additive model is not
appropriate since the size of the seasonal
and random fluctuations change over time
and the level of the time series. It is then
appropriate to transform the time series so
that we can model the data with a classic
additive model.
logGift <- log(gift)
plot.ts(logGift)
41. Decomposing Time Series
Decomposing a time series means separating it into it’s constituent components,
which are often a trend component and a random component, and if the data is
seasonal, a seasonal component.
42. Decomposing non-Seasonal Data
Recall that non-seasonal time series consist of a trend component and
a random component. Decomposing the time series involves tying to
separate the time series into these individual components.
One way to do this is using some smoothing method, such as a simple
moving average. The SMA() function in the TTR R package can be
used to smooth time series data using a moving average. The SMA
function takes a span argument as n order. To calculate the moving
average of order 5, we set n = 5.
Lets start with n=3 to see a clearer picture of the Kings dataset trend
component
kingsSMA3 <- SMA(kings, n=3)
plot.ts(kingsSMA3)
It seems like there is still some random fluctuations in the data, we
might want to try a big larger of a smoother. Lets try n=8.
43. Decomposing Seasonal Data
A seasonal time series, in addition to the trend and random components, also has
a seasonal component. Decomposing a seasonal time series means separating
the time series into these three components. In R we can use the decompose()
function to estimate the three components of the time series.
Lets estimate the trend, seasonal, and random components of the New York births
dataset.
birthsComp <- decompose(births)
birthsComp
Now lets plot the components.
plot(birthsComp)
44.
45. Seasonally Adjusting
If you have a seasonal time series, you can seasonally adjust the series by
estimating the seasonal component, and subtracting it from the original time
series. We can see below that time time series simply consists of the trend and
random components.
birthsSeasonAdj <- births - birthsComp$seasonal
plot.ts(birthsSeasonAdj)