0% found this document useful (0 votes)
3 views20 pages

Chapter1 Programming R

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)
3 views20 pages

Chapter1 Programming R

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/ 20

Welcome to the

course!
T I M E S E R I E S A N A LY S I S I N R

David S. Matteson
Associate Professor at Cornell University
Introduction
Time Series: A sequence of data in chronological order.
Data is commonly recorded sequentially, over time.

Time series data is everywhere.

TIME SERIES ANALYSIS IN R


Time series example
Monthly values of the Consumer Price Index (CPI):

TIME SERIES ANALYSIS IN R


Time series data
Time series data is dated or time stamped in R.

print(BMW_data)

...
1996-07-08 0.002
1996-07-09 -0.006
1996-07-10 -0.016
1996-07-11 -0.020
1996-07-14 -0.006
1996-07-15 -0.014
1996-07-16 0.002
1996-07-17 -0.001
...

TIME SERIES ANALYSIS IN R


Time series plots
plot(Time_Series)

TIME SERIES ANALYSIS IN R


Basic time series models
White Noise (WN)
Random Walk (RW)

Autoregression (AR)

Simple Moving Average (MA)

1Throughout this course, you will not only be learning how to use R for time
series analysis and forecasting, you will also learn several models for time

TIME SERIES ANALYSIS IN R


Time series plots
T I M E S E R I E S A N A LY S I S I N R
Sampling frequency
T I M E S E R I E S A N A LY S I S I N R

David S. Matteson
Associate Professor at Cornell University
Sampling frequency: exact
Some time series data is exactly evenly spaced.

TIME SERIES ANALYSIS IN R


Sampling frequency: approximate
Some time series data is only approximately evenly spaced.

TIME SERIES ANALYSIS IN R


Sampling frequency: missing values
Some time series data is evenly spaced, but with missing
values.

TIME SERIES ANALYSIS IN R


Basic assumptions
Simplifying assumptions for time series:

Consecutive observations are equally spaced.

Apply a discrete-time observation index.


This may only hold approximately.

Ex. Daily log returns on stock may only be available for


weekdays.

Ex. Monthly CPI values are equally spaced by month, not by


days.

TIME SERIES ANALYSIS IN R


Sampling frequency: R functions
R functions: start() , frequency(Hourly_series)
end() , frequency() ,
deltat()
24
start(Hourly_series)
deltat(Hourly_series)
1 1
0.0417
end(Hourly_series)

1 24

TIME SERIES ANALYSIS IN R


Let's practice!
T I M E S E R I E S A N A LY S I S I N R
Basic time series
objects
T I M E S E R I E S A N A LY S I S I N R

David S. Matteson
Associate Professor at Cornell University
Building ts() objects - I
Start with a vector of data time_series <- ts(data_vector)
plot(time_series)
Apply the ts() function

data_vector

10 6 11 8 10 3 6 9

TIME SERIES ANALYSIS IN R


Building ts() objects - II
Specify the start date and observation frequency:
time_series <- ts(data_vector, start = 2001, frequency = 1)

plot(time_series)

TIME SERIES ANALYSIS IN R


Using is.ts()
The is.ts() function checks whether an object is of the
ts() class:

is.ts(data_vector)

FALSE

is.ts(time_series)

TRUE

TIME SERIES ANALYSIS IN R


Why ts() objects?
Why create and use time series objects of the ts() class?

Improved plotting.

Access to time index information.

Model estimation and forecasting (later chapters).

TIME SERIES ANALYSIS IN R


Let's practice!
T I M E S E R I E S A N A LY S I S I N R

You might also like