Time Series Decomposition

I want to use the function decompose in my time-series data, a yearly dataset.

tsData <- ts(Clean_Data$`GDP Growth Rate (%)`, start = c(1960,1), frequency = 1)
tsData

then this is the result

Time Series:
Start = c(1960, 1) 
End = c(2020, 1) 
Frequency = 1
 [1]           NA  0.056165793  0.047731218  0.070604874  0.034469821  0.052658105  0.044259942
 [8]  0.053241502  0.049454181  0.046563586  0.037646049  0.054286314  0.054467911  0.089206468
[15]  0.035581151  0.055647736  0.088066306  0.056020556  0.051721033  0.056396757  0.051489113
[22]  0.034232692  0.036193276  0.018746165 -0.073236826 -0.073066088  0.034167828  0.043116348
[29]  0.067525445  0.062053111  0.030369663 -0.005783347  0.003376030  0.021163072  0.043876233
[36]  0.046786922  0.058458735  0.051853623 -0.005767181  0.030819165  0.044112222  0.030492313
[43]  0.037162550  0.050869111  0.065692285  0.049425051  0.053164168  0.065192916  0.043444873
[50]  0.014483231  0.073345000  0.038582328  0.068969517  0.067505313  0.063479875  0.063483097
[57]  0.071494567  0.069309883  0.063414856  0.061185257 -0.095730299

So if I use the decompose function here

components.ts = decompose(tsData)

The problem is that I keep getting an error saying...

Error in decompose(tsData) : time series has no or less than 2 periods

I know that if I put 12 in frequency, this will divide my dataset monthly, and that's not what I want to happen.

My question is, how can I use the decompose function on a yearly basis?

Thanks in advance!

This drove me nuts with stl until I found that i needed 2n + 1, points, where n is your frequency.

1 Like

It is not clear why you are using decompose (Classical Seasonal Decomposition by Moving Averages) for data that has no seasonality.

For ideas on methods that smooth out the random effects and leave the trend/cycle, see Chapter 28 of Irizarry's Introduction to Data Science at Chapter 28 Smoothing | Introduction to Data Science

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.