How to do Time Series(ts) Analysis using R? part-1

Hi all,

Hope you are familiar with the time series function or you may have heard of time series analysis. In R there is a different R library for time series data analysis [TSDL]. With out loading this library, you can not perform time series analysis. But you don’t have to worry, this is pre-installed library in R software . If not you can simply load this library using

library("tsdl").

Lets learn time series analysis using R step by step. The complete Introduction to R Programming

Index

  1. Introduction
  2. Reading time series data
  3. Plotting time series
  4. Decomposing Time series
  5. Forecast
  6. ARIMA Models

1).  Introduction:

A time series is a series of data points indexed (or listed or graphed) in time order. Most commonly, a time series is a sequence taken at successive equally spaced points in time.

Time series analysis comprises methods for analyzing time series data in order to extract meaningful statistics and other characteristics of the data. Time series forecasting is the use of a model to predict future values based on previously observed values.

2). Reading time series data: 

I am using this data to show how to read time series data. I have downloaded this data to my local. If you don’t want to download you can load the data fro server also by scanning the URL address.   

data<-scan("Book1.csv")
datatimeseries<-ts(data,frequency=1,start=c(1987,1))
datatimeseries

Look at the R console output

 

timeseries

skip=3 means i have ignored the first 3 rows.

data<-scan(“filename”): you have loaded the data into variable name “data”.

datatimeseries<-ts(data,frequency=1,start=c(1987,1)): The data you have loaded into data variable will be in the format of time series.

Frequency: Different for yearly, monthly and quarterly. for yearly frequency=1, monthly frequency = 12 and for quarterly frequency = 4.

start=c(1987,1): Starting of the time to the end.

3). Plotting Time Series:

Lets plot the above loaded time series data, For plotting you will need graphics library.

Library("graphics")

If the library is already installed, then give require(“libraryname”).

plot.ts(datatimeseries)

Look at the time series plot

timeseriesgraph

Will discuss later other steps

If you have any doubts or suggestions please mention in comments section or shoot me an email at irrfankhann29@gmail.com

 

Advertisements

7 thoughts on “How to do Time Series(ts) Analysis using R? part-1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s