SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Decomposition
Causal
Models
Quantitative Forecasting
Methods
Quantitative
Forecasting
Time Series
Models
Regression
Exponential
Smoothing
Trend
Models
Moving
Average
Time Series Forecasting
Time Series Analysis
Forecasting
Ada pattern
(pola)
Smoothing
Prinsipnya mengeliminasi
randomness sehingga pattern
dapat diproyeksi ke masa
depan
Pattern (pola) didekomposisi
menjadi subpattern yang
mengindentifikasi tiap
komponen time series (C,S,T,I)
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
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
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
Decomposition Graphics
Decomposition
Plot
Seasonal sub-series plot
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
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
© BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU
Rata-rata bergerak yg diletakkan di tengah nilai-nilai data yg
dirata-ratakan.
Jika observasi (N) berjumlah ganjil, data diletakkan pada periode
ke- (N+1)/2
Contoh: MA(3) hasil rata-rata diletakkan pada periode ke
(3+1)/2=2
Jika observasi (N) berjumlah genap, maka gunakan rata-rata
bergerak ganda 2 x MA(N).
© BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU
Seasonal Indices
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).
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)
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
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
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
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 ˆ
/
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.
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
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
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
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
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

© BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU
Ringkasan Prosedur SPSS
Input data pada worksheet SPSS
Masukkan informasi tahun dan bulan. Klik Data > Define Dates.
Isikan/pilih hal-hal berikut:
Cases Are: pilih Years, months.
First Case Is: isikan Year = 2007
Month=1
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
Pada worksheet SPSS, terdapat empat peubah baru seperti tampilan
berikut:
© BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU
• ERR_1 merupakan error
• SAS_1 merupakan musiman (seasonal)
• SAF_1 merupakan komponen siklus (cycle)
• STC_1 merupakan data trend
© BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU
Untuk proyeksi dengan penggambaran kurva
Klik Analyze > Time Series > Sequence Chart
Contoh grafik komponen musiman metode dekomposisi multiplikatif
Masukkan komponen misalnya
komponen Seasonal Adjusted Series
(SAS_1) ke dalam kotak variable(s) di
sebelah kanan, klik OK.
Date
OCT
2010
MAY
2010
DEC
2009
JUL
2009
FEB
2009
SEP
2008
APR
2008
NOV
2007
JUN
2007
JAN
2007
Seasonal
adjusted
series
for
Kredit
from
SEASON,
MOD_4,
…
350000.00000
300000.00000
250000.00000
200000.00000
150000.00000
100000.00000
Time Series
Analysis in R
Decomposing
Time Series
Loading Necessary Libraries
library(astsa, quietly=TRUE, warn.conflicts=FALSE)
library(ggplot2)
library(knitr)
library(printr)
library(plyr)
library(dplyr)
library(lubridate)
library(gridExtra)
library(reshape2)
library(TTR)
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)
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
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
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
Plotting Time Series
Plot the kings data.
plot.ts(kings)
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.
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)
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.
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.
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)
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)
Ringkasan Prosedur dengan R
decompose(x, type = c("additive", "multiplicative"), filter = NULL)

Weitere ähnliche Inhalte

Ähnlich wie 2b. Decomposition.pptx

Holtwinters terakhir lengkap
Holtwinters terakhir lengkapHoltwinters terakhir lengkap
Holtwinters terakhir lengkapZulyy Astutik
 
time series.ppt [Autosaved].pdf
time series.ppt [Autosaved].pdftime series.ppt [Autosaved].pdf
time series.ppt [Autosaved].pdfssuser220491
 
Data Science - Part X - Time Series Forecasting
Data Science - Part X - Time Series ForecastingData Science - Part X - Time Series Forecasting
Data Science - Part X - Time Series ForecastingDerek Kane
 
Basic Business Forecasting
Basic Business ForecastingBasic Business Forecasting
Basic Business ForecastingEd Dansereau
 
time series.pdf
time series.pdftime series.pdf
time series.pdfcollege
 
Trend and seasonal component/abshor.marantika/kelompok 12
Trend and seasonal component/abshor.marantika/kelompok 12Trend and seasonal component/abshor.marantika/kelompok 12
Trend and seasonal component/abshor.marantika/kelompok 12Linlin2611
 
Trend and seasonal component/Abshor.Marantika - kelompok 12
Trend and seasonal component/Abshor.Marantika - kelompok 12Trend and seasonal component/Abshor.Marantika - kelompok 12
Trend and seasonal component/Abshor.Marantika - kelompok 12Linlin2611
 
1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-main1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-mainZulyy Astutik
 
1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-main1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-mainZulyy Astutik
 
IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...
IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...
IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...StatsCommunications
 
1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx
1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx
1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptxDeepGondaliya3
 
Chapter 7 Forecasting Time Series ModelsLan WangCSU East .docx
Chapter 7 Forecasting Time Series ModelsLan WangCSU East .docxChapter 7 Forecasting Time Series ModelsLan WangCSU East .docx
Chapter 7 Forecasting Time Series ModelsLan WangCSU East .docxchristinemaritza
 
Applied Statistics Chapter 2 Time series (1).ppt
Applied Statistics Chapter 2 Time series (1).pptApplied Statistics Chapter 2 Time series (1).ppt
Applied Statistics Chapter 2 Time series (1).pptswamyvivekp
 

Ähnlich wie 2b. Decomposition.pptx (20)

Holtwinters terakhir lengkap
Holtwinters terakhir lengkapHoltwinters terakhir lengkap
Holtwinters terakhir lengkap
 
time series.ppt [Autosaved].pdf
time series.ppt [Autosaved].pdftime series.ppt [Autosaved].pdf
time series.ppt [Autosaved].pdf
 
Data Science - Part X - Time Series Forecasting
Data Science - Part X - Time Series ForecastingData Science - Part X - Time Series Forecasting
Data Science - Part X - Time Series Forecasting
 
Time Series Analysis Ravi
Time Series Analysis RaviTime Series Analysis Ravi
Time Series Analysis Ravi
 
Basic Business Forecasting
Basic Business ForecastingBasic Business Forecasting
Basic Business Forecasting
 
Chapter 18 Part I
Chapter 18 Part IChapter 18 Part I
Chapter 18 Part I
 
time series.pdf
time series.pdftime series.pdf
time series.pdf
 
Trend and seasonal component/abshor.marantika/kelompok 12
Trend and seasonal component/abshor.marantika/kelompok 12Trend and seasonal component/abshor.marantika/kelompok 12
Trend and seasonal component/abshor.marantika/kelompok 12
 
Trend and seasonal component/Abshor.Marantika - kelompok 12
Trend and seasonal component/Abshor.Marantika - kelompok 12Trend and seasonal component/Abshor.Marantika - kelompok 12
Trend and seasonal component/Abshor.Marantika - kelompok 12
 
forecasting
forecastingforecasting
forecasting
 
Time series Analysis
Time series AnalysisTime series Analysis
Time series Analysis
 
Time series
Time series Time series
Time series
 
1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-main1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-main
 
1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-main1 s2.0-0272696386900197-main
1 s2.0-0272696386900197-main
 
IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...
IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...
IAOS 2018 - Seasonal Adjustment of Daily Data, D. Ladiray, J. Palate, G.L. Ma...
 
lect1
lect1lect1
lect1
 
lecture3.pdf
lecture3.pdflecture3.pdf
lecture3.pdf
 
1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx
1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx
1.3-CHAPTER 13 FORECASTING_BA_UDineshK.pptx
 
Chapter 7 Forecasting Time Series ModelsLan WangCSU East .docx
Chapter 7 Forecasting Time Series ModelsLan WangCSU East .docxChapter 7 Forecasting Time Series ModelsLan WangCSU East .docx
Chapter 7 Forecasting Time Series ModelsLan WangCSU East .docx
 
Applied Statistics Chapter 2 Time series (1).ppt
Applied Statistics Chapter 2 Time series (1).pptApplied Statistics Chapter 2 Time series (1).ppt
Applied Statistics Chapter 2 Time series (1).ppt
 

Kürzlich hochgeladen

dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
MK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxMK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxUnduhUnggah1
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 

Kürzlich hochgeladen (20)

dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
MK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxMK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docx
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 

2b. Decomposition.pptx

  • 5. Forecasting Ada pattern (pola) Smoothing Prinsipnya mengeliminasi randomness sehingga pattern dapat diproyeksi ke masa depan Pattern (pola) didekomposisi menjadi subpattern yang mengindentifikasi tiap komponen time series (C,S,T,I)
  • 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
  • 13. © BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU Rata-rata bergerak yg diletakkan di tengah nilai-nilai data yg dirata-ratakan. Jika observasi (N) berjumlah ganjil, data diletakkan pada periode ke- (N+1)/2 Contoh: MA(3) hasil rata-rata diletakkan pada periode ke (3+1)/2=2
  • 14. Jika observasi (N) berjumlah genap, maka gunakan rata-rata bergerak ganda 2 x MA(N). © BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU
  • 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 
  • 28. © BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU Ringkasan Prosedur SPSS Input data pada worksheet SPSS Masukkan informasi tahun dan bulan. Klik Data > Define Dates. Isikan/pilih hal-hal berikut: Cases Are: pilih Years, months. First Case Is: isikan Year = 2007 Month=1
  • 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
  • 30. Pada worksheet SPSS, terdapat empat peubah baru seperti tampilan berikut: © BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU • ERR_1 merupakan error • SAS_1 merupakan musiman (seasonal) • SAF_1 merupakan komponen siklus (cycle) • STC_1 merupakan data trend
  • 31. © BAMBANG JUANDA & JUNAIDI: EKONOMETRIKA DERET WAKTU Untuk proyeksi dengan penggambaran kurva Klik Analyze > Time Series > Sequence Chart Contoh grafik komponen musiman metode dekomposisi multiplikatif Masukkan komponen misalnya komponen Seasonal Adjusted Series (SAS_1) ke dalam kotak variable(s) di sebelah kanan, klik OK. Date OCT 2010 MAY 2010 DEC 2009 JUL 2009 FEB 2009 SEP 2008 APR 2008 NOV 2007 JUN 2007 JAN 2007 Seasonal adjusted series for Kredit from SEASON, MOD_4, … 350000.00000 300000.00000 250000.00000 200000.00000 150000.00000 100000.00000
  • 32. Time Series Analysis in R Decomposing Time Series
  • 33. Loading Necessary Libraries library(astsa, quietly=TRUE, warn.conflicts=FALSE) library(ggplot2) library(knitr) library(printr) library(plyr) library(dplyr) library(lubridate) library(gridExtra) library(reshape2) library(TTR)
  • 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
  • 38. Plotting Time Series Plot the kings data. plot.ts(kings)
  • 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)
  • 46. Ringkasan Prosedur dengan R decompose(x, type = c("additive", "multiplicative"), filter = NULL)