Time Series Analysis with R programming

Here is a tutorial on how to use R programming software to carry out time series analysis

To load data set from the package “fma”, use the commands:

>data (package=fma)
This instantly loads the pre existing data sets in the package.

To load the data set regarding sales of one family houses, use the command:
>data (hsales)

To print the data:
>hsales
Time Series Analysis with R programming

How to create a time series data in R programming?

Now, form a time series from the data using the command:

>timeseries <- ts (hsales, frequency=12, start=1973)
Here, the variable name is “timeseries”, feequency is 12(because it is monthly data), and start=1 (since the data starts from 1973)

Now, print the series:
>timeseries
time series data in R programming

How to plot the time series graph in R program?

To plot the time series, use the command:
>plot.ts (timeseries, main=”Sales of one family houses”)
Time series Analysis using R program

Decomposing an additive and multiplicative Time Series model in R

To decompose the time series into its components, use the command in R statistical software:
>timeseriescomponents <- decompose (timeseries)

Print the decomposed series, 
>timeseriescomponents
Time series Analysis using R program image 1 Time series Analysis using R program image 2 Time series Analysis using R program image 3
You can also plot the decomposed time series components using R software
>plot (timeseriescomponents)
Time series Analysis using R program image 4