A matter of time

R allows time series decomposition into seasonal and trend lines using in built stl() function.

The syntax is as follows:

object<-ts(object[,c],start = c(yyyy,mm,dd), freq =12)
plot(stl(object, s.window="periodic"))

where in the above example a data is monthly.
Using an arbitrary dataset I produced the following graphic.

I sought to use Mathematica to produce a similar graphic. The decomposition was relatively straightforward. The graphic formatting was the challenge (and the following results are imperfect).

It required:

  • suppression of the horizontal frame labels of all but the bottom plot
  • changing the vertical spacings of the plots in the GraphicsGrid[]
  • effect of different vertical axis ticks, particularly negative tick values displacing the plot area and leading to misalignment.
  • use of ImageResize[] to render closer resemblance to R plot

The reassuring aspect is the morphology of the seasonal component.
Some attempts at time series decomposition for the same dataset using Mathematica are presented in the following graphics:

First attempt. Note that the seasonal decomposition has not been reference to mean explaining the different scales compared with the R output.

Second attempt: seasonal component referenced to mean

Image resized. Note font distortion

A histogram of the residuals follows:

There was insufficient evidence to reject the null hypothesis of normal distribution. The estimated distribution of the residuals: \epsilon \in N(0, 1.4).

I expect that better methods could be devised and further, alternative formats that could lead to automation of plots without the need for customisation of plot vertical spacings.

 

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: