You are on page 1of 59

POLITEKNIK STATISTIKA STIS

For Better Official Statistics

PENGANTAR
TIME SERIES ANALYSIS:
Konsep dan Pemodelan

Pertemuan I / 2022
PENDAHULUAN
For Better Official Statistics
Types of Data

▪ Cross-Section
▪ Time Series
▪ Longitudinal/Panel

3
For Better Official Statistics
Cross-Sectional Data

Cross-sectional
data are
observations
collected at a
single point in
time

4
For Better Official Statistics
Time Series Data

A time series consists


of data that are
collected, recorded, or
observed over
successive increments
of time.

5
For Better Official Statistics
Panel Data

6
For Better Official Statistics
Stochastic Process vs. Time Series

7
For Better Official Statistics
Two General “Classes” of Processes

✓ Stationary
▪ Unconditional mean and variance constant
▪ Time-invariant covariance
✓ Nonstationary

8
For Better Official Statistics
Stationary Processes?

9
For Better Official Statistics
Nonstationary Time Series

Nonstationary in Mean Nonstationary in Variance

10
For Better Official Statistics
Modelling Time Series Data
Case 1 Case 2
Sales predicted by sales pattern in the past Sales predicted by other relevant variables

https://exceldashboardschool.com/sales-forecast-chart/ https://www.sganalytics.com/blog/choosing-right-price-elasticity-model/

SALEt = a + b.SALEt-1 +et SALEt = a + b.PRICEt +et


SALEt = a + b.t + c.t2+et SALEt = a + b.PRICEt +c.ADVt+et 11
For Better Official Statistics
Time Series Analysis

✓ Time Series Forecasting


▪ Menjelaskan pola data berdasarkan waktu
▪ Memprediksi kejadian yang akan datang berdasarkan perilaku variabel tersebut di masa
lalu

✓ Causal Methods
▪ Eksplanatoris atau kausalitas, yakni menganalisis hubungan antar variabel time series
▪ Mengestimasi parameter-parameter hubungan antar variabel ekonomi, seperti elastisitas,
propensitas, multiplier, dsb dengan menggunakan data time series

12
For Better Official Statistics
Classification of Forecasting Methods

Forecasting Method

Objective Subjective (Judgmental)


Forecasting Methods Forecasting Methods

Time Series Causal


Analogies
Methods Methods

Naïve Methods Simple Regression


Delphi Method

Moving Averages Multiple Regression

Survey
Exponential Smoothing Neural Networks

Trend Decomposition
Sales Force Composite

ARIMA

Neural Networks

Combination of Time Series – Causal Methods


▪ VAR, VECM
▪ Intervention Model
▪ ARIMAX
▪ VARIMA (VARIMAX)
▪ Neural Networks

References: Makridakis et al; Hanke and Reitsch; Wei, W.W.S.; and Box, Jenkins and Reinsel
For Better Official Statistics

Classification of
Forecasting Methods [2]

Sources: Zellner M, Abbas AE, Budescu


DV, Galstyan A (2021)
14
For Better Official Statistics
Forecasting Methods Popularity

Most frequently searched forecasting methods Distribution of most frequently searched forecasting
according to Google Scholar over time topics according to Google Scholar over time

Sources: Zellner M, Abbas AE, Budescu


DV, Galstyan A (2021)
15
PEMODELAN DAN
PERAMALAN
For Better Official Statistics
Five Steps in the Forecasting Process

Problem formulation and data


1 collection
Data manipulation and
cleaning
2

3 Model building and evaluation

Model implementation
(the actual forecast)
4

5 Forecast evaluation

References: Hanke (2014) 17


For Better Official Statistics
Problem Formulation and Data Collection

✓ Specification of a forecasting problem


▪ Why is a forecast needed?
▪ Who will use the forecast?
▪ What level of detail or aggregation is required, and what is the proper time horizon?
▪ What data are available, and will the data be sufficient to generate the needed forecast?
▪ etc.

✓ The relevant data must be available and correct


▪ Data should be reliable and accurate
▪ Data should be relevant
▪ Data should be consistent
▪ Data should be timely

18
For Better Official Statistics
Data Manipulation and Cleaning

✓ Periksa kesamaan periode waktu: menit, harian, pekanan, bulanan, triwulanan, tahunan.
Jika belum sama, maka disamakan.
✓ Periksa kesamaan satuan (unit) dan tahun dasar. Jika belum sama, maka disamakan
✓ Atasi “missing data”, dengan interpolasi, deleting cases, dsb
✓ Cek kembali nilai-nilai ekstrim (terlalu tinggi atau terlalu rendah)
✓ Agregasi/Disagregasi data. Pahami data stock (posisi) atau data flow (aliran); bisa
diagregasi atau tidak. Misal jumlah penduduk (posisi), nilai produksi (flow, bisa diagregasi)
✓ dll.

19
For Better Official Statistics
Model Building and Evaluation

1 Eksplorasi pola data

2 Memilih teknik peramalan

3 Evaluasi model: perkiraan akurasi ramalan

20
STEP 1
EKSPLORASI POLA
DATA
For Better Official Statistics
Eksplorasi Pola Data

The first step is visual inspection: graph and observe your data

“You can observe a lot just by watching”


Yogi Berra

22
For Better Official Statistics
Pola Umum Data Time Series

Sebelum memilih model time series yang tepat, pertama kali yang dilakukan adalah
mengeksplorasi pola data.
✓ Pola horizontal (stasioner pada rata-rata)
✓ Pola trend
✓ Pola seasonal
✓ Pola cyclical

23
For Better Official Statistics
Pola Horizontal

24
For Better Official Statistics
Pola Trend

A trend exists when there is a long-term increase or decrease in the data. 25


For Better Official Statistics
Pola Seasonal

Indonesian Economic Growth (Quarter-over-Quarter)


5

0
2011Q1 2011Q2 2011Q3 2011Q4 2012Q1 2012Q2 2012Q3 2012Q4 2013Q1 2013Q2 2013Q3 2013Q4 2014Q1 2014Q2 2014Q3 2014Q4
-1

-2

-3

A seasonal pattern occurs when a time series is affected by seasonal factors such as the time of the
year or the day of the week. Seasonality is always of a fixed and known frequency.
26
For Better Official Statistics
Pola Cyclic

A cycle occurs when the data exhibit rises and falls that are not of a fixed frequency.
27
For Better Official Statistics
Pola Kombinasi

▪ The monthly housing sales (left) show strong seasonality within each year, as well as some strong cyclic
behaviour with a period of about 6–10 years. There is no apparent trend in the data over this period.
▪ The Australian quarterly electricity production (right) shows a strong increasing trend, with strong seasonality.
There is no evidence of any cyclic behaviour here. 28
For Better Official Statistics
Pola Kombinasi [2]

29
STEP 2
MEMILIH TEKNIK
PERAMALAN
For Better Official Statistics
Forecasting Methods

✓ Subjective (excluded in this course)


✓ Objective
❑ Time Series Forecasting (Univariate)
▪ Deterministic Model
o Smoothing methods
o Time series decomposition
▪ Stochastic (Statistical) Model
o Models for stationary data
o Models for non-stationary data
❑ Causal Methods
▪ Error correction model
▪ Autoregressive distributed lag model
31
For Better Official Statistics
How to Select the Method?

To select the appropriate forecasting technique properly, the forecaster must be able to
accomplish the following: (see Hanke, 2014: 32-34)
✓ Define the nature of the forecasting problem.
✓ Explain the nature of the data under investigation.
✓ Describe the capabilities and limitations of potentially useful forecasting techniques.
✓ Develop some predetermined criteria on which the selection decision can be made.

32
For Better Official Statistics
Smoothing Methods

Tujuan untuk mengurangi komponen irregular sehingga komponen trend, seasonal, dan cyclic
lebih jelas terlihat

33
For Better Official Statistics
Time Series Decomposition

Prinsip dasar dekomposisi time series


adalah menguraikan data time
series ke dalam komponen-
komponen pembentuknya, agar
dapat dipahami lebih baik serta dapat
digunakan untuk peramalan

34
For Better Official Statistics
Stochastic Models

Stochastic Model: bersifat probabilistik, ada asumsi-asumsi tertentu pada error term
✓ Models for stationary data: AR, MA, ARMA
✓ Models for non-stationary data: ARIMA, SARIMA

35
For Better Official Statistics
Choosing a Forecasting Technique

36
STEP 3
EVALUASI
AKURASI MODEL
For Better Official Statistics
Forecast Evaluation – General Idea

✓ Hard to say how a given strategy will perform in the future


▪ Anything can happen?
✓ Idea: estimate the model on a fraction of the available data and use the remaining
part to evaluate out-of-sample forecast performance

38
For Better Official Statistics
Example 1

✓ Background: 21 Dec 2012 (Friday) - the end of a long cycle according to the Mayan calendar
✓ Resulting weather forecast:

Is it a good forecast? 39
For Better Official Statistics
Example 2

Is this a “good” forecast?


40
For Better Official Statistics
Forecast Often!

✓ Forecasts from the same model need to be repeated


▪ Models are evaluated using out-of-sample forecast performance
✓ The properties of a model (correct on average, low volatility) are evaluated using
various statistical measures
▪ Average of the forecast errors, degree of uncertainty
✓ Evaluation has to be repeated
▪ “It is often said there are two types of forecasts … lucky or wrong!”

41
For Better Official Statistics
Lucky or Wrong

✓ Economic variables are random processes and therefore each has a probability
distribution
✓ We call that distribution, which is typically unknown, the “data generation process
(DGP)” of that variable
✓ If the variable can have continuous values, the probability of a single point
forecast being equal to the eventual outcome is zero
✓ Therefore, it is only possible to attach a probability to a range of possible
outcomes encompassing the actual outcome
✓ If a point forecast happens to be equal to the actual outcome, it is purely by
chance and quite unlikely to be repeated in the next period
42
For Better Official Statistics
Data Generation Process

✓ Every economic variable has an underlying “data generation process (DGP)”


✓ The DGP is a probability density function, for example, 𝑁 𝜇, 𝜎 2
✓ For any sequence of data points, 𝜋𝑡 drawn from this distribution, we may write
𝑦𝑡+1 = 𝐸 𝑦𝑡+1 | 𝐼𝑛𝑓𝑜𝑟𝑚𝑎𝑡𝑖𝑜𝑛𝑡 + 𝜀𝑡+1
Where 𝐸𝑡 is the “conditional expectation operator” and 𝜀𝑡 is a residual error term,
which we expect to have zero mean

43
For Better Official Statistics
Why Conditional Means?

✓ The density for 𝑦𝑡+1 is difficult to estimate precisely, requiring a considerable


amount of data in practice
✓ Conditional means can be estimated more readily using a variety of statistical
procedures (models)
✓ For example, it is often assumed that the conditional mean is a linear function of
other explanatory variables (“information set”), and to use ordinary least squares
to estimate the unknowns in that relationship

44
For Better Official Statistics
Assuming that Conditional Mean is Known

𝑦𝑡+1 = 𝐸 𝑦𝑡+1 | 𝐼𝑛𝑓𝑜𝑟𝑚𝑎𝑡𝑖𝑜𝑛𝑡 + 𝜀𝑡+1


✓ We still need an estimate of 𝜀𝑡+1 to complete the forecast
✓ Assuming 𝜀𝑡+1 is a white noise process from a normal distribution with zero
mean, say, our best guess for all of its future values is zero
✓ So it is typically impossible to predict the actual outcome exactly

45
For Better Official Statistics
Source of Forecast Uncertainty #1

✓ Even if we know the conditional mean, our conditional forecast will necessarily
differ from the outcome
✓ Indeed, the observed forecast errors will obviously reflect the distribution of the
true error term, which is normally unknown
✓ The best we can hope for is that, on average, our actual forecast errors are zero.
Why?
𝑦𝑡+1 = 𝐸 𝑦𝑡+1 | 𝐼𝑛𝑓𝑜𝑟𝑚𝑎𝑡𝑖𝑜𝑛𝑡 + 𝜀𝑡+1
✓ Recall that with as 𝑁 → ∞,
σ𝑛𝑡=1 𝜀𝑡
→0
𝑁 𝑝
46
For Better Official Statistics
Additional Sources of Forecast Uncertainty

✓ We will continue with our maintained assumption that the conditional mean is
known and correctly specified
✓ However, now assume it depends on a set of variables, X:
𝑦𝑡+1 = 𝐹 𝑋𝑡+1 ; 𝜃 + 𝜀𝑡+1
✓ These variables might be jointly determined within the same system (economic
model), or be determined outside of the system (exogenous)
✓ The right-hand side or explanatory variables, 𝑋𝑡 , will need to be forecasted using
additional equations, namely:
𝑋𝑡+1 = 𝐺 𝑍𝑡+1 ; 𝛽 + 𝑢𝑡+1
47
For Better Official Statistics
Source of Forecast Uncertainty #2

✓ Inherent randomness of the explanatory variables


✓ The uncertainty associated with 𝑋𝑡 will also result in a wider forecast confidence
interval for 𝑦𝑡

48
For Better Official Statistics
What if Parameters of DGP are Unknown

✓ We will continue with our maintained assumption that the conditional mean is
known
✓ However, let’s now assume that we don’t know the values of the parameters on X,
namely 𝜃
𝑦𝑡+1 = 𝐹 𝑋𝑡+1 ; 𝜃 + 𝜀𝑡+1

49
For Better Official Statistics
Source of Forecast Uncertainty #3

✓ The unknown parameters need to be estimated from the available data, which are
random
✓ It follows that the estimates of 𝜃 are necessarily random variables and therefore
can contribute to your forecast errors
✓ Why? Estimates of the unknown parameters will typically be different from their
true values: 𝜃መ ≠ 𝜃

50
For Better Official Statistics
More Sources of Forecast Uncertainty

✓ The conditional mean is misspecified. Why? Perhaps


▪ The set of variables in X is incomplete
▪ Actual functional form used is wrong (linear or non-linear?)
▪ Underlying parameters may change over time (i.e., structural break)
✓ Estimation Issues:
▪ Parameters are estimated incorrectly (possibly because of misspecification,
measurement error in the explanatory variables and a poor estimation
procedure)

51
For Better Official Statistics
What We Learned

𝑦𝑡+1 = 𝐹 𝑋𝑡+1 ; 𝜃 + 𝜀𝑡+1


✓ Sources of forecast uncertainty
▪ Economic variables are inherently random
▪ There are unknown parameters in the conditional mean that need to be
estimated
▪ Explanatory variables also need to be forecast and could be random
quantities themselves
▪ The working form of the conditional mean may be misspecified

52
For Better Official Statistics
How to Measure Forecast Uncertainty

53
For Better Official Statistics
Measures of Forecast Uncertainty

✓ How can we measure forecast uncertainty?


✓ How do we use a measure of forecast uncertainty in practice?
✓ Unfortunately, there is no unique measure of forecast accuracy and precision

54
For Better Official Statistics
Common Statistical Measures

✓ Bias: the difference between the forecasts and the correct outcome (on average)
✓ Variance (“standard forecast error, SE”): A narrow range of outcomes is
compatible with the forecast
✓ Mean Squared Forecast Error (MSFE): A combination of bias and variance that is
commonly reported in forecast comparisons
The smaller they are the better the forecast

55
For Better Official Statistics
Measures of Forecast Accuracy
𝑓
1 ✓ Bias : The average of the forecast errors
𝐵𝐼𝐴𝑆 = ෍ 𝐹𝐸𝑡 di mana 𝐹𝐸𝑡 = 𝑦ො𝑡 − 𝑦𝑡
𝑓 ✓ SE : Standard forecast error
𝑡=1
✓ MSE : Mean Squared Error
𝑓
1 ✓ RMSE : Root Mean Squared Error
𝑆𝐸 = ෍ 𝐹𝐸𝑡 − 𝐵𝐼𝐴𝑆 2
𝑓 ✓ MAE : Mean Absolute Error
𝑡=1
✓ MAPE : Mean Absolute Percentage Error
𝑓
1
𝑀𝑆𝐸 = ෍ 𝐹𝐸𝑡2
𝑓
𝑡=1

𝑓
1
𝑅𝑀𝑆𝐸 = ෍ 𝐹𝐸𝑡2
𝑓
𝑡=1

𝑓 𝑓
1 1 𝐹𝐸𝑡
𝑀𝐴𝐸 = ෍ 𝐹𝐸𝑡 𝑀𝐴𝑃𝐸 = ෍
𝑓 𝑓 𝑦𝑡
𝑡=1 𝑡=1 56
For Better Official Statistics
Forecast Strategies

✓ When evaluating a model, important to do it for different forecast horizons (short-


and long-run)
✓ Two forecasting strategies
▪ Expanding window
o A model is estimated in [1, 𝑇] and forecast is made for 𝑇 + ℎ
o At 𝑇 + 1 the model is re-estimated on [1, 𝑇 + 1] and a forecast is made for 𝑇 + ℎ + 1
o Estimation window expands as we progress into the future: get data, re-estimate, forecast
o Forecasts are made for the same horizon!

▪ Rolling window
o The size of estimation sample (w) is chosen initially and fixed. 𝑤 can be less than 𝑇
o A model is estimated in [𝑇 − 𝑤 + 1, 𝑇] and a forecast is for 𝑇 + ℎ
o At 𝑇 + 1 the model is re-estimated on [𝑇 − 𝑤 + 2, 𝑇 + 1] and a forecast is made for 𝑇 + ℎ + 1
o Estimation sample rolls forward: get data, re-estimate, forecast
o Again, forecasts are made for the same horizon! Helps you deal with structural breaks too! 57
For Better Official Statistics
Expanding vs. Rolling (Sliding) Window

58
POLITEKNIK STATISTIKA STIS
For Better Official Statistics

Terima Kasih!

You might also like