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]  2  3  4  5  6  7  8  9 11 12 14 15 16 17 18 19 21 22 24 25 26 27 28
#> 
#> $trend_line
#>   [1] 1137.9436 1136.9709 1135.8318 1134.5272 1133.0949 1131.5766 1129.9997
#>   [8] 1128.3720 1126.6193 1124.3596 1122.3628 1120.5238 1119.1214 1118.1976
#>  [15] 1117.9579 1118.7292 1120.9707 1124.5740 1128.7926 1132.5750 1134.4106
#>  [22] 1135.6300 1136.7808 1137.9552 1139.1380 1140.2664 1141.2516 1142.0037
#>  [29]  833.5024  833.5034  833.4934  833.4752  833.4514  833.4272  833.4065
#>  [36]  833.3932  833.3944  833.4166  833.4689  833.5577  833.6851  833.8489
#>  [43]  834.0452  834.2708  834.5215  834.7923  835.0776  835.3642  835.6231
#>  [50]  835.8033  835.8232  835.5759  835.2999  834.8540  834.2970  833.6987
#>  [57]  833.1498  832.7101  832.4310  832.3386  832.4194  832.6920  833.1493
#>  [64]  833.7915  834.6195  835.6680  836.9777  838.5399  840.3426  842.3489
#>  [71]  844.4798  846.6768  848.9136  851.1488  853.3382  855.4136  857.2771
#>  [78]  858.9158  859.7719  860.1453  860.2497  860.2100  860.1021  859.9751
#>  [85]  859.8599  859.7724  859.7192  859.7005  859.7147  859.7568  859.8183
#>  [92]  859.8904  859.9611  860.0171  860.0440  860.0260  859.9471  859.7946
#>  [99]  859.5564  859.2252
#> 
#> $Deseaonalized_Series
#>             Jan           Feb           Mar           Apr           May
#> 1  -13.79996020    9.15951109 -128.23318570   35.55827994  -13.79778120
#> 2   -4.97778524 -138.06719452  -53.35925221 -198.64365622   18.32644548
#> 3  125.00558964   65.86401628  -66.65301349  -81.91819624 -100.20522515
#> 4 -137.25075351  172.71384754  261.12975658   95.52785603  -43.38797374
#> 5  -67.47950409  -28.67283932  -23.22455729  -30.49032285  -12.00281222
#> 6  -47.27580212   18.43841179   56.44936508   70.29403756  108.67761975
#> 7  -32.76998023 -123.01839193   -7.73956747  144.67189779  -37.97994107
#> 8   62.28370569  112.35806718  -18.12052774   23.38503860   74.58241387
#> 9   63.19648478 -155.66416581 -100.95780574 -159.13963370              
#>             Jun           Jul           Aug           Sep           Oct
#> 1   69.84266810 -214.83755465   71.85955779  246.05259492  -35.20494609
#> 2 -284.15469222  -68.63050404  -22.34345550  -31.73866233   23.52462332
#> 3   47.91588413  142.66874858 -169.24364916  109.22052040  -51.27261762
#> 4  -66.42967882 -275.88310425  -40.03924468 -129.84961767  234.36233810
#> 5   68.56531407  -34.13484230  -18.46713350  -86.47784446  -87.55552757
#> 6  102.75128473   87.18447056  141.69159760  -66.67070337 -217.19432164
#> 7   56.50345206   90.39022461    0.08620437 -113.57776122 -162.05538893
#> 8   -3.33752286  262.34380886   16.34115827   43.71081931  259.13749416
#> 9                                                                      
#>             Nov           Dec
#> 1 -140.30056015 -192.48082986
#> 2    0.28149297  105.08782557
#> 3 -145.34420895   75.64974751
#> 4  251.98467953  -10.32121709
#> 5  194.63125342  -80.29562314
#> 6 -208.41758498   -7.63383431
#> 7  -35.03985770  183.06785230
#> 8   39.01823306 -120.98299385
#> 9                            
#> 
#> $breakpoints
#> [1]   0  28 100
#> 
#> $trend
#>            Jan          Feb          Mar          Apr          May          Jun
#> 1  -2.58068534  -5.22031428  -7.85994322 -11.66249675 -15.46505027 -20.24872233
#> 2 -71.37236741 -79.35121240 -87.33005740 -85.73692004 -84.14378268 -70.14213019
#> 3   5.29525755   8.12230681  10.94935607   6.20807710   1.46679812  -5.26470287
#> 4  12.12075784   6.20232976   0.28390168   4.58190374   8.87990580  12.03022044
#> 5   7.82859501   7.97857547   8.12855592   0.68594670  -6.75666253 -10.45680279
#> 6  22.18232637  29.05741313  35.93249990  31.65748635  27.38247280  17.42298235
#> 7 -31.34554077 -29.52398082 -27.70242087 -21.77575607 -15.84909127  -7.62981942
#> 8  27.23752034  38.44764094  49.65776153  60.15099926  70.64423699  68.79267994
#> 9 -36.47875612 -56.56470068 -76.65064523 -98.29738163                          
#>            Jul          Aug          Sep          Oct          Nov          Dec
#> 1 -25.03239439 -30.08582834 -35.13926228 -42.06844238 -48.99762247 -60.18499494
#> 2 -56.14047769 -42.49951508 -28.85855246 -19.32577573  -9.79299899  -2.24887072
#> 3 -11.99620386  -7.79186271  -3.58752156   5.97956019  15.54664193  13.83369988
#> 4  15.18053508   8.83694475   2.49335441  -1.07112296  -4.63560033   1.59649734
#> 5 -14.15694304 -10.93245758  -7.70797212  -1.93055623   3.84685967  13.01459302
#> 6   7.46349189  -1.43600089 -10.33549366 -17.81748480 -25.29947594 -28.32250835
#> 7   0.58945242   6.75330236  12.91715231  14.97607049  17.03498868  22.13625451
#> 8  66.94112288  50.59555288  34.24998288  17.07958925  -0.09080439 -18.28478025
#> 9                                                                              
#> 
#> $seasonality
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 2   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 3   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 4   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 5   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 6   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 7   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 8   -4.143600   13.869559  -44.598627   39.914473   40.702863  -41.419268
#> 9   -4.143600   13.869559  -44.598627   39.914473                        
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 2 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 3 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 4 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 5 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 6 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 7 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 8 -102.162131   29.768482   -2.671910   50.845392   12.937743    6.957018
#> 9                                                                        
#> 
#> $remainder
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1  -11.219275   14.379825 -120.373242   47.220777    1.667269   90.091390
#> 2   66.394582  -58.715982   33.970805 -112.906736  102.470228 -214.012562
#> 3  119.710332   57.741709  -77.602370  -88.126273 -101.672023   53.180587
#> 4 -149.371511  166.511518  260.845855   90.945952  -52.267880  -78.459899
#> 5  -75.308099  -36.651415  -31.353113  -31.176270   -5.246150   79.022117
#> 6  -69.458128  -10.619001   20.516865   38.636551   81.295147   85.328302
#> 7   -1.424439  -93.494411   19.962853  166.447654  -22.130850   64.133271
#> 8   35.046185   73.910426  -67.778289  -36.765961    3.938177  -72.130203
#> 9   99.675241  -99.099465  -24.307161  -60.842252                        
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -189.805160  101.945386  281.191857    6.863496  -91.302938 -132.295835
#> 2  -12.490026   20.156060   -2.880110   42.850399   10.074492  107.336696
#> 3  154.664952 -161.451786  112.808042  -57.252178 -160.890851   61.816048
#> 4 -291.063639  -48.876189 -132.342972  235.433461  256.620280  -11.917714
#> 5  -19.977899   -7.534676  -78.769872  -85.624971  190.784394  -93.310216
#> 6   79.720979  143.127598  -56.335210 -199.376837 -183.118109   20.688674
#> 7   89.800772   -6.667098 -126.494914 -177.031459  -52.074846  160.931598
#> 8  195.402686  -34.254395    9.460836  242.057905   39.109037 -102.698214
#> 9                                                                        
#> 

StructuralDecompose(Data = runif(n = 50, min = 1, max = 10))
#> $anomalies
#> logical(0)
#> 
#> $trend_line
#>  [1] 6.020025 6.042772 6.068238 6.095602 6.124039 6.152831 6.181502 6.209515
#>  [9] 6.236318 6.261528 6.284879 6.306509 6.327431 6.350061 6.378807 6.422013
#> [17] 6.491036 6.527982 6.550431 6.558599 6.551760 6.529302 6.491058 6.436083
#> [25] 6.366610 6.282241 6.188651 6.096041 6.010904 5.928755 5.843420 5.753372
#> [33] 5.658094 5.560504 5.454227 5.342421 5.230632 5.120413 5.011682 4.904233
#> [41] 4.797651 4.691733 4.586130 4.480210 4.373235 4.264860 4.155105 4.044051
#> [49] 3.931718 3.818036
#> 
#> $Deseaonalized_Series
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1  1.77022109  2.95589977 -2.25504572 -0.33215767 -2.71334375 -0.77287705
#> 2  1.36528568  1.74428575 -2.62050166  2.11115792  1.40459909 -0.96179499
#> 3 -4.14452875 -1.03469969  1.90900714  1.09685064 -2.30671226 -1.40781320
#> 4  1.85218699 -2.45142760  3.23104322 -2.63871447  3.82524047  3.26848120
#> 5 -0.80806218 -1.38216509                                                
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1 -1.51074240 -0.05535902  1.74581594 -1.90816094 -1.89424792 -2.11978913
#> 2 -0.14995544  4.64874295 -1.25743948  1.11858629  1.34603621  1.36237264
#> 3  0.19486266 -2.76868074  0.87845616  0.97788603 -1.03882715 -0.34184543
#> 4  1.50803693 -1.95017028 -1.65996155 -0.48604245  1.28471292  0.86817468
#> 5                                                                        
#> 
#> $breakpoints
#> [1]  0 50
#> 
#> $trend
#>             Jan           Feb           Mar           Apr           May
#> 1  0.2372935139  0.1096909174 -0.0179116791 -0.1256342916 -0.2333569041
#> 2 -0.1430985944 -0.0006027701  0.1418930542  0.2992155524  0.4565380505
#> 3 -0.0029696606 -0.1650908764 -0.3272120921 -0.3982411940 -0.4692702959
#> 4  0.3411666907  0.4276412201  0.5141157494  0.5039846619  0.4938535744
#> 5 -0.3924124170 -0.5384245354                                          
#>             Jun           Jul           Aug           Sep           Oct
#> 1 -0.3341114699 -0.4348660356 -0.5175683848 -0.6002707341 -0.5149276216
#> 2  0.5120647606  0.5675914706  0.5085938046  0.4495961385  0.3667127466
#> 3 -0.4485484647 -0.4278266335 -0.3657084907 -0.3035903480 -0.1930178770
#> 4  0.4200094343  0.3461652942  0.2434647205  0.1407641468  0.0133872306
#> 5                                                                      
#>             Nov           Dec
#> 1 -0.4295845091 -0.2863415518
#> 2  0.2838293547  0.1404298470
#> 3 -0.0824454060  0.1293606424
#> 4 -0.1139896857 -0.2532010514
#> 5                            
#> 
#> $seasonality
#>           Jan         Feb         Mar         Apr         May         Jun
#> 1  0.72432802  0.48955053  1.02260117 -0.23015883 -2.39325397  1.87603708
#> 2  0.72432802  0.48955053  1.02260117 -0.23015883 -2.39325397  1.87603708
#> 3  0.72432802  0.48955053  1.02260117 -0.23015883 -2.39325397  1.87603708
#> 4  0.72432802  0.48955053  1.02260117 -0.23015883 -2.39325397  1.87603708
#> 5  0.72432802  0.48955053                                                
#>           Jul         Aug         Sep         Oct         Nov         Dec
#> 1  1.68327571 -1.39878187 -1.27558910  0.45656301 -0.86723561 -0.08733736
#> 2  1.68327571 -1.39878187 -1.27558910  0.45656301 -0.86723561 -0.08733736
#> 3  1.68327571 -1.39878187 -1.27558910  0.45656301 -0.86723561 -0.08733736
#> 4  1.68327571 -1.39878187 -1.27558910  0.45656301 -0.86723561 -0.08733736
#> 5                                                                        
#> 
#> $remainder
#>          Jan        Feb        Mar        Apr        May        Jun        Jul
#> 1  1.5329276  2.8462089 -2.2371340 -0.2065234 -2.4799868 -0.4387656 -1.0758764
#> 2  1.5083843  1.7448885 -2.7623947  1.8119424  0.9480610 -1.4738597 -0.7175469
#> 3 -4.1415591 -0.8696088  2.2362192  1.4950918 -1.8374420 -0.9592647  0.6226893
#> 4  1.5110203 -2.8790688  2.7169275 -3.1426991  3.3313869  2.8484718  1.1618716
#> 5 -0.4156498 -0.8437406                                                       
#>          Aug        Sep        Oct        Nov        Dec
#> 1  0.4622094  2.3460867 -1.3932333 -1.4646634 -1.8334476
#> 2  4.1401491 -1.7070356  0.7518735  1.0622069  1.2219428
#> 3 -2.4029722  1.1820465  1.1709039 -0.9563817 -0.4712061
#> 4 -2.1936350 -1.8007257 -0.4994297  1.3987026  1.1213757
#> 5                                                       
#>