Skip to contents

Main decomposition algorithm

Usage

StructuralDecompose(
  Data,
  frequency = 12,
  break_algorithm = "strucchange",
  smoothening_algorithm = "lowess",
  break_level = 0.05,
  median_level = 0.5,
  mean_level = 0.5,
  level_length = 12,
  conf_level = 0.5,
  window_len = 12,
  plot = FALSE
)

Arguments

Data

Time series required

frequency

Frequency of the tine series

break_algorithm

breakpoints algorithm used. Defaults to strucchange

smoothening_algorithm

Smoothing algorithm used. Defaults to lowess

break_level

Break level for the breakpoints algorithm

median_level

Average median distance between two level

mean_level

Average mean distance between a group of points near breakpoints

level_length

Minimum number of points required to determine a level

conf_level

Confidence level for Anomaly detection, best to keep this a static value

window_len

Length of the Moving window for Anomaly Detection

plot

True of False indicating if you want the internal plots to be generated

Value

The decomposed time series along with a host of other metrics

Examples

StructuralDecompose(Data = StructuralDecompose::Nile_dataset[,1])
#> $anomalies
#>  [1]  7  9 12 18 25 26 28 32 39 43 46 47 59 84 94
#> 
#> $trend_line
#>   [1] 1132.6414 1127.7249 1122.8799 1118.1309 1113.5251 1109.1044 1104.9009
#>   [8] 1100.9425 1097.2713 1093.9101 1090.8337 1087.9628 1085.1639 1082.2270
#>  [15] 1078.8593 1077.4766 1075.0220 1071.2022 1065.9538 1059.3129 1051.4334
#>  [22] 1042.5699 1033.1416 1023.1102 1012.4993 1001.5739  990.6492  979.6720
#>  [29]  968.1119  955.4056  941.3736  926.1223  910.2829  895.1017  881.6144
#>  [36]  870.2716  861.2360  854.3718  849.5573  846.5968  845.0726  844.2166
#>  [43]  843.2879  841.6887  839.4095  836.7515  833.9392  831.1646  828.5177
#>  [50]  826.3109  825.0823  825.2013  826.8053  829.4168  832.4399  835.2395
#>  [57]  837.3651  838.6601  839.3156  839.5099  839.2957  838.6227  837.7486
#>  [64]  837.0697  836.9403  837.4794  838.5937  839.7983  840.5090  840.4231
#>  [71]  839.7779  838.9286  838.3233  838.1007  838.3640  839.5720  842.0796
#>  [78]  846.0802  851.4910  857.9386  865.0322  872.2299  878.8293  884.2546
#>  [85]  888.1896  890.4884  888.0231  884.1477  879.9246  875.6166  871.2662
#>  [92]  866.8725  862.4037  857.8173  853.0628  848.0717  842.7768  837.1301
#>  [99]  831.0880  824.6332
#> 
#> $Deseasonalized_Series
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1  -16.301071    7.212120 -130.146716   33.842108   22.913295  106.587534
#> 2   21.176401 -113.290058  -29.126178 -175.503529   81.416363 -216.510323
#> 3  243.841057  193.363115   69.083936   62.301068 -217.673477  -59.713677
#> 4 -172.895693  140.565172  230.175912   64.376235  -37.634240  -62.524662
#> 5  -68.177335  -30.373880  -27.349145  -38.228239   13.633086   88.275101
#> 6  -61.955409    1.314332   36.984558   48.903328  123.498103  115.212542
#> 7  -29.982991 -121.163662   -7.630840  142.401040   -5.641195   83.611712
#> 8   26.150750   70.448628  -61.289958  -19.174691   71.513831   -4.924663
#> 9   72.563522 -144.193133  -87.354843 -142.660146                        
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -178.362310  107.640463  280.629063   -2.777303 -110.181835 -164.883341
#> 2    5.584820   59.270138   56.466998  118.562916  102.510278  214.969303
#> 3   46.165053 -253.539298   37.617500 -110.968938 -194.962485   33.807910
#> 4 -273.749268  -39.105700 -129.509072  234.381308  251.712758  -11.085086
#> 5  -20.901286  -11.656483  -85.464717  -91.527316  186.336306  -92.430391
#> 6   96.944961  148.784723  -61.608596 -213.290334 -205.126002   -4.849105
#> 7  110.047580   10.644431 -113.131784 -172.097124  -55.177400  153.824891
#> 8  262.272386   17.710485   46.496708  263.315467   44.589118 -113.992247
#> 9                                                                        
#> 
#> $breakpoints
#> [1]   0 100
#> 
#> $trend
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1   1.2421572   1.9488900   2.6556229   1.8374821   1.0193414  -0.9987736
#> 2 -35.5664255 -39.6878214 -43.8092173 -36.5350731 -29.2609290  -7.8819454
#> 3  77.4646221  64.8418089  52.2189956  31.0445142   9.8700328 -12.5170711
#> 4 -27.8149987 -26.5430151 -25.2710315 -15.6843846  -6.0977376   0.8006031
#> 5  10.1603451  11.1176238  12.0749026   4.7387211  -2.5974605  -6.9782883
#> 6  16.6574764  23.8771710  31.0968656  27.9809336  24.8650016  16.4780471
#> 7 -24.2336794 -21.7806176 -19.3275558 -13.9802033  -8.6328507  -2.6471656
#> 8   8.0227433  18.8045669  29.5863905  41.9583684  54.3303462  56.0570166
#> 9 -25.6243660 -42.7271398 -59.8299135 -78.6256823                        
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1  -3.0168887  -5.2800027  -7.5431168 -12.4592535 -17.3753903 -26.4709079
#> 2  13.4970381  35.3131995  57.1293608  68.7867615  80.4441623  78.9543922
#> 3 -34.9041749 -42.6844611 -50.4647473 -43.7418287 -37.0189100 -32.4169544
#> 4   7.6989438   3.7825804  -0.1337831  -2.2389057  -4.3440284   2.9081583
#> 5 -11.3591160  -9.6159925  -7.8728690  -3.8135349   0.2457991   8.4516377
#> 6   8.0910927   0.5749302  -6.9412322 -13.4265367 -19.9118411 -22.0727602
#> 7   3.3385196   5.7046547   8.0707899   5.8898717   3.7089534   5.8658483
#> 8  57.7836871  44.9076405  32.0315939  18.2178416   4.4040893 -10.6101384
#> 9                                                                        
#> 
#> $seasonality
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 2    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 3    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 4    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 5    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 6    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 7    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 8    3.659677   25.063010  -29.733169   58.026966   23.561600  -55.691921
#> 9    3.659677   25.063010  -29.733169   58.026966                        
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 2 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 3 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 4 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 5 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 6 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 7 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 8 -113.538616   21.417009   -7.900391   48.867217   14.348092   11.920512
#> 9                                                                        
#> 
#> $remainder
#>            Jan          Feb          Mar          Apr          May          Jun
#> 1  -17.5432285    5.2632298 -132.8023390   32.0046259   21.8939539  107.5863076
#> 2   56.7428264  -73.6022366   14.6830398 -138.9684562  110.6772922 -208.6283775
#> 3  166.3764347  128.5213059   16.8649408   31.2565540 -227.5435099  -47.1966056
#> 4 -145.0806940  167.1081875  255.4469438   80.0606192  -31.5365028  -63.3252654
#> 5  -78.3376805  -41.4915041  -39.4240478  -42.9669598   16.2305463   95.2533890
#> 6  -78.6128853  -22.5628388    5.8876921   20.9223944   98.6331018   98.7344947
#> 7   -5.7493119  -99.3830447   11.6967162  156.3812434    2.9916559   86.2588778
#> 8   18.1280069   51.6440610  -90.8763481  -61.1330589   17.1834848  -60.9816799
#> 9   98.1878883 -101.4659935  -27.5249295  -64.0344638                          
#>            Jul          Aug          Sep          Oct          Nov          Dec
#> 1 -175.3454218  112.9204659  288.1721800    9.6819503  -92.8064452 -138.4124329
#> 2   -7.9122182   23.9569385   -0.6623624   49.7761542   22.0661157  136.0149113
#> 3   81.0692275 -210.8548372   88.0822477  -67.2271090 -157.9435747   66.2248648
#> 4 -281.4482115  -42.8882807 -129.3752893  236.6202138  256.0567861  -13.9932440
#> 5   -9.5421702   -2.0404901  -77.5918484  -87.7137810  186.0905074 -100.8820291
#> 6   88.8538681  148.2097928  -54.6673642 -199.8637970 -185.2141611   17.2236553
#> 7  106.7090605    4.9397758 -121.2025744 -177.9869959  -58.8863536  147.9590430
#> 8  204.4886990  -27.1971558   14.4651145  245.0976255   40.1850291 -103.3821087
#> 9                                                                              
#> 

StructuralDecompose(Data = runif(n = 50, min = 1, max = 10))
#> $anomalies
#> [1]  2  6 10 35 42
#> 
#> $trend_line
#>  [1] 4.175138 4.108641 4.066601 4.041519 4.024664 4.013865 4.016407 4.097851
#>  [9] 4.433594 4.756974 5.090278 5.472748 5.931888 6.374898 6.717487 6.891046
#> [17] 6.891452 6.687846 6.412101 6.164513 5.980492 5.789847 5.670809 5.665345
#> [25] 5.864478 6.280410 6.728110 7.009632 7.039903 6.863309 6.637170 6.409378
#> [33] 6.145832 5.888451 5.722091 5.697741 5.795643 5.949809 6.076040 6.246173
#> [41] 6.420178 6.555429 6.656790 6.636899 6.507007 6.369417 6.236814 6.106056
#> [49] 5.968965 5.814315
#> 
#> $Deseasonalized_Series
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1  0.25957851  4.52193187  0.02561422 -3.27549941 -1.99589546  4.13998028
#> 2 -2.04672860  1.60803141 -1.90842018  2.43786746 -0.86198753  0.60896968
#> 3  0.84458113 -0.26273932 -1.61693994  2.28282104  0.11769854  1.45475363
#> 4  0.88165649 -2.18341826  3.79622840 -1.10985701  3.11438950 -5.93789765
#> 5  0.20759402 -3.55601444                                                
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -2.21649517  0.10725422 -2.93539547  4.56402184  0.40703015  0.90443845
#> 2  0.99414490  3.01317040 -1.08255028 -3.72915116 -1.65024827 -0.41441793
#> 3  2.09395195 -2.13000316  0.97745102 -1.56435216 -2.01456178 -0.79842615
#> 4 -0.71419183 -0.98316224  2.89760126  0.55040795  3.04251466  0.04539699
#> 5                                                                        
#> 
#> $breakpoints
#> [1]  0 50
#> 
#> $trend
#>            Jan          Feb          Mar          Apr          May          Jun
#> 1  0.505499543  0.450383267  0.395266992  0.350320200  0.305373408  0.256020797
#> 2  0.320205313  0.351735081  0.383264849  0.266527974  0.149791100  0.035967895
#> 3 -0.155543116 -0.106065326 -0.056587536 -0.005831171  0.044925194  0.024138595
#> 4 -0.346100396 -0.360365501 -0.374630607 -0.228539627 -0.082448647 -0.022418368
#> 5 -0.167253552 -0.201046378                                                    
#>            Jul          Aug          Sep          Oct          Nov          Dec
#> 1  0.206668187  0.154062564  0.101456941  0.137626299  0.173795657  0.247000485
#> 2 -0.077855310 -0.122196911 -0.166538512 -0.181957021 -0.197375529 -0.176459323
#> 3  0.003351997 -0.025383946 -0.054119889 -0.086172752 -0.118225615 -0.232163006
#> 4  0.037611911 -0.002619487 -0.042850885 -0.077995582 -0.113140280 -0.140196916
#> 5                                                                              
#> 
#> $seasonality
#>          Jan        Feb        Mar        Apr        May        Jun        Jul
#> 1 -0.2910249  0.8952919 -1.1473155  0.5228147  0.2790736  0.5356098  1.1184320
#> 2 -0.2910249  0.8952919 -1.1473155  0.5228147  0.2790736  0.5356098  1.1184320
#> 3 -0.2910249  0.8952919 -1.1473155  0.5228147  0.2790736  0.5356098  1.1184320
#> 4 -0.2910249  0.8952919 -1.1473155  0.5228147  0.2790736  0.5356098  1.1184320
#> 5 -0.2910249  0.8952919                                                       
#>          Aug        Sep        Oct        Nov        Dec
#> 1 -1.3123081 -0.1425125  0.1819775 -2.2929562  1.6529165
#> 2 -1.3123081 -0.1425125  0.1819775 -2.2929562  1.6529165
#> 3 -1.3123081 -0.1425125  0.1819775 -2.2929562  1.6529165
#> 4 -1.3123081 -0.1425125  0.1819775 -2.2929562  1.6529165
#> 5                                                       
#> 
#> $remainder
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1 -0.24592103  4.07154861 -0.36965277 -3.62581961 -2.30126886  3.88395948
#> 2 -2.36693392  1.25629633 -2.29168503  2.17133948 -1.01177863  0.57300178
#> 3  1.00012425 -0.15667400 -1.56035240  2.28865221  0.07277334  1.43061503
#> 4  1.22775688 -1.82305276  4.17085901 -0.88131738  3.19683815 -5.91547928
#> 5  0.37484757 -3.35496806                                                
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -2.42316336 -0.04680834 -3.03685242  4.42639555  0.23323450  0.65743797
#> 2  1.07200021  3.13536731 -0.91601177 -3.54719414 -1.45287274 -0.23795861
#> 3  2.09059996 -2.10461921  1.03157091 -1.47817941 -1.89633616 -0.56626314
#> 4 -0.75180374 -0.98054275  2.94045214  0.62840353  3.15565494  0.18559391
#> 5                                                                        
#>