Based on @b.gatessucks answer and on @RahulNarain comment tip, I created this functions for the multiplicative decompose case. I changed @b.gatessucks method for seasonality to keep it closer from R method, and used `TemporalData`

to easily handle time interval.

```
decompose[data_,startDate_]:=Module[{dateRange,plot,plotOptions,observedData,observedPlot,trendData,trendPlot,dataDetrended,seasonalData,seasonalPlot,randomData,randomPlot},
dateRange={{startDate,1},Automatic,"Month"};
(*Setting Plot Options*)
plotOptions={AspectRatio -> 0.2,ImageSize-> 600,ImagePadding->{{30,10},{10,5}},Joined->True};
(*Observed data*)
observedData=TemporalData[data,dateRange]["Path"];
observedPlot=DateListPlot[observedData,Sequence@plotOptions];
(*Extracting trend component*)
trendData=Interpolation[MovingAverage[observedData,12],InterpolationOrder->1];
trendPlot=DateListPlot[{#,trendData[#]}&/@observedData[[All,1]],Sequence@plotOptions]//Quiet;
dataDetrended=N@{#[[1]],#[[2]]/trendData[#[[1]]]}&/@observedData//Quiet;
(*Extracting seasonal component*)
seasonalData=Mean/@Flatten[Partition[N@dataDetrended[[All,2]],12,12,1,{}],{2}];
seasonalData=TemporalData[PadRight[seasonalData,Length[data],seasonalData],dateRange]["Path"];
seasonalPlot=DateListPlot[seasonalData,Sequence@plotOptions];
(*Extracting random component*)
randomData=TemporalData[dataDetrended[[All,2]]/seasonalData[[All,2]],dateRange]["Path"];
randomPlot=DateListPlot[randomData,Sequence@plotOptions];
(*Plotting data*)
plot=Labeled[
Grid[Transpose[{Rotate[Style[#,15,Bold],90\[Degree]]&/@{"observed","trend","seasonal","random"}
,{observedPlot,trendPlot,seasonalPlot,randomPlot}}
]
]
,Style["Decomposition of multiplicative time series",Bold,17]
,Top
]
]
```

Using the functions like this:

```
rawData = Import["http://www.massey.ac.nz/~pscowper/ts/cbe.dat"][[2 ;;, 3]];
decompose[rawData, 1958]
```

We get:

Almost exactly as in R!

I say "almost" because R don't use interpolation, so the `MovingAverage`

lost 12 point in R that we don't lose in this function due to interpolation method.
I prefer to keep the ticks in each plot, I find it's better to read. It's a question of personal options.

I would also really like to how to do this solely in Mathematica. My guess is that some of the Version 9 built in time-series functions will make it relatively simple. – Cameron Murray – 2012-12-21T03:38:21.170

1While I have no doubt that Mathematica is meta tool and all that, the fact remains that specialized software do the job better-like for decomposition and econometric analysis, nothing beats Eviews – rselva – 2012-12-21T08:31:06.250

2@rselva Asking in the most constructive spirit, could you provide some examples illustrating your statement ? – b.gates.you.know.what – 2012-12-21T10:54:25.747

@rselva Agree on Eviews (I wish I could afford a personal license). FWIW, as much as I love MMA, using it for econometrics is at best a challenge, and at worse a time killer. I wish MMA's design could be made more flexible for econometrics, but I understand why this would be a messy chore-and-a-half. I plan to learn some R myself (and am pleased they've built in this new capability). For those interested in a version of R that is automatically linked up to Excel, check out: http://rcom.univie.ac.at/

– telefunkenvf14 – 2012-12-21T20:57:35.3531This question would be easier to answer if you could find a reference to the algorithm that R's time series decomposition is using. It might even be described in the documentation. Asking to reverse-engineer the functionality of a magical third-party black box is still a valid question, but a much harder one (as evidenced by your comment on b.gatessucks's answer). – None – 2012-12-23T01:30:13.780

Well, I went ahead and found the documentation: http://stat.ethz.ch/R-manual/R-devel/library/stats/html/decompose.html. It seems pretty easy to implement: just a bunch of moving averages. The period of seasonality is assumed to be 1 unit (12 data points in this case), so no need for a heavy-duty NonlinearModelFit.

– None – 2012-12-23T01:36:21.590@RahulNarain, very nice!.. I'll study it and see how to implement it in Mathematica. Much more simple then my fourier assumption. – Murta – 2012-12-23T01:58:50.037

@b.gatessucks Pl check out Economics top cited papers using Thompson Reuters database or even Google Scholar.Check out top Economics books- all of them have reference to Eviews- typically under 'Methods'.Search for Granger, casualty - all typical terms for econometrics to see EViews influence on Econometric analysis. Better yet try EViews if your university / Office has access to the s/w – rselva – 2012-12-23T03:27:02.863