A time series is made up of several elements, namely the observed, trend, seasonal and random elements.
Decomposition is the method by which we extract each element from an observed time series.
What do we mean by each of these?
Elements of a Time Series
- Observed: This is the time series “as is”, i.e. the actual data points that we observe across the original time series.
- Trend: A trend describes the overall direction of a time series. e.g. for this time series, we see that the general trend is upwards over time. Therefore, the trend shows a long-term increase. A trend also represents the portion of a time series that has variations of low frequency.
- Seasonal: The seasonal portion of the time series represents particular time periods where there is a significant deviation in the data. This deviation is usually directly related to the particular time period where the shift occurs. For instance, if one is analysing sales and figures spike up over Christmas time, this is due to a seasonal shift.
- Random: The random element of a time series is one where fluctuations are not very predictable, and are not being influenced by the elements outlined above. Therefore, this component of the time series remains unexplained and is not particularly useful for forecasting purposes.
Using decomposition, it is possible to split the time series into its elements. For instance, suppose that we observe particular peaks and valleys in data at certain intervals. Is this seasonality-induced or simply random? Decomposition allows us to figure this out.
Decomposition Example
Let’s take a hypothetical 10-year time series dataset with an annual growth of 9 percent and volatility of 15 percent. The dataset is generated by means of Brownian Motion.
1. Firstly, we stack our data in R into periods of 12 months:
pricetimeseries <- ts(price, frequency=12, start=c(2005,1))
> pricetimeseries
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2005 500.0000 541.2439 526.5013 551.0514 540.5827 514.3329 491.9740 489.4631 488.9738 492.3253 516.7793 521.8121
2006 504.9705 528.3009 568.7668 552.2308 532.3383 532.0111 591.2718 554.6121 555.9807 593.6032 563.9333 577.1098
2007 593.6958 561.9326 591.1153 665.2396 636.7973 613.3456 636.6896 701.8802 754.5975 728.0549 714.7095 694.6709
2008 707.9059 690.9421 722.0142 789.3634 792.3824 802.7935 772.6972 804.9252 857.8302 966.1737 992.8240 990.5000
2009 976.0028 983.2667 972.8880 984.1440 1029.3636 1070.9459 1146.2044 1178.8113 1220.5092 1274.6487 1273.9045 1379.8261
2010 1468.4127 1487.9828 1439.7403 1428.1181 1401.1307 1403.2463 1383.9310 1446.6171 1395.8787 1380.4445 1397.4217 1544.6010
2011 1584.6387 1773.4895 1602.3330 1526.4886 1545.9674 1595.9804 1684.5142 1773.6467 1682.4303 1735.6806 1794.3587 1921.4301
2012 2029.2455 1882.5611 2030.4814 2073.4115 1961.4187 2213.5897 2102.9015 2277.0280 2285.9271 2160.1356 2124.1639 1951.9991
2013 1931.7909 1881.9828 1894.6552 2041.6443 2135.3248 2442.6593 2592.6303 2664.4166 2634.0081 2890.3535 2992.4778 2983.7225
2014 2904.0352 3039.0263 3096.3050 3294.4045 3262.4493 3437.1290 3275.2508 3300.6543 3391.6936 3527.3727 3521.3571 3617.1176
2015 3455.2405
2. We decompose our data in order to estimate the observed, trend, seasonal and random portions of our model:
library("TTR")
pricetimeseriescomponents <- decompose(pricetimeseries)
pricetimeseriescomponents
$x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2005 500.0000 541.2439 526.5013 551.0514 540.5827 514.3329 491.9740 489.4631 488.9738 492.3253 516.7793 521.8121
2006 504.9705 528.3009 568.7668 552.2308 532.3383 532.0111 591.2718 554.6121 555.9807 593.6032 563.9333 577.1098
2007 593.6958 561.9326 591.1153 665.2396 636.7973 613.3456 636.6896 701.8802 754.5975 728.0549 714.7095 694.6709
2008 707.9059 690.9421 722.0142 789.3634 792.3824 802.7935 772.6972 804.9252 857.8302 966.1737 992.8240 990.5000
2009 976.0028 983.2667 972.8880 984.1440 1029.3636 1070.9459 1146.2044 1178.8113 1220.5092 1274.6487 1273.9045 1379.8261
2010 1468.4127 1487.9828 1439.7403 1428.1181 1401.1307 1403.2463 1383.9310 1446.6171 1395.8787 1380.4445 1397.4217 1544.6010
2011 1584.6387 1773.4895 1602.3330 1526.4886 1545.9674 1595.9804 1684.5142 1773.6467 1682.4303 1735.6806 1794.3587 1921.4301
2012 2029.2455 1882.5611 2030.4814 2073.4115 1961.4187 2213.5897 2102.9015 2277.0280 2285.9271 2160.1356 2124.1639 1951.9991
2013 1931.7909 1881.9828 1894.6552 2041.6443 2135.3248 2442.6593 2592.6303 2664.4166 2634.0081 2890.3535 2992.4778 2983.7225
2014 2904.0352 3039.0263 3096.3050 3294.4045 3262.4493 3437.1290 3275.2508 3300.6543 3391.6936 3527.3727 3521.3571 3617.1176
2015 3455.2405
$seasonal
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2005 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2006 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2007 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2008 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2009 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2010 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2011 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2012 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2013 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2014 -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
2015 -2.509453
$trend
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2005 NA NA NA NA NA NA 514.7937 514.4616 515.6833 517.4935 517.1992 517.5922
2006 522.4662 529.3182 534.8247 541.8366 548.0212 552.2900 558.2910 563.3892 565.7217 571.3616 580.4228 588.1642
2007 593.4455 601.4741 615.8859 629.7638 641.6483 652.8290 662.4862 672.6203 683.4498 694.0758 705.7303 720.1067
2008 733.6673 743.6278 752.2227 766.4457 787.9554 811.8698 835.3667 858.7176 881.3508 899.9198 917.9098 938.9571
2009 965.6929 996.8343 1027.5245 1055.4893 1080.0541 1107.9877 1144.7267 1186.2736 1226.7556 1264.7067 1298.6959 1328.0321
2010 1351.7832 1372.8470 1391.3127 1403.0279 1412.5826 1424.5948 1436.3032 1453.0420 1471.7128 1482.5863 1492.7199 1506.7854
2011 1527.3403 1553.4908 1579.0567 1605.7978 1637.1384 1669.3786 1703.6051 1726.6751 1749.0592 1789.6872 1829.7861 1872.8303
2012 1915.9968 1954.4039 2000.5238 2043.3551 2074.7826 2089.7982 2087.0113 2082.9266 2077.2431 2070.2600 2076.1825 2092.9732
2013 2122.9231 2159.4696 2190.1142 2235.0433 2301.6488 2380.8170 2464.3157 2553.0360 2651.3149 2753.5820 2852.7439 2941.1436
2014 3011.0224 3065.9748 3124.0549 3182.1676 3230.7467 3279.1748 3328.5332 NA NA NA NA NA
2015 NA
$random
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
2005 NA NA NA NA NA NA -19.4223348 -58.4776817 -35.0316644 -47.2573529 -13.7795456
2006 -14.9862776 13.0828396 64.6272826 20.0417748 28.3561046 -38.5028903 36.3781936 -42.2563457 -18.0631390 0.1525175 -29.8491296
2007 2.7597374 -25.4413011 5.9145072 45.1233383 39.1879973 -57.7073699 -22.3992308 -4.2193575 62.8256115 11.8900900 -4.3804144
2008 -23.2519989 -38.5856602 0.4765708 32.5651923 48.4659205 -27.3002184 -59.2720868 -87.2715770 -31.8427716 44.1648885 61.5544873
2009 12.8193068 0.5325453 -23.9513855 -61.6977621 -6.6514911 -55.2656870 4.8751444 -40.9415341 -14.5684656 -12.1471391 -38.1510732
2010 119.1389086 129.2358641 79.1127758 34.7377275 32.5871362 -39.5724485 -48.9748086 -39.9041017 -84.1562050 -124.2308824 -108.6579257
2011 59.8078778 234.0988021 53.9614619 -69.6617112 -47.1319471 -91.6221767 -15.6935569 13.4923715 -74.9510234 -76.0957148 -48.7870755
2012 115.7581424 -57.7426351 60.6427592 39.7038825 -69.3249794 105.5675353 19.2875814 160.6221901 200.3619256 67.7865257 34.6217240
2013 -188.6226873 -263.3867536 -264.7738742 -183.7515092 -122.2849823 43.6183421 131.7120193 77.9013658 -25.6289384 114.6823972 126.3742824
2014 -104.4776796 -12.8483715 2.9352320 121.8843968 75.7415710 139.7302430 -49.8849986 NA NA NA NA
2015 NA
Dec
2005 -4.6847673
2006 -19.9589725
2007 -34.3404013
2008 42.6382806
2009 42.8893841
2010 28.9110049
2011 39.6951704
2012 -149.8786775
2013 33.6743083
2014 NA
2015
$figure
[1] -2.509453 -14.100128 -30.685117 -9.647518 -44.039006 18.223937 -3.397367 33.479217 8.322089 22.089082 13.359657 8.904607
$type
[1] "additive"
attr(,"class")
[1] "decomposed.ts"
plot(pricetimeseriescomponents)

Observations
- Trend: The graph in our decomposition series shows an upward trend, and we can see that we have the short-term peaks and valleys smoothed out. For instance, moving averages are an example of a trend, where short-term fluctuations are “averaged out” over a period of time.
- Seasonal: From looking at the data, we see that there are particularly large bottoms and tops in May and August. This implies that we are observing a particularly sharp seasonal trend around those months.
- Random: As mentioned, the random element of the data is that which is free of any trend or seasonality. Therefore, the values we observe under the random heading are just that – random. They cannot particularly be used for forecasting purposes.
Hi,
As per acf graph can we consider it AR1 or it can be AR 2 also?
Hi Ajeet,
We didn’t calculate the number of lags directly here, merely decomposed the time series into its separate elements.
However, when we run the Dickey-Fuller test on the time series, we see it is AR(1). We know this because an AR(1) series is one that becomes stationary when we obtain first differences.
By first differencing the series and then running the Dickey-Fuller test, we see that we have a highly significant p-value, indicating stationarity: