0% found this document useful (0 votes)
29 views37 pages

Timeseries - Analysis

The document discusses time series forecasting and analysis. It defines a time series as a series of data points indexed in time order, with examples like daily bus passengers or stock prices. Time series forecasting uses models to predict future values based on past time and data. The document outlines extracting patterns from time series through analysis, and modeling trends, seasonality, and randomness. It also covers loading, decomposing, and modeling time series data in R.

Uploaded by

Grace Yin
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)
29 views37 pages

Timeseries - Analysis

The document discusses time series forecasting and analysis. It defines a time series as a series of data points indexed in time order, with examples like daily bus passengers or stock prices. Time series forecasting uses models to predict future values based on past time and data. The document outlines extracting patterns from time series through analysis, and modeling trends, seasonality, and randomness. It also covers loading, decomposing, and modeling time series data in R.

Uploaded by

Grace Yin
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/ 37

Time Series Forecasting

Time Series Forecasting

• A time series is a series of data points indexed in time


order
Time Series Forecasting

• A time series is a series of data points indexed in time


order
• Examples of time series are daily number of passengers on a
bus, monthly energy demand, weekly sales of a certain
product, and the daily closing value of Tesla stock.
Time Series Forecasting

• A time series is a series of data points indexed in time


order
• Examples of time series are daily number of passengers on a
bus, monthly energy demand, weekly sales of a certain
product, and the daily closing value of Tesla stock.
• Time series are very frequently plotted via line charts where
the x-axis is the time.
Time Series Forecasting
Time Series Forecasting

• Time series analysis extracts meaningful statistics and


characteristics from the time series data (trends, seasonality,
etc.).
• Time series forecasting is the use of a model to predict
future values based on time and previously observed values.
Time Series Forecasting

• Time series analysis extracts meaningful statistics and


characteristics from the time series data (trends, seasonality,
etc.).
• Time series forecasting is the use of a model to predict
future values based on time and previously observed values.
• Typically the time series is Discrete meaning that the data is
recorded at discrete times (hourly, daily, monthly, etc.).
Time Series Forecasting

• Time series analysis extracts meaningful statistics and


characteristics from the time series data (trends, seasonality,
etc.).
• Time series forecasting is the use of a model to predict
future values based on time and previously observed values.
• Typically the time series is Discrete meaning that the data is
recorded at discrete times (hourly, daily, monthly, etc.).
• Note that a discrete time series does not mean that the data
is discrete.
Time Series Analysis

Objectives of time series analysis:


1. Description: summary statistics, plots and graphs
2. Analysis and Interpretation: find a model to describe the
time dependence in the data, can we interpret the model?
3. Forecasting: forecast the next value, or the next few values
Data Cleaning

Questions to ask to check for data inconsistencies


• Is data missing?
• Does the data fall within expected ranges?
• Are there outliers or unusual values?

Graphical as well as analytical methods can be useful


Data Imputation

Correcting Inconsistent Values


Data Imputation

Correcting Inconsistent Values


Do Nothing: Leave as is and use robust models.
Data Imputation

Correcting Inconsistent Values


Do Nothing: Leave as is and use robust models.
Mean Value: Replace the missing value with the average.
Data Imputation

Correcting Inconsistent Values


Do Nothing: Leave as is and use robust models.
Mean Value: Replace the missing value with the average.
Stochastic Mean Value: Replace the missing value with a random
value added to the average.
Data Imputation

Correcting Inconsistent Values


Do Nothing: Leave as is and use robust models.
Mean Value: Replace the missing value with the average.
Stochastic Mean Value: Replace the missing value with a random
value added to the average.
Window Mean Value: Replace the missing value with the average
k values that are before and after.
Data Imputation

Correcting Inconsistent Values


Do Nothing: Leave as is and use robust models.
Mean Value: Replace the missing value with the average.
Stochastic Mean Value: Replace the missing value with a random
value added to the average.
Window Mean Value: Replace the missing value with the average
k values that are before and after.
Regression: Use regression to predict the missing value.
Time Series Models
Time Series Models

1. Regression models that use time indices as x-variables.


These can be helpful for an initial description of the data and
form the basis of several simple forecasting methods.
Time Series Models

1. Regression models that use time indices as x-variables.


These can be helpful for an initial description of the data and
form the basis of several simple forecasting methods.
2. Smoothing models such as moving average and exponential
smoothing.
Time Series Models

1. Regression models that use time indices as x-variables.


These can be helpful for an initial description of the data and
form the basis of several simple forecasting methods.
2. Smoothing models such as moving average and exponential
smoothing.
3. ARIMA (Autoregressive Integrated Moving Average) models
that relate the present value of a series to past values and
past prediction errors.
Time Series Data Variations

Trend: long-term change in the mean level.


Seasonal variation: sales figures exhibit variation that is annual in
period.
Cyclic variation: variation at other fixed periods.
Time Series Data Variations

Trend: long-term change in the mean level.


Seasonal variation: sales figures exhibit variation that is annual in
period.
Cyclic variation: variation at other fixed periods.

Examples
• Sales of a given item increases due to population increase.
• Swim suits sales are high in the summer and low in the winter.
• Economic data is affected by business cycles.
Time Series Model Components
Questions to Ask
Questions to Ask

• Is there a trend, i.e. do the measurements tend to increase


(or decrease) over time?
Questions to Ask

• Is there a trend, i.e. do the measurements tend to increase


(or decrease) over time?
• Is there seasonality, i.e. is there a regularly repeating pattern
of highs and lows related to calendar time such as seasons,
quarters, months, days of the week?
Questions to Ask

• Is there a trend, i.e. do the measurements tend to increase


(or decrease) over time?
• Is there seasonality, i.e. is there a regularly repeating pattern
of highs and lows related to calendar time such as seasons,
quarters, months, days of the week?
• Is there a long-run cycle or period unrelated to seasonality
factors?
Questions to Ask

• Is there a trend, i.e. do the measurements tend to increase


(or decrease) over time?
• Is there seasonality, i.e. is there a regularly repeating pattern
of highs and lows related to calendar time such as seasons,
quarters, months, days of the week?
• Is there a long-run cycle or period unrelated to seasonality
factors?
• Are their outliers?
In regression, outliers are far away from your line.
In time series data, outliers are far away from the other data.
Loading Time Series Data in R

Load the data from a csv file (or any other place where the
data is stored)
tempToronto <- read.csv("torontoTemperature.csv", header=TRUE)
head(tempToronto)

Get the start date


startYear = tempToronto$Year[1]
startMonth = tempToronto$Month[1]
Loading Time Series Data in R
Create the Time Series of the Average Temperature
TorontoTempts <- ts(tempToronto$AvgTemperature, start=c(startYear, startMonth),
frequency=12)

• Note that the frequency is set to 12 as it is monthly data.


• Quarterly data frequency = 4, Yearly Data frequency = 1,
Daily Data frequency = 365.25 (Why 365.25?)
Plot the Time Series
plot(TorontoTempts)
Time Series Model

• The four components of a time series model (m: trend, s:


seasonal, c: cyclical, r : random)
Time Series Model

• The four components of a time series model (m: trend, s:


seasonal, c: cyclical, r : random)
• Two different models
Additive: yt = mt + st + ct + rt
Multiplicative: yt = mt × st × ct × rt
Time Series Model

• The four components of a time series model (m: trend, s:


seasonal, c: cyclical, r : random)
• Two different models
Additive: yt = mt + st + ct + rt
Multiplicative: yt = mt × st × ct × rt
The cyclical component is typically ignored.
Additive: yt = mt + st + rt
Multiplicative: yt = mt × st × rt
Time Series Model

• The four components of a time series model (m: trend, s:


seasonal, c: cyclical, r : random)
• Two different models
Additive: yt = mt + st + ct + rt
Multiplicative: yt = mt × st × ct × rt
The cyclical component is typically ignored.
Additive: yt = mt + st + rt
Multiplicative: yt = mt × st × rt
• The additive model is appropriate if the magnitude of the
seasonal fluctuation does not vary over time.
• A multiplicative model is appropriate when the magnitude of
the seasonal fluctuation changes over time.
Time Series Model

Additive: Multiplicative:
Beer Production Data: the Airline passengers Data: with
magnitude of the seasonality time the magnitude of the
stays constant over time seasonality increases
(1950s-1980s). (1950s-1970s).
Time Series Model
Time Series Decomposition identifies the trend, seasonality, and
random components of the time series.
Time Series Decomposition in R
TorontoTemptsDecomposed = decompose(TorontoTempts)
plot(TorontoTemptsDecomposed)
#You can also print TorontoTemptsDecomposed for the detailed numbers

For a multiplicative model add type=“multiplicative” to the


decompose function
TorontoTemptsDecomposed = decompose(TorontoTempts, type="multiplicative")

You might also like