5
$\begingroup$

In another question (Using TimeSeriesForecast for forecasting the traffic growth) I asked to use the TimeSeriesForecast on this set of data the answer provided the plot with and without the seasonalization for the future value.

Is it possible to get the same plot (without seasonalization) for data which are already available (now this is only for the forecasted one)?

EDIT

The SARIMA model has the seasonal peaks. Is it possible to calculate the same model also for the range of dates on which I provided the data?

If that is possible maybe I could use the model of the periodic peaks to modulate the real data getting rid of the data seasonality.

What I would be curious to get is not a regression (which would be a flat line) but the deseasonalized data.

enter image description here enter image description here

$\endgroup$
5
  • $\begingroup$ What is stagionalization? $\endgroup$
    – C. E.
    Mar 26, 2015 at 12:05
  • $\begingroup$ @Pickett: sorry, my english is terrible. I meant seasonalization, I will correct. Thanks for telling me. $\endgroup$
    – Revious
    Mar 26, 2015 at 12:28
  • 1
    $\begingroup$ I'm not sure what you mean with deseasonalized without making a regression. Do you mean filtering or smoothing? Or something like this, this or this, which are all different kinds of regressions? $\endgroup$
    – Karsten 7.
    Mar 26, 2015 at 12:38
  • $\begingroup$ @Karsten7. I am not sure if what I want can be achieved. I will edit the question. ps: how did you managed to get the 3 images? $\endgroup$
    – Revious
    Mar 26, 2015 at 13:44
  • 1
    $\begingroup$ The last one was created using something like what I show in my answer. The other two were produced by fitting a function, that is not a straight line, to the data (, but this is still doing a linear regression). $\endgroup$
    – Karsten 7.
    Mar 26, 2015 at 15:31

2 Answers 2

3
$\begingroup$

Removing seasonality by using MeanFilter:

data = MapAt[DateString[{#, {"Day", "/", "Month", "/", "Year"}}] &,
 Import["D:\\Analytics www.superinformati.com Panoramica del pubblico 20141201-20150303 - Sheet 1.tsv"][[3 ;;, {1, 2}]]
 , {All, 1}]

DateListPlot[{data, 
 Transpose[{data[[All, 1]], MeanFilter[data[[All, 2]], 7]}]}]

MeanFiltered

$\endgroup$
3
  • 2
    $\begingroup$ I used a range of 7 for the MeanFilter, as the SARIMA model revealed a seasonal order of 7 and because assuming a weekly seasonality makes sense. $\endgroup$
    – Karsten 7.
    Mar 26, 2015 at 16:30
  • $\begingroup$ Thanks a lot. And really great job, if you want there is also a last question mathematica.stackexchange.com/questions/78311/… $\endgroup$
    – Revious
    Mar 26, 2015 at 17:19
  • $\begingroup$ How could you see that the seasonality is 7 days? $\endgroup$
    – Revious
    May 7, 2015 at 20:06
3
$\begingroup$

Your description of what you want to do is quite vague and the "not a regression" part is kind of contradictory. Therefore I'll take

"Is it possible to calculate the same model also for the range of dates on which I provided the data?"

part to formulate an answer.

Importing your data saved in TSV format

data = MapAt[DateString[{#, {"Day", "/", "Month", "/", "Year"}}] &,
 Import["D:\\Analytics www.superinformati.com Panoramica del pubblico 20141201-20150303 - Sheet 1.tsv"][[3 ;;, {1, 2}]]
 , {All, 1}]

Finding the SARIMA process

tsm = TimeSeriesModelFit[data]

One can use RandomFunction to create multiple simulations assuming a random process. The following code produces 5 simulations. I use Length@data - 30 because your data looks like the real trend starts somewhere after 30 days.

rf1 = RandomFunction[tsm["BestFit"], {Length@data - 30}, 5]

Creating a plot of these simulations and of their mean

randomP1 = 
 DateListPlot[Transpose[{data[[30 ;;, 1]], #}] & /@ rf1["States"], 
  PlotStyle -> Opacity[1/2], 
  PlotRange -> {{data[[1, 1]], data[[-1, 1]]}, Automatic}]

meanP1 = DateListPlot[
  Transpose[{data[[30 ;;, 1]], TimeSeriesThread[Mean, rf1]["PathStates"]}], 
  PlotStyle -> Red, PlotRange -> {{data[[1, 1]], data[[-1, 1]]}, Automatic}]

Putting everything into one plot

Show[{randomP1,
 DateListPlot[data, PlotStyle -> Directive[Black, Thick]],
 meanP1}]

SARIMA

Doing the same using a ARIMA model

tsm2 = TimeSeriesModelFit[data, "ARIMA"]    

rf2 = RandomFunction[tsm2["BestFit"], {Length@data - 30}, 5]

randomP2 = 
 DateListPlot[Transpose[{data[[30 ;;, 1]], #}] & /@ rf2["States"], 
  PlotStyle -> Opacity[1/2], 
  PlotRange -> {{data[[1, 1]], data[[-1, 1]]}, Automatic}]

meanP2 = DateListPlot[
  Transpose[{data[[30 ;;, 1]], TimeSeriesThread[Mean, rf2]["PathStates"]}], 
  PlotStyle -> Red, PlotRange -> {{data[[1, 1]], data[[-1, 1]]}, Automatic}]

Show[{randomP2,
 DateListPlot[data, PlotStyle -> Directive[Black, Thick]],
 meanP2}]

ARIMA

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.