THE CONCEPT OF TIME SERIES ANALYSIS IN R

INRODUCTION AND DEFINITION.

In most branches of science, engineering and commerce, variables are measured sequentially in time. Reserve banks record interest rates and exchange rates every day.

Government statistics departments compute gross domestic products yearly. When a variable is measured sequentially in time over or at fixed intervals – the sampling interval – the resulting data form a time series.

However, observations that have been collected over fixed sampling intervals form historical time series. In such cases, we take a historical approach where the historical time series are treated as realizations of sequence of random variables.

PLOTS, TRENDS AND SEASONAL VARIATIONS

The number of international passenger bookings (in thousands) per month on an airline (pan Am) in the united states were obtained from Federal Aviation Administration for the period 1949-1960. The company used the data to predict future demand before ordering new aircraft and training aircrew. The data are available as a time series in R and illustrate several important concepts that arise in an exploratory time series analysis. Type the following commands in r and check your results against the output shown here. To save on typing, the data is assigned to variable called AP.

Note: run these commands one after the other….

>data(AirPassengers}

>AP=AirPassengers

>view(AP)

##see the results below

All data in R are stored in objects, which have range of methods available. The class of the object can be found using the class function class(AP); run the code below:

>class(AP)

“ts”

You will see that it gives you ‘ts’ which means time series, indicating that the dataset is a time series data. We can determine the start and end dates as well as the frequency

>start(AP)

The result is 1949

>end(AP)

The result is 1960

>frequency(AP)

The answer is 12 indicating the data was obtained in monthly basis. We can obtain the summary of the data as follows:

>summary(AP)

Plots of data wll be;

>plot(AP,ylab=”Passengers (1000s)”,las=1,col=”chocolate”,lwd=2,main=”TIME PLOT OF AIR PASSENGERS’ BOOKING”,col.main=”navy”,col.lab=”blue”,sub=”Figure I”)

Plots can be put in a single graphics window using the layout function, which takes as input a vector (or matrix) for the location of each plot in the display window.

First of all, run this code to create an empty graphic space;

>windows()

The command windows() helps to create another empty graphical space on which another graph would be plotted.

To obtain the aggregate of the data on annual basis, run the code:

>aggregate(AP)

Aggregate here, means summation of each row for every year, that is the sum of all series (observations) from January to December for every year. Run this code

>layout(1:2)

Run the commands as well

>plot(aggregate(AP),main=”Time Plot of the Yearly Aggregate Bookings”,ylab=””,las=1,col=4,col.main=”red”,lwd=2,sub=”Figure II,col.lab=”coral”)

>boxplot(AP~cycle(AP),main=”Box plot of the Air Passengers’ Bookings”,las=1,col=c(1:12),col.main=”navy”,sub=”Figure III,ylab=””)

COMPUTATION OF TRENDS  AND SEASONAL VARIATIONS

In R, the function “decompose” estimates trends and seasonal effects using a moving average method. This can be obtained as follows:

>dec=decompose(AP) ##the default type of model is additive

>print(dec)

>plot(dec,col=2,lwd=2,sub=”Figure IV”)

Leave a Reply

Your email address will not be published. Required fields are marked *

More Articles & Posts