0% found this document useful (0 votes)
16 views18 pages

FM - Resumes

sdasdas

Uploaded by

butarros123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views18 pages

FM - Resumes

sdasdas

Uploaded by

butarros123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Time Series Basics and Getting Started with R

Forecasts can be:


• required several years in advance (for the case of capital investments)
• only a few minutes beforehand (for telecommunication routing)

Factores that affect forecastability (make it easier):


• we have a good understanding of the factors that contribute to it.
• there is lots of data available.
• the forecasts cannot affect the thing we are trying to forecast.
• there is relatively low natural/unexplainable random variation.
• the future is somewhat similar to the past.

Time Series
List of values that is observed sequentially over time. Only consider time series observed at regular intervals of time
(e.g., hourly, daily, weekly, monthly, quarterly, annually).

Time Series- R
• tsibble objects extend tidy data frames (tibble objects) by introducing temporal structure.
• A tsibble allows storage and manipulation of multiple time series in R.
• It contains:
• An index: time information about the observation.
• Measured variable(s): numbers of interest.
• Key variable(s): optional unique identifiers for each series
• It works with tidyverse functions.

In R we can use the pipe (%>%) and it can be read as “then. It focuses on the multiple operations and steps, making
the code easier to read.

The tsibble index: common time index variables can be created with these functions:

Tsibble objects:
• filter() function to select rows.
• select() function to select columns.
• combine functions index_by() or group_by() with summarise() to summarise over keys.
• mutate() function to create new variables.
• autoplot()

Time Series patterns


1. Trend: pattern exists when there is a long-term increase or decrease in the data. (bottom left)
2. Seasonal: pattern exists when a series is influenced by seasonal factors (e.g., the quarter of the year, the
month, or day of the week). (top-left)
3. Cyclic: pattern exists when data exhibit rises and falls that are not of fixed period (duration usually of a t least
2 years). (top-rigth)

Forecasting Methods
Difference between seasonal and cyclic patterns:

SEASONAL PATTERN CYCLIC PATTERN

LENGTH constant variable


AVERAGE LENGTH shorter longer
MAGNITUDE less variable more variable
TIMING OF PEAKS AND
TROUGHS predictable unpredictable

Seasonal Plots

Multiple seasonal periods: We can plot the daily pattern, weekly pattern or yearly pattern by specifying the period
argument.

Forecasting Methods
Seasonal subseries plots: An alternative plot that emphasizes the seasonal patterns is where the data for each
season are collected together in separate mini time plots.

Notes:
- the blue line indicate the means for each
month;
-this plot enables the underlying seasonal
pattern to be seen clearly, and also shows the
changes in seasonality over time
- It is especially useful in identifying changes
within particular seasons

Lagplot

Notes:
- The previous figure displays scatterplots of
quarterly Australian beer production, where the
horizontal axis shows lagged values of the time
series.
- Here the colors indicate the quarter of the
variable on the vertical axis.
- The relationship is strongly positive at lags 4 and
8, reflecting the strong seasonality in the data.
- The negative relationship seen for lags 2 and 6
occurs because peaks (in Q4) are plotted against
troughs (in Q2)

Basic Transformations and Adjustments

Adjusting the historical data can often lead to a simpler time series. The purpose of these adjustments and
transformations is to simplify the patterns in the historical data by removing known sources of variation, or by
making the pattern more consistent across the whole data set.
Simpler patterns are usually easier to model and lead to more accurate forecasts.

1. Calendar adjustments
• Some of the variation seen in seasonal data may be due to simple calendar effects.
• In such cases, it is usually much easier to remove the variation before doing any further analysis.
2. Population adjustments
• Any data that are affected by population changes can be adjusted to give per-capita data.
• That is, consider the data per person (or per thousand people, or per million people).
3. Inflation adjustments
• Data which are affected by the value of money are best adjusted before modelling. For example, the average cost
of a new house will have increased over the last few decades due to inflation.
• For this reason, financial time series are usually adjusted so that all values are stated in dollar values from a
particular year.

Forecasting Methods
• To make these adjustments, a price index is used. For consumer goods, a common price index is the Consumer
Price Index (or CPI).
• This allows us to compare the growth or decline of industries relative to a common price value.

Mathematical Transformations
If the data show different variation at different levels of the series, then a transformation can be useful.

Notes:
- if the varience is not constant all the time, using
log it will be better
- dont use log when we have zeros;
- changes in a log value are relative (percent)
- changes on the original scale

Box- Cox transformation

Notes:
- This attempts to balance the seasonal
fluctuations and random variation across the
series.
-A low value of λ can give extremely large
prediction intervals.

About transformations:

• Often no transformation needed.

• Simple transformations are easier to explain and work well enough.

• Transformations can have very large effect on PI.


• log1p() can be useful for data with zeros.

• If some data are negative, no power transformation is possible unless a constant is added to all values.

• Choosing logs is a simple way to force forecasts to be positive.


• Transformations must be reversed to obtain forecasts on the original scale. (Handled automatically by fable)
Classical decomposition

Notes:
- use the additive when the seasonality
is not changing so much

Forecasting Methods
Other decompositions and comparisons:

Classical Based on Census II Decomp.


Additive Multiplicative X11 X13- ARIMA STL
Smooth trends estimate

Lead well with outliers

Consider first few and las


few obs.
Works with
increasing/decreasing
variance
Hourly

Daily

Weekly

Monthly

Quarterly

Yearly

X11, X12 and X13 arima were develop for economic data.

X12 and X13 arima estimate missing values and replace them.

STL stands for Seasonal and Trend decomposition using LOESS. LOESS- locally weighted regression and scatterplot
smoothing. To use STL we first need to take logs or use Box-Cox.

Forecasting Methods
Forecaster’s Toolbox
the process of producing forecasts for time series data can be broken down into a few steps.

Tidy (data preparation) in forecasting is to prepare data in the correct format. This process may involve loading in
data, identifying missing values, filtering the time series, and other pre-processing tasks.

ARMA models
The statistical models used to describe time series data are called stochastic processes.

Stochastic processes
A stochastic process is a time-ordered sequence of random variables, {(y t);t = 1, . . . , T}.

Classical statistics versus Time Serie

Stationary

Forecasting Methods
Stationary assumptions:

White Noise
Is an uncorrelated stationary process. This process does not have memory (as we can see in the 3.)

Forecasting Methods
Box-Jenkins methodology. Forecasting with ARIMA models

1. Tentative identification - use all relevant information from the data to suggest some candidate models to be
analysed in more detail during the next stages.
Here we study our models and see if they are stationary through DF test (Dickey Fuller Test). If H0 is rejected then
our model is stationary.

Non stationary (we dont reject H0):

-0.9995 > -2.88 (at 5%)

How to make that model stationary:


- Remove the trend component – TSP (Trend Stationary Process)
- Take the first differences – DSP (Difference Stationary Process) (note: it is possible to take more than the first differences)
Reavaluate the DF test:

Stationary (we reject H0):

-6.4572 < -2.88 (at 5%)

2. Estimation - use the available data to estimate the model and test statistical hypotheses regarding the
parameters. Information Criteria:

Notes:
- the objective is to MINIMIZE
- HC e BIC performs better with large samples and
overparametrized models in small samples

- AIC performs better with small samples and


overparametrized models in large samples

The best model to use is the


“auto” – lower values

In this step, the estimate not statistically significant may then be removed from the model. For example:

Forecasting Methods
3. Diagnostic checking - use a set of tools to verify if the model is satisfactory or if it is inadequate and should be
replaced by another model. A model is adequate if it satisfies the model assumptions. The most important one is
that the error term, εt , is a white noise process.

To check the autocorrelation in our residuals we use the Ljunk-Box or the Ljunk Box-Pierce. Our goal is to not reject
H0.

The p value is high so we don’t have evidence


that exists correlation. So we can consider that
our residuals is a white noise process.

Note: the box pierce is better for small samples

How residuals should behave

Introduction to SARIMA models

Forecasting Methods
Examples of SARIMA models:

Forecasting Methods
Exponential Smoothing
Simple exponential smoothing
Forecasts produced using exponential smoothing methods are weighted averages of past observations, with
the weights decaying exponentially as the observations get older.

These methods are very simple but:

• Want something in between these methods.


• Most recent data should have more weight

To forecast using exponential smoothing, we need two parameters:


- α (between 0 and 1) To choose optimal parameters we should minimize the SSE
- ℓ0

ETS – exponential smoothing

Holt’s Linear Trend – models with trend – ETS(A,A,N)

Forecasting Methods
Damped trend method – ETS(A,Ad,N)
In this method we set the trend component as “Ad” (addictive).

Holt-Winters additive method – ETS(A,A,A)

Forecasting Methods
Holt-Winters multiplicative method – ETS(M,A,M)
For when seasonal variations are changing proportional to the level of the series.

Holt-Winters damped method – ETS(M, Ad, M)

Innovations state space models

• Each model has an observation equation and transition equations, one for each state (level, trend, seasonal), i.e.,
state space models.
• Two models for each method: one with additive and one with multiplicative errors, i.e., in total 18 models.
• ETS(Error, Trend, Seasonal)

Forecasting Methods
ETS(A,N,N): A model for SES

ETS(A, A,N): A model for Holt’s method

ETS(A, A,A): HW additive method

ETS(M,N,N): SES with multiplicative errors

Forecasting Methods
ETS(M,A,N): Holt with multiplicative errors

Estimating ETS models

• Smoothing parameters α, β, γ and ϕ, and the initial states ℓ0, b0, s0, s−1, . . . ,s−m+1 are estimated by maximizing
the “likelihood” = the probability of the data arising from the specified model.
• For models with additive errors equivalent to minimizing SSE.

• For models with multiplicative errors, not equivalent to minimizing SSE.

Forecasting with ETS models

Point forecasts: iterate the equations for t = T + 1,T + 2, . . . , T + h and set all εt = 0 for t > T.
• Not the same as E(yt+h|xt) unless trend and seasonality are both additive.

Prediction intervals: can only be generated using the models.


• The prediction intervals will differ between models with additive and multiplicative errors.
• Exact formulae for some models.
• More general to simulate future sample paths, conditional on the last estimate of the states, and to obtain
prediction intervals from the percentiles of these simulated future paths.

Automatic forecasting

• Apply each model that is appropriate to the data. Optimize parameters and initial values using MLE (or some other
criterion).
• Select best method using AICc.

• Produce forecasts using best method.

• Obtain forecast intervals using underlying state space model.

Forecasting Methods
Dynamic Regression
Regression with ARIMA errors

• Be careful in distinguishing η t from εt .


• Only the errors εt are assumed to be white noise.
• In ordinary regression, η t is assumed to be white noise and so η t = εt .

Estimation

If we minimize ∑η2 t (by using ordinary regression):

1. Estimated coefficients βˆ 0, . . . , βˆ k are no longer optimal as some information ignored;

2. Statistical tests associated with the model (e.g., t-tests on the coefficients) are incorrect.

3. p-values for coefficients usually too small (“spurious regression”).


4. AIC of fitted models misleading.

• Minimizing ∑ε2t avoids these problems.

• Maximizing likelihood similar to minimizing ∑ε2t .

Stationary in Regression with ARMA errors


• All variables in the model must be stationary.

• If we estimate the model while any of these are non-stationary, the estimated coefficients can be incorrect.
• Difference variables until all stationary.

• If necessary, apply same differencing to all variables.

Any regression with an ARIMA error can be rewritten as a regression with an ARMA error by differencing all variables
with the same differencing operator as in the ARIMA model.

Forecasting Methods
Model selection

• Fit regression model with automatically selected ARIMA errors. (R will take care of differencing before estimation.)
• Check that εt series looks like white noise.

Forecasting

• To forecast a regression model with ARIMA errors, we need to forecast the regression part of the model and the
ARIMA part of the model and combine the results.
• Some predictors are known into the future (e.g., time, dummies).
• Separate forecasting models may be needed for other predictors.
• Forecast intervals ignore the uncertainty in forecasting the predictors.

Stochastic & deterministic trends

Forecasting with trend


• Point forecasts are almost identical, but prediction intervals differ.
• Stochastic trends have much wider prediction intervals because the errors are non-stationary.
• Be careful of forecasting with deterministic trends too far ahead.

Forecasting Methods
Lagged predictors

Forecasting Methods

You might also like