rjd3filters allows to reproduce the entire X-11 process

X-11 without outlier correction

library("rjd3filters")
library("rjd3x11plus")
b1 <- rjd3toolkit::ABS$X0.2.09.10.M
x11_step <- x11plus_trend(b1, trend.coefs = lp_filter(horizon = 6, ic = 3.5),
                             extreme.lsig = 300, extreme.usig = 400, mul = FALSE,
                             seas.s0 = "S3X3",
                             seas.s1 = "S3X5",
                             userdefined = sprintf("b%i", 1:11))
compare <- function(x, id, na.rm = TRUE) {
  if (na.rm)
    x <- na.omit(x)
  res <- cbind(x, x11_step$user_defined[[id]])
  all.equal(res[,1], res[,2], check.attributes = FALSE)
}
compare(b1, "b1")
#> [1] TRUE

e1 <- simple_ma(12, - 6)
e2 <- simple_ma(12, - 5)
# used to have the 1rst estimate of the trend
tc_1 <- M2X12 <- (e1 + e2)/2
coef(M2X12) |> round(3)
#>   t-6   t-5   t-4   t-3   t-2   t-1     t   t+1   t+2   t+3   t+4   t+5   t+6 
#> 0.042 0.083 0.083 0.083 0.083 0.083 0.083 0.083 0.083 0.083 0.083 0.083 0.042
M2X12 * b1 # b2
#>            Jan       Feb       Mar       Apr       May       Jun       Jul
#> 1982                                      NA        NA        NA        NA
#> 1983  494.8167  496.0250  497.5833  499.6750  502.9417  507.9500  512.5292
#> 1984  530.3292  535.3417  538.8958  543.5375  548.7792  554.2042  561.5917
#> 1985  596.9083  602.6792  607.6542  612.6875  619.1208  628.3708  636.8000
#> 1986  649.6417  652.1000  656.1583  661.4625  662.8083  670.4833  679.8083
#> 1987  704.5875  707.8458  709.1333  711.3792  714.9542  720.5583  725.1125
#> 1988  743.9333  744.4292  748.6083  751.5875  757.7375  767.6125  772.2125
#> 1989  782.8833  787.2375  791.7167  794.0792  797.2292  799.4333  801.3542
#> 1990  818.5417  819.8250  820.6083  821.3625  823.1375  823.1958  823.5917
#> 1991  822.9417  826.9083  827.3833  830.4000  833.9500  836.0500  839.5167
#> 1992  862.5208  860.3083  861.6208  866.7125  869.5375  872.6417  875.6708
#> 1993  886.5708  886.0875  887.3375  887.7250  887.1333  889.6750  891.4750
#> 1994  900.1583  903.5542  908.2375  911.9875  915.2417  920.9667  925.7042
#> 1995  938.0125  945.2125  947.0833  945.2417  947.4500  951.8958  956.9125
#> 1996  968.2500  970.0167  969.6792  969.2625  970.4000  970.1750  969.6833
#> 1997  967.9375  968.3625  970.5500  976.7417  979.7792  982.7458  987.6583
#> 1998  999.6000 1003.9792 1005.4042 1007.2667 1010.2167 1015.3417 1020.3958
#> 1999 1036.2333 1037.9750 1041.8292 1045.3833 1049.2125 1056.0208 1059.2208
#> 2000 1087.2250 1083.6625 1090.4125 1093.7042 1095.8708 1101.4208 1107.8750
#> 2001 1126.3208 1134.4583 1130.7958 1131.6250 1138.8708 1147.3833 1153.5500
#> 2002 1177.7375 1180.9792 1187.2333 1192.5083 1202.0792 1211.2208 1217.0750
#> 2003 1257.4875 1263.3875 1270.6125 1280.7292 1286.4708 1291.4167 1298.4667
#> 2004 1338.1208 1346.0167 1353.7375 1360.4833 1362.5958 1366.1417 1371.9750
#> 2005 1386.2500 1387.4208 1387.5792 1384.0792 1382.4042 1384.0250 1383.3000
#> 2006 1392.6208 1398.8875 1397.6292 1396.4417 1401.1542 1407.7375 1413.9333
#> 2007 1439.9625 1445.2375 1454.0083 1463.6000 1470.2917 1478.6458 1489.7458
#> 2008 1514.6583 1517.6958 1516.9833 1518.7250 1518.7167 1524.0125 1532.0250
#> 2009 1555.5083 1558.0708 1561.8083 1565.9125 1571.8542 1570.5917 1567.5542
#> 2010 1559.3708 1559.0708 1559.2625 1557.2917 1553.1042 1550.0292 1545.8958
#> 2011 1535.8875 1532.5958 1528.1458 1522.4583 1518.0542 1515.2458 1512.2417
#> 2012 1518.3458 1516.5292 1520.1792 1522.6792 1524.7958 1526.2833 1528.6917
#> 2013 1519.1083 1516.8333 1515.5750 1516.0875 1516.7833 1515.4583 1516.5333
#> 2014 1510.4833 1511.6500 1508.0667 1508.5833 1510.0083 1512.1000 1514.2500
#> 2015 1524.9292 1529.8042 1534.8625 1540.3333 1545.7667 1554.0792 1562.6083
#> 2016 1589.1917 1584.5833 1582.7250 1579.5792 1574.7833 1570.2250 1563.8125
#> 2017 1549.9833 1549.4167        NA        NA        NA        NA        NA
#>            Aug       Sep       Oct       Nov       Dec
#> 1982        NA        NA  490.4125  492.5500  493.6583
#> 1983  515.5292  517.5750  517.4292  520.3958  525.6167
#> 1984  567.4083  570.7042  576.6000  585.0500  591.8750
#> 1985  640.1292  642.1000  643.2750  645.6875  647.4750
#> 1986  683.0750  686.7208  692.2333  693.9917  697.3042
#> 1987  727.4042  732.2417  737.2333  740.0833  743.3458
#> 1988  772.2708  774.0125  774.9625  775.2083  778.8875
#> 1989  804.7250  806.4750  808.7375  812.7875  816.8208
#> 1990  825.0208  825.4750  825.3292  826.0292  822.9958
#> 1991  843.9833  845.7958  848.5250  854.0917  859.4875
#> 1992  875.6375  876.8750  879.4542  881.0083  884.7208
#> 1993  891.6833  895.3833  897.8167  897.5000  898.6208
#> 1994  926.7375  927.0625  929.7292  933.6250  934.1833
#> 1995  962.5500  964.8583  964.4417  965.4750  967.0333
#> 1996  969.6042  971.1125  971.1000  970.5083  968.5750
#> 1997  990.3750  988.4500  992.0375  996.0583  995.8333
#> 1998 1022.3500 1026.6208 1029.2625 1030.2667 1033.8500
#> 1999 1061.0000 1063.4375 1066.3625 1071.0542 1084.0625
#> 2000 1110.5167 1116.0167 1121.4375 1125.0083 1122.1167
#> 2001 1157.0000 1159.2167 1161.8208 1166.1333 1173.8625
#> 2002 1222.5125 1227.0083 1235.1708 1243.2250 1249.1042
#> 2003 1305.6708 1311.0042 1314.8958 1318.9750 1326.8667
#> 2004 1376.5958 1385.6333 1387.5500 1381.7375 1383.9875
#> 2005 1381.1250 1377.1292 1381.2375 1389.5000 1388.5917
#> 2006 1417.3875 1423.0708 1426.4500 1428.5958 1435.2625
#> 2007 1499.0792 1503.8125 1508.5667 1514.8167 1513.4042
#> 2008 1530.7458 1528.7167 1534.8708 1543.6542 1551.8708
#> 2009 1570.6125 1572.6250 1567.3583 1558.5417 1556.8208
#> 2010 1543.7750 1541.5792 1542.6042 1545.2958 1541.2208
#> 2011 1510.7417 1512.4833 1510.2417 1508.8500 1516.8708
#> 2012 1529.3958 1530.6458 1530.4792 1527.6833 1523.7667
#> 2013 1516.7375 1510.3708 1510.3583 1513.4292 1509.0167
#> 2014 1514.6292 1517.2500 1520.3042 1520.9792 1522.4875
#> 2015 1568.8583 1576.6208 1580.5000 1581.7417 1587.4167
#> 2016 1557.3917 1551.3667 1550.9667 1554.0625 1552.5542
#> 2017        NA
compare(M2X12 * b1 , "b2")
#> [1] TRUE
si_1 <- 1 - tc_1
si_1 * b1 # b3
#>               Jan          Feb          Mar          Apr          May
#> 1982                                                  NA           NA
#> 1983 -115.6166667 -118.0250000  -25.4833333    3.7250000    7.6583333
#> 1984 -115.6291667 -120.8416667  -54.1958333  -56.2375000   49.1208333
#> 1985  -80.6083333 -150.1791667  -81.8541667  -24.9875000   81.1791667
#> 1986  -79.1416667 -173.9000000 -108.7583333  -67.1625000   88.7916667
#> 1987  -90.6875000 -194.6458333 -109.2333333  -37.2791667   -0.9541667
#> 1988 -112.9333333 -193.3291667  -70.5083333  -35.8875000  -16.9375000
#> 1989 -151.3833333 -235.2375000  -72.7166667  -96.4791667  -32.4291667
#> 1990 -140.3416667 -233.6250000  -93.8083333  -77.2625000   -7.6375000
#> 1991 -128.9416667 -222.2083333 -108.1833333  -82.2000000   -5.7500000
#> 1992 -122.5208333 -194.4083333 -160.1208333  -35.3125000    9.0625000
#> 1993 -124.4708333 -243.0875000 -133.2375000  -47.0250000   19.4666667
#> 1994 -154.4583333 -239.1541667  -86.7375000  -80.2875000   -7.2416667
#> 1995 -185.6125000 -262.7125000 -135.8833333  -39.2416667  -20.2500000
#> 1996 -135.1500000 -232.9166667 -157.6791667  -74.0625000   -7.6000000
#> 1997 -127.0375000 -240.9625000 -112.6500000 -127.7416667   15.0208333
#> 1998  -82.3000000 -287.7791667 -182.5041667  -37.1666667  -40.0166667
#> 1999  -94.2333333 -299.5750000 -138.6291667  -92.1833333  -38.0125000
#> 2000 -162.3250000 -285.4625000 -188.5125000  -69.0041667  -43.5708333
#> 2001 -154.4208333 -319.8583333 -113.2958333  -92.4250000  -15.3708333
#> 2002 -149.8375000 -339.5791667 -143.3333333 -117.2083333  -11.1791667
#> 2003 -158.1875000 -362.8875000 -177.9125000  -58.3291667  -49.3708333
#> 2004 -155.2208333 -356.2166667 -222.3375000  -83.3833333  -82.2958333
#> 2005 -139.9500000 -350.1208333  -86.7791667 -230.3791667 -118.2041667
#> 2006 -198.9208333 -361.1875000 -193.1291667  -47.8416667 -133.5541667
#> 2007 -172.6625000 -398.2375000 -122.4083333 -161.0000000 -105.1916667
#> 2008 -116.8583333 -377.1958333 -165.2833333 -122.1250000  -97.6166667
#> 2009 -104.5083333 -501.4708333 -174.9083333  -56.8125000  -52.4541667
#> 2010  -90.2708333 -447.1708333 -179.3625000 -167.5916667 -125.9041667
#> 2011 -123.2875000 -415.0958333 -206.5458333  -49.8583333 -109.1541667
#> 2012 -155.9458333 -384.8291667 -170.9791667 -131.4791667  -67.8958333
#> 2013 -121.7083333 -403.2333333 -118.2750000 -176.9875000  -74.8833333
#> 2014  -59.4833333 -446.7500000 -214.8666667  -65.6833333  -98.2083333
#> 2015  -53.7291667 -476.0041667 -167.6625000  -98.1333333 -117.0666667
#> 2016  -69.9916667 -428.7833333 -131.2250000 -128.5791667 -125.0833333
#> 2017 -121.4833333 -457.0166667           NA           NA           NA
#>               Jun          Jul          Aug          Sep          Oct
#> 1982           NA           NA           NA           NA  -37.7125000
#> 1983  -45.5500000  -44.2291667  -57.3291667  -34.8750000  -32.1291667
#> 1984  -53.8041667  -18.1916667  -64.0083333  -47.9041667  -20.0000000
#> 1985  -66.5708333  -34.0000000  -57.6291667  -79.0000000   -6.1750000
#> 1986 -117.0833333  -16.6083333 -101.9750000  -24.8208333  -26.6333333
#> 1987  -50.0583333   -4.2125000 -125.8041667  -59.9416667  -28.1333333
#> 1988  -45.6125000  -88.7125000 -121.3708333  -50.7125000  -45.3625000
#> 1989  -13.1333333  -86.2541667  -80.9250000  -48.5750000  -57.0375000
#> 1990    9.2041667 -113.2916667  -65.6208333  -84.3750000  -38.7291667
#> 1991  -89.1500000  -45.0166667  -73.5833333 -104.2958333   10.0750000
#> 1992  -46.6416667  -87.4708333 -152.0375000  -57.0750000   23.0458333
#> 1993   -2.5750000 -119.9750000 -162.9833333  -50.6833333  -10.9166667
#> 1994   -8.3666667 -142.8041667 -127.9375000  -40.0625000    4.8708333
#> 1995  -45.0958333  -76.3125000  -88.6500000 -108.0583333  -43.8416667
#> 1996  -61.5750000  -61.6833333  -80.7041667 -137.4125000  -37.4000000
#> 1997 -152.5458333  -16.5583333 -154.3750000  -49.3500000  -15.1375000
#> 1998 -165.9416667   21.9041667 -152.4500000  -87.2208333   -7.9625000
#> 1999 -161.6208333   -4.7208333 -161.5000000  -61.1375000  -22.6625000
#> 2000   64.0791667 -248.5750000 -101.3166667  -61.4166667  -51.0375000
#> 2001 -122.4833333  -52.7500000 -194.0000000 -146.3166667  -29.8208333
#> 2002  -68.2208333 -141.3750000 -156.6125000 -166.9083333  -23.7708333
#> 2003  -53.5166667 -116.4666667 -204.4708333 -112.8041667    1.2041667
#> 2004   17.9583333  -66.0750000 -209.7958333  -67.7333333  -29.2500000
#> 2005   70.1750000  -93.2000000 -170.4250000  -99.3291667  -66.8375000
#> 2006   21.2625000   -1.9333333 -178.1875000 -203.9708333  -81.8500000
#> 2007   12.8541667  -27.4458333 -183.5791667 -150.5125000  -67.9666667
#> 2008 -122.4125000   50.2750000 -262.3458333 -145.4166667  -82.4708333
#> 2009  -70.0916667    3.1458333 -229.1125000 -172.7250000  -33.0583333
#> 2010    1.3708333   35.1041667 -219.7750000 -119.5791667  -77.7041667
#> 2011  -43.3458333   20.2583333 -217.2416667 -166.7833333 -105.5416667
#> 2012   90.1166667 -105.2916667 -170.3958333 -162.8458333  -87.8791667
#> 2013   21.9416667 -125.9333333 -179.5375000 -150.9708333  -47.0583333
#> 2014  -50.5000000  -12.6500000 -260.4291667 -160.8500000  -41.6041667
#> 2015  -73.1791667  -21.7083333 -236.9583333 -176.5208333  -14.2000000
#> 2016   25.8750000  -95.5125000 -263.4916667 -157.8666667  -53.5666667
#> 2017           NA           NA           NA                          
#>               Nov          Dec
#> 1982   30.3500000  395.6416667
#> 1983   48.3041667  438.0833333
#> 1984   38.1500000  447.5250000
#> 1985   51.4125000  540.0250000
#> 1986    6.9083333  670.5958333
#> 1987    3.1166667  716.7541667
#> 1988   95.0916667  791.1125000
#> 1989  111.0125000  752.5791667
#> 1990  105.4708333  740.1041667
#> 1991   90.6083333  740.8125000
#> 1992   87.5916667  766.1791667
#> 1993   72.5000000  811.8791667
#> 1994   66.7750000  883.3166667
#> 1995  101.9250000  890.1666667
#> 1996  111.0916667  869.0250000
#> 1997  115.2416667  883.2666667
#> 1998  107.4333333  941.8500000
#> 1999  136.1458333  985.5375000
#> 2000  107.4916667 1055.3833333
#> 2001  178.6666667 1095.6375000
#> 2002  251.8750000 1089.4958333
#> 2003  209.2250000 1097.3333333
#> 2004  154.9625000 1116.8125000
#> 2005  150.9000000 1147.4083333
#> 2006  194.7041667 1175.8375000
#> 2007  173.0833333 1233.5958333
#> 2008  132.2458333 1334.2291667
#> 2009  178.0583333 1238.2791667
#> 2010  160.2041667 1211.1791667
#> 2011  151.1500000 1213.6291667
#> 2012  145.2166667 1229.5333333
#> 2013  155.4708333 1216.4833333
#> 2014  166.7208333 1234.4125000
#> 2015  148.7583333 1326.1833333
#> 2016  130.2375000 1297.8458333
#> 2017
compare(si_1 * b1 , "b3")
#> [1] TRUE

M3X3 <- macurves("S3x3")
M3X3_s <- to_seasonal(M3X3, 12)
s_1 <- M3X3_s * si_1
s_1_norm <- M2X12 * s_1
s_1_norm <- impute_last_obs(s_1_norm, n = 6, nperiod = 1)
s_1_demean <- s_1 - s_1_norm
s_1_f <- impute_last_obs(s_1_demean, n = 6, nperiod = 12)
s_1_f * b1 # b5
#>              Jan         Feb         Mar         Apr         May         Jun
#> 1982                                      -23.443152   40.457639  -51.370306
#> 1983 -106.560590 -122.548862  -45.041917  -23.443152   40.457639  -51.370306
#> 1984 -100.417618 -131.460095  -57.565471  -31.532112   53.242445  -61.594991
#> 1985  -91.950714 -148.875829  -76.433365  -37.456250   60.597762  -71.377508
#> 1986  -89.219039 -168.030633  -90.434896  -44.251003   53.555826  -76.770467
#> 1987  -98.483353 -188.111748  -91.703453  -46.708873   23.017863  -63.055517
#> 1988 -115.586593 -204.015085  -85.194213  -56.021123   -3.121354  -43.115606
#> 1989 -130.666377 -219.099209  -84.528144  -69.792342  -17.230363  -29.340586
#> 1990 -135.009722 -222.247029  -96.500463  -72.955131  -12.411497  -30.701312
#> 1991 -132.037674 -221.934934 -114.283179  -67.895872   -3.048920  -39.670679
#> 1992 -130.621701 -219.923939 -125.656790  -57.455941    4.848843  -36.087982
#> 1993 -138.252874 -230.676755 -125.617091  -54.098399    5.165258  -28.207407
#> 1994 -148.660590 -239.527141 -124.039333  -57.300193   -1.318326  -25.932350
#> 1995 -152.968808 -246.511979 -127.054707  -65.718229   -5.079861  -47.981597
#> 1996 -139.313831 -247.866590 -137.071971  -73.815066   -8.295409  -84.094232
#> 1997 -119.851157 -257.107600 -141.862654  -80.664198  -11.319001 -124.791570
#> 1998 -108.633623 -271.840220 -153.306925  -75.785918  -22.936053 -125.333854
#> 1999 -116.871412 -287.908005 -151.815066  -76.660860  -29.372049 -107.613966
#> 2000 -136.012731 -301.390837 -153.160108  -78.221682  -29.675598  -68.212982
#> 2001 -149.057176 -318.277932 -144.185012  -85.551775  -25.110899  -66.487712
#> 2002 -154.576678 -335.480691 -156.517554  -87.754726  -31.487423  -53.795486
#> 2003 -153.380401 -350.336863 -162.929977 -100.505073  -52.628684  -35.832350
#> 2004 -157.686535 -356.666898 -172.175559 -111.822068  -81.057948    4.079591
#> 2005 -162.826408 -362.527913 -156.136343 -130.583546 -103.587191   27.822415
#> 2006 -165.870351 -369.241725 -153.784066 -123.952411 -111.643808   14.741127
#> 2007 -154.324961 -391.214564 -148.296740 -121.639892 -103.584626  -17.986323
#> 2008 -132.788484 -415.742940 -162.056597 -112.734896  -95.972126  -51.408083
#> 2009 -114.862944 -441.814313 -172.530035 -108.099460  -92.348823  -54.604398
#> 2010 -112.467496 -438.813889 -183.726717 -109.240220  -97.234915  -28.476678
#> 2011 -122.041898 -424.153318 -180.123129 -109.485050  -93.722473    1.070177
#> 2012 -123.208063 -408.453356 -172.166262 -119.455536  -87.812288   20.463465
#> 2013 -106.881501 -416.155228 -164.181867 -117.285706  -85.886825    3.657542
#> 2014  -83.100405 -433.365181 -166.438600 -110.163465  -95.648129  -15.037828
#> 2015  -72.797518 -447.629231 -163.001080 -104.630022 -107.973900  -30.333963
#> 2016  -77.856713 -449.882774 -160.691371 -103.602392 -115.707748  -27.906584
#> 2017  -87.078292 -448.150514 -160.691371 -103.602392 -115.707748  -27.906584
#>              Jul         Aug         Sep         Oct         Nov         Dec
#> 1982  -31.331771  -59.633989  -47.013818  -29.579572   41.687249  425.118885
#> 1983  -31.331771  -59.633989  -47.013818  -25.368171   43.328041  442.665246
#> 1984  -30.686490  -66.360333  -50.077006  -21.375437   39.898322  485.945075
#> 1985  -28.164159  -79.492689  -54.691319  -19.900135   32.682215  557.140490
#> 1986  -29.801505  -98.053742  -51.947531  -25.471103   28.863947  640.733198
#> 1987  -41.603569 -109.017052  -52.622357  -34.001582   41.569348  707.375135
#> 1988  -67.001794 -106.675868  -54.274923  -41.961863   69.969753  747.377353
#> 1989  -80.600000  -91.876254  -65.020313  -39.642612   91.954302  752.918133
#> 1990  -87.371566  -87.592458  -74.327546  -25.527469   99.979591  751.360340
#> 1991  -82.674344 -100.293499  -77.102450   -7.496566   92.933893  754.458893
#> 1992  -95.245583 -124.949518  -67.075174    3.789294   84.524846  780.449151
#> 1993 -105.960089 -135.078299  -62.334144   -1.409549   80.042882  818.740760
#> 1994 -109.603125 -125.742052  -71.158912  -12.574942   83.181250  855.537963
#> 1995  -87.615104 -113.220891  -88.090895  -25.471026   94.076601  875.810378
#> 1996  -56.211960 -114.002315  -96.186960  -26.635648  104.350540  888.091223
#> 1997  -25.060957 -132.636497  -85.630208  -22.696682  113.552296  905.898765
#> 1998  -33.651543 -142.015760  -75.892882  -21.044522  116.163812  942.821779
#> 1999  -61.484819 -149.478819  -75.102701  -25.460552  126.132311  990.949576
#> 2000 -110.742496 -147.686497  -95.039255  -32.456366  145.567843 1039.538021
#> 2001 -119.685069 -163.674633 -118.675405  -28.283951  178.691049 1073.858391
#> 2002 -121.583951 -176.701080 -128.178800  -23.187404  200.599190 1093.214043
#> 2003 -102.564718 -191.142747 -117.585320  -21.921219  198.596721 1106.681983
#> 2004  -85.437558 -190.879919 -111.783642  -36.746451  182.452180 1123.984279
#> 2005  -62.946644 -186.445814 -122.764853  -54.624267  170.454282 1151.880691
#> 2006  -30.633738 -191.441069 -147.325637  -70.068750  167.929128 1193.488638
#> 2007  -10.834664 -205.829128 -158.843345  -70.959799  165.407948 1233.567438
#> 2008   12.805710 -225.351505 -156.806539  -68.114448  160.613079 1258.221971
#> 2009   18.528241 -228.990895 -152.365992  -66.062384  160.460224 1249.578742
#> 2010   11.768538 -219.705883 -149.410667  -75.537789  157.422647 1232.177797
#> 2011  -21.286709 -203.831867 -154.488908  -80.845891  155.593287 1218.935648
#> 2012  -56.149151 -198.649113 -156.268519  -76.973650  152.258661 1221.626640
#> 2013  -69.437249 -207.461593 -161.041069  -58.627064  153.708102 1235.661535
#> 2014  -60.389815 -228.464082 -162.486722  -44.045306  153.237301 1257.964519
#> 2015  -50.245499 -243.472029 -164.790940  -35.388895  149.358410 1283.056154
#> 2016  -49.581391 -251.234774 -165.139095  -34.433230  145.419084 1298.523714
#> 2017  -49.581391 -251.234774
compare(s_1_f * b1 , "b5")
#> [1] TRUE
sa_1 <- 1- s_1_f
sa_1 * b1 # b6
#>            Jan       Feb       Mar       Apr       May       Jun       Jul
#> 1982                                483.5432  462.1424  495.1703  490.4318
#> 1983  485.7606  500.5489  517.1419  526.8432  470.1424  513.7703  499.6318
#> 1984  515.1176  545.9601  542.2655  518.8321  544.6576  561.9950  574.0865
#> 1985  608.2507  601.3758  602.2334  625.1562  639.7022  633.1775  630.9642
#> 1986  659.7190  646.2306  637.8349  638.5510  698.0442  630.1705  693.0015
#> 1987  712.3834  701.3117  691.6035  720.8089  690.9821  733.5555  762.5036
#> 1988  746.5866  755.1151  763.2942  771.7211  743.9214  765.1156  750.5018
#> 1989  762.1664  771.0992  803.5281  767.3923  782.0304  815.6406  795.7000
#> 1990  813.2097  808.4470  823.3005  817.0551  827.9115  863.1013  797.6716
#> 1991  826.0377  826.6349  833.4832  816.0959  831.2489  786.5707  877.1743
#> 1992  870.6217  885.8239  827.1568  888.8559  873.7512  862.0880  883.4456
#> 1993  900.3529  873.6768  879.7171  894.7984  901.4347  915.3074  877.4601
#> 1994  894.3606  903.9271  945.5393  889.0002  909.3183  938.5323  892.5031
#> 1995  905.3688  929.0120  938.2547  971.7182  932.2799  954.7816  968.2151
#> 1996  972.4138  984.9666  949.0720  969.0151  971.0954  992.6942  964.2120
#> 1997  960.7512  984.5076  999.7627  929.6642 1006.1190  954.9916  996.1610
#> 1998 1025.9336  988.0402  976.2069 1045.8859  993.1361  974.7339 1075.9515
#> 1999 1058.8714 1026.3080 1055.0151 1029.8609 1040.5720 1002.0140 1115.9848
#> 2000 1060.9127 1099.5908 1055.0601 1102.9217 1081.9756 1233.7130  970.0425
#> 2001 1120.9572 1132.8779 1161.6850 1124.7518 1148.6109 1091.3877 1220.4851
#> 2002 1182.4767 1176.8807 1200.4176 1163.0547 1222.3874 1196.7955 1197.2840
#> 2003 1252.6804 1250.8369 1255.6300 1322.9051 1289.7287 1273.7323 1284.5647
#> 2004 1340.5865 1346.4669 1303.5756 1388.9221 1361.3579 1380.0204 1391.3376
#> 2005 1409.1264 1399.8279 1456.9363 1284.2835 1367.7872 1426.3776 1353.0466
#> 2006 1359.5704 1406.9417 1358.2841 1472.5524 1379.2438 1414.2589 1442.6337
#> 2007 1421.6250 1438.2146 1479.8967 1424.2399 1468.6846 1509.4863 1473.1347
#> 2008 1530.5885 1556.2429 1513.7566 1509.3349 1517.0721 1453.0081 1569.4943
#> 2009 1565.8629 1498.4143 1559.4300 1617.1995 1611.7488 1555.1044 1552.1718
#> 2010 1581.5675 1550.7139 1563.6267 1498.9402 1524.4349 1579.8767 1569.2315
#> 2011 1534.6419 1541.6533 1501.7231 1582.0851 1502.6225 1470.8298 1553.7867
#> 2012 1485.6081 1540.1534 1521.3663 1510.6555 1544.7123 1595.9365 1479.5492
#> 2013 1504.2815 1529.7552 1561.4819 1456.3857 1527.7868 1533.7425 1460.0372
#> 2014 1534.1004 1498.2652 1459.6386 1553.0635 1507.4481 1476.6378 1561.9898
#> 2015 1543.9975 1501.4292 1530.2011 1546.8300 1536.6739 1511.2340 1591.1455
#> 2016 1597.0567 1605.6828 1612.1914 1554.6024 1565.4077 1624.0066 1517.8814
#> 2017 1515.5783 1540.5505 1530.9914 1626.2024 1568.1077 1585.1066 1495.0814
#>            Aug       Sep       Oct       Nov       Dec
#> 1982  498.0340  512.1138  482.2796  481.2128  464.1811
#> 1983  517.8340  529.7138  510.6682  525.3720  521.0348
#> 1984  569.7603  572.8770  577.9754  583.3017  553.4549
#> 1985  661.9927  617.7913  657.0001  664.4178  630.3595
#> 1986  679.1537  713.8475  691.0711  672.0361  727.1668
#> 1987  710.6171  724.9224  743.1016  701.6307  752.7249
#> 1988  757.5759  777.5749  771.5619  800.3302  822.6226
#> 1989  815.6763  822.9203  791.3426  831.8457  816.4819
#> 1990  846.9925  815.4275  812.1275  831.5204  811.7397
#> 1991  870.6935  818.6024  866.0966  851.7661  845.8411
#> 1992  848.5495  886.8752  898.7107  884.0752  870.4508
#> 1993  863.7783  907.0341  888.3095  889.9571  891.7592
#> 1994  924.5421  958.1589  947.1749  917.2187  961.9620
#> 1995  987.1209  944.8909  946.0710  973.3234  981.3896
#> 1996 1002.9023  929.8870  960.3356  977.2495  949.5088
#> 1997  968.6365 1024.7302  999.5967  997.7477  973.2012
#> 1998 1011.9158 1015.2929 1042.3445 1021.5362 1032.8782
#> 1999 1048.9788 1077.4027 1069.1606 1081.0677 1078.6504
#> 2000 1156.8865 1149.6393 1102.8564 1086.9322 1137.9620
#> 2001 1126.6746 1131.5754 1160.2840 1166.1090 1195.6416
#> 2002 1242.6011 1188.2788 1234.5874 1294.5008 1245.3860
#> 2003 1292.3427 1315.7853 1338.0212 1329.6033 1317.5180
#> 2004 1357.6799 1429.6836 1395.0465 1354.2478 1376.8157
#> 2005 1397.1458 1400.5649 1369.0243 1369.9457 1384.1193
#> 2006 1430.6411 1366.4256 1414.6687 1455.3709 1417.6114
#> 2007 1521.3291 1512.1433 1511.5598 1522.4921 1513.4326
#> 2008 1493.7515 1540.1065 1520.5144 1515.2869 1627.8780
#> 2009 1570.4909 1552.2660 1600.3624 1576.1398 1545.5213
#> 2010 1543.7059 1571.4107 1540.4378 1548.0774 1520.2222
#> 2011 1497.3319 1500.1889 1485.5459 1504.4067 1511.5644
#> 2012 1557.6491 1524.0685 1519.5736 1520.6413 1531.6734
#> 2013 1544.6616 1520.4411 1521.9271 1515.1919 1489.8385
#> 2014 1482.6641 1518.8867 1522.7453 1534.4627 1498.9355
#> 2015 1575.3720 1564.8909 1601.6889 1581.1416 1630.5438
#> 2016 1545.1348 1558.6391 1531.8332 1538.8809 1551.8763
#> 2017 1554.3348
compare(sa_1 * b1 , "b6")
#> [1] TRUE

h13 <- lp_filter(horizon = 6, ic = 3.5)
tc_2 <- h13 * sa_1
tc_2 * b1 # b7
#>            Jan       Feb       Mar       Apr       May       Jun       Jul
#> 1982                                478.2765  482.8008  487.6970  492.0921
#> 1983  489.2404  495.6111  501.2316  504.7038  505.7864  506.4552  508.5027
#> 1984  526.2366  529.2061  534.0533  540.4488  547.9069  556.7454  564.5273
#> 1985  590.1932  600.2107  611.4806  621.9800  629.8612  635.5527  639.4848
#> 1986  647.1107  646.9835  648.1251  651.8062  659.7331  668.7500  677.3090
#> 1987  703.0687  703.8874  706.4011  710.7287  716.7933  723.2959  728.3548
#> 1988  747.0877  754.6823  758.6458  759.8470  758.5857  756.6617  758.6509
#> 1989  787.9300  784.3449  782.2924  784.4335  790.0580  797.6288  804.5296
#> 1990  815.1236  816.9223  820.5208  824.9422  828.5787  830.8131  830.0138
#> 1991  823.5193  822.5066  822.5614  823.5336  826.9730  832.9334  839.6391
#> 1992  860.1441  864.4782  867.0668  867.7926  868.4994  869.7528  872.0361
#> 1993  884.1122  886.0296  888.8678  892.1340  893.7556  893.1806  891.3135
#> 1994  901.9831  906.8510  910.3225  912.4865  914.3848  917.0651  922.2012
#> 1995  933.3637  933.5731  938.2310  945.9664  953.3952  958.5753  961.2950
#> 1996  971.0399  971.3401  971.7342  972.5164  973.8616  975.0545  974.3662
#> 1997  967.7838  971.5350  973.2678  973.3591  974.9790  978.9540  984.0581
#> 1998  997.2415  997.3743  999.8649 1004.4566 1009.6485 1015.2631 1020.1678
#> 1999 1038.7254 1039.2019 1037.8463 1038.3668 1041.8716 1048.2719 1057.3997
#> 2000 1074.6140 1080.8931 1087.4445 1095.4638 1104.0200 1110.6335 1113.9968
#> 2001 1128.0249 1130.8177 1136.9392 1140.6839 1142.1090 1142.8506 1144.5974
#> 2002 1181.7393 1186.5206 1188.9181 1192.1846 1195.6908 1200.6014 1207.9087
#> 2003 1260.8824 1267.6421 1273.8295 1278.8051 1284.2755 1289.7706 1294.8380
#> 2004 1333.1753 1338.3093 1345.8059 1355.5295 1366.9878 1377.8001 1385.3081
#> 2005 1392.4503 1389.8997 1385.2683 1380.8591 1377.3673 1376.9966 1380.5528
#> 2006 1380.2916 1387.3415 1398.5500 1409.3835 1415.7647 1417.9376 1417.2443
#> 2007 1433.4930 1441.1823 1448.8879 1458.5260 1471.1088 1484.1563 1495.3979
#> 2008 1528.8771 1526.3858 1521.0243 1514.4016 1509.8919 1507.2434 1508.6551
#> 2009 1559.1936 1567.0935 1572.8798 1576.2199 1576.5864 1576.0230 1573.7841
#> 2010 1560.7677 1550.8381 1543.3420 1540.9041 1543.7216 1549.4946 1555.5850
#> 2011 1534.1555 1531.9071 1529.4026 1526.4197 1521.5278 1515.2128 1509.0566
#> 2012 1507.9353 1517.1258 1525.8547 1533.6003 1538.7680 1540.2603 1538.3190
#> 2013 1523.3436 1521.1137 1518.1472 1513.7359 1510.4123 1510.0511 1511.6092
#> 2014 1505.8189 1503.2206 1504.3506 1506.4647 1508.7807 1511.4399 1513.5703
#> 2015 1521.9322 1523.4604 1525.7922 1531.1163 1539.1194 1548.3359 1558.7293
#> 2016 1604.9908 1602.4616 1595.4172 1586.0690 1576.1816 1566.1880 1557.9160
#> 2017 1540.3165 1549.5424 1559.8416 1566.1639 1566.6342 1562.0955 1555.1216
#>            Aug       Sep       Oct       Nov       Dec
#> 1982  494.1801  492.3454  487.5649  484.3054  484.6338
#> 1983  512.0796  516.0279  519.8319  522.4752  524.0864
#> 1984  570.2071  573.7676  575.4125  577.2838  582.0523
#> 1985  642.7917  645.2273  647.4582  648.0337  647.9295
#> 1986  685.3008  692.0373  697.1898  701.3603  703.5648
#> 1987  729.9434  729.4201  729.2137  732.1640  738.3674
#> 1988  764.9226  773.6153  782.4425  788.5955  789.9578
#> 1989  809.6214  813.3235  815.1347  815.1223  814.4282
#> 1990  827.0127  823.2620  820.8291  820.2630  822.3032
#> 1991  845.6198  850.8945  854.1429  855.6841  857.4731
#> 1992  875.5525  879.1870  882.0800  884.2732  884.1707
#> 1993  889.1061  886.6276  887.1560  891.0795  896.2862
#> 1994  929.0619  935.2239  937.5880  936.5172  934.7606
#> 1995  961.6451  963.0434  965.4486  968.0275  969.5027
#> 1996  970.7972  965.1632  961.4199  960.8795  963.6944
#> 1997  990.3254  996.2855  998.5630  998.2472  998.5402
#> 1998 1024.6400 1027.5494 1030.6820 1033.9446 1037.0511
#> 1999 1065.9959 1072.4856 1075.7269 1075.9588 1072.7769
#> 2000 1114.5689 1113.5674 1113.6102 1116.8862 1123.2065
#> 2001 1147.9822 1153.4453 1160.8738 1168.0531 1175.1897
#> 2002 1217.3961 1228.5466 1238.4462 1246.4771 1254.1158
#> 2003 1301.3925 1310.6686 1319.9787 1327.1247 1330.6477
#> 2004 1388.6168 1387.2256 1387.6884 1391.0740 1392.5169
#> 2005 1384.0256 1384.9608 1380.6550 1375.4039 1375.9441
#> 2006 1415.5131 1414.3555 1415.9911 1420.9595 1426.0610
#> 2007 1504.3033 1511.4876 1517.3394 1521.8845 1527.2877
#> 2008 1516.9330 1528.8439 1539.0051 1546.1290 1552.1924
#> 2009 1569.6415 1567.6048 1570.3348 1573.0643 1569.8358
#> 2010 1558.5893 1556.6240 1549.2444 1540.7244 1536.4873
#> 2011 1503.7305 1499.9448 1498.9432 1500.4005 1501.7981
#> 2012 1533.8484 1527.9859 1524.0638 1522.9803 1523.1034
#> 2013 1514.3497 1517.9286 1517.7686 1513.9166 1510.5018
#> 2014 1515.7317 1516.9847 1518.1428 1519.6370 1520.8240
#> 2015 1570.2753 1581.1962 1592.2694 1601.1666 1604.7084
#> 2016 1550.6404 1545.0351 1538.8459 1534.2685 1534.2199
#> 2017 1546.0510
compare(tc_2 * b1 , "b7")
#> [1] TRUE

si_2 <- 1 - tc_2
si_2 * b1 # b8
#>               Jan          Feb          Mar          Apr          May
#> 1982                                         -18.1764686   19.7991942
#> 1983 -110.0404355 -117.6110797  -29.1316445   -1.3037913    4.8135647
#> 1984 -111.5366186 -114.7061493  -49.3533483  -53.1487757   49.9930754
#> 1985  -73.8932195 -147.7107406  -85.6805524  -34.2799629   70.4388188
#> 1986  -76.6107479 -168.7834557 -100.7250581  -57.5061620   91.8668920
#> 1987  -89.1686548 -190.6874404 -106.5011209  -36.6286817   -2.7933472
#> 1988 -116.0877205 -203.5823499  -80.5458466  -44.1469853  -17.7856636
#> 1989 -156.4299699 -232.3448709  -63.2924005  -86.8335163  -25.2580321
#> 1990 -136.9236148 -230.7223472  -93.7208319  -80.8422036  -13.0787333
#> 1991 -129.5192622 -217.8065914 -103.3613724  -75.3336339    1.2270063
#> 1992 -120.1440573 -198.5782340 -165.5668002  -36.3926471   10.1006068
#> 1993 -122.0122054 -243.0296430 -134.7677611  -51.4340242   12.8443733
#> 1994 -156.2830838 -242.4509755  -88.8225033  -80.7864796   -6.3847632
#> 1995 -180.9636517 -251.0731476 -127.0310398  -39.9663905  -26.1951561
#> 1996 -137.9398843 -234.2401280 -159.7341885  -77.3164087  -11.0616385
#> 1997 -126.8838117 -244.1350230 -115.3678003 -124.3590905   19.8210415
#> 1998  -79.9415030 -281.1742815 -176.9649165  -34.3565596  -39.4485387
#> 1999  -96.7253985 -300.8018804 -134.6463470  -85.1668007  -30.6716176
#> 2000 -149.7140027 -282.6930982 -185.5444590  -70.7638080  -51.7199624
#> 2001 -156.1248673 -316.2176975 -119.4392287 -101.4838671  -18.6089911
#> 2002 -153.8392796 -345.1206498 -145.0180591 -116.8846359   -4.7907999
#> 2003 -161.5823583 -367.1421069 -181.1294542  -56.4051416  -47.1755318
#> 2004 -150.2752590 -348.5093452 -214.4059212  -78.4295141  -86.6878451
#> 2005 -146.1502728 -352.5996850  -84.4682566 -227.1591109 -113.1672899
#> 2006 -186.5915528 -349.6415245 -194.0500121  -60.7835213 -148.1646817
#> 2007 -166.1929550 -394.1822823 -117.2879170 -155.9259891 -106.0088366
#> 2008 -131.0771088 -385.8858216 -169.3243286 -117.8015696  -88.7918791
#> 2009 -108.1935911 -510.4934932 -185.9798346  -67.1198953  -57.1863970
#> 2010  -91.6676551 -438.9381235 -163.4420188 -151.2041251 -116.5216452
#> 2011 -121.5554959 -414.4070549 -207.8026117  -53.8196846 -112.6278111
#> 2012 -145.5353046 -385.4257916 -176.6547095 -142.4003250  -81.8679545
#> 2013 -125.9436127 -407.5137112 -120.8472402 -174.6358630  -68.5123233
#> 2014  -54.8188912 -438.3206141 -211.1505783  -63.5646932  -96.9807260
#> 2015  -50.7322106 -469.6603880 -158.5921864  -88.9162589 -110.4194381
#> 2016  -85.7907753 -446.6616037 -143.9171518 -135.0689866 -126.4815884
#> 2017 -111.8164676 -457.1423868 -189.5415609  -43.5639476 -114.2342005
#>               Jun          Jul          Aug          Sep          Oct
#> 1982  -43.8970391  -32.9921126  -55.7801050  -27.2454317  -34.8649125
#> 1983  -44.0551555  -40.2026621  -53.8795948  -33.3278857  -34.5318651
#> 1984  -56.3454166  -21.1273459  -66.8071010  -50.9675667  -18.8124641
#> 1985  -73.7526892  -36.6847860  -60.2917427  -82.1273489  -10.3582220
#> 1986 -115.3499551  -14.1090159 -104.2007942  -30.1372951  -31.5897613
#> 1987  -52.7959394   -7.4547509 -128.3434398  -57.1201292  -20.1136970
#> 1988  -34.6617370  -75.1509369 -114.0226230  -50.3152727  -52.8424932
#> 1989  -11.3288169  -89.4296034  -85.8213988  -55.4234577  -63.4347249
#> 1990    1.5869248 -119.7137856  -67.6126719  -82.1620372  -34.2291240
#> 1991  -86.0333588  -45.1391245  -75.2198137 -109.3944650    4.4571237
#> 1992  -43.7527784  -83.8360641 -151.9525021  -59.3869927   20.4199717
#> 1993   -6.0805897 -119.8134633 -160.4061399  -41.9275854   -0.2560126
#> 1994   -4.4651486 -139.3011830 -130.2618597  -48.2238998   -2.9879990
#> 1995  -51.7753166  -80.6949961  -87.7450910 -106.2434307  -44.8485715
#> 1996  -66.4545138  -66.3661733  -81.8972266 -131.4632146  -27.7199209
#> 1997 -148.7540370  -12.9581383 -154.3254317  -57.1855374  -21.6630156
#> 1998 -165.8631278   22.1321705 -154.7399670  -88.1493825   -9.3820488
#> 1999 -153.8718787   -2.8997072 -166.4958907  -70.1855552  -32.0268549
#> 2000   54.8665166 -254.6967639 -105.3689384  -58.9674043  -43.2101768
#> 2001 -117.9506458  -43.7973742 -184.9822462 -140.5453478  -28.8738249
#> 2002  -57.6013951 -132.2087241 -151.4961133 -168.4466077  -27.0462154
#> 2003  -51.8706425 -112.8380291 -200.1924915 -112.4686118   -3.8786900
#> 2004    6.2999164  -79.4080820 -221.8168278  -69.3256234  -29.3883826
#> 2005   77.2033598  -90.4527781 -173.3255912 -107.1608477  -66.2549619
#> 2006   11.0623648   -5.2442758 -176.3130588 -195.2554702  -71.3910628
#> 2007    7.3436723  -33.0979075 -188.8032629 -158.1875984  -76.7394194
#> 2008 -105.6434119   73.6448655 -248.5330029 -145.5439469  -86.6051256
#> 2009  -75.5229964   -3.0840881 -228.1415472 -167.7048264  -36.0348421
#> 2010    1.9053858   25.4149821 -234.5893390 -134.6239965  -84.3444376
#> 2011  -43.3127668   23.4433680 -210.2305394 -154.2447662  -94.2432152
#> 2012   76.1396654 -114.9190105 -174.8484215 -160.1858704  -81.4638254
#> 2013   27.3488773 -121.0092456 -177.1496674 -158.5285510  -54.4686108
#> 2014  -49.8399134  -11.9702832 -261.5317153 -160.5847103  -39.4428174
#> 2015  -67.4359487  -17.8293397 -238.3753196 -181.0962490  -25.9693782
#> 2016   29.9120329  -89.6160373 -256.7404030 -151.5351013  -41.4458743
#> 2017   -4.8954782 -109.6215511 -242.9509913                          
#>               Nov          Dec
#> 1982   38.5945852  404.6661840
#> 1983   46.2247879  439.6135712
#> 1984   45.9161917  457.3476972
#> 1985   49.0662718  539.5705460
#> 1986   -0.4602892  664.3351777
#> 1987   11.0359789  721.7326365
#> 1988   81.7044971  780.0422080
#> 1989  108.6776656  754.9718433
#> 1990  111.2370154  740.7968343
#> 1991   89.0158584  742.8268712
#> 1992   84.3267984  766.7292635
#> 1993   78.9204581  814.2137760
#> 1994   63.8827944  882.7394450
#> 1995   99.3724992  887.6973047
#> 1996  120.7205304  873.9056411
#> 1997  113.0527949  880.5598374
#> 1998  103.7554241  938.6489156
#> 1999  131.2412072  996.8231443
#> 2000  115.6137521 1054.2935304
#> 2001  176.7469189 1094.3103056
#> 2002  248.6228906 1084.4841513
#> 2003  201.0752559 1093.5522516
#> 2004  145.6260479 1108.2830607
#> 2005  164.9960575 1160.0558607
#> 2006  202.3404846 1185.0389948
#> 2007  166.0155197 1219.7122960
#> 2008  129.7709981 1333.9075549
#> 2009  163.5357444 1225.2641538
#> 2010  164.7755809 1215.9127030
#> 2011  159.5994852 1228.7019297
#> 2012  149.9196972 1230.1966005
#> 2013  154.9834303 1214.9982333
#> 2014  168.0630054 1236.0759793
#> 2015  129.3334405 1308.8916168
#> 2016  150.0315061 1316.1801312
#> 2017
compare(si_2 * b1 , "b8")
#> [1] TRUE

M3X5 <- macurves("S3x5")
M3X5_s <- to_seasonal(M3X5, 12)
s_2 <- M3X5_s * si_2
s_2_norm <- M2X12 * s_2
s_2_norm <- impute_last_obs(s_2_norm, n = 6, nperiod = 1)
s_2_demean <- s_2 - s_2_norm
s_2_f <- impute_last_obs(s_2_demean, n = 6, nperiod = 12)
s_2_f * b1 # b10
#>               Jan          Feb          Mar          Apr          May
#> 1982                                         -25.3309999   32.0933639
#> 1983  -94.8072734 -132.5039611  -60.9632263  -27.5940738   38.4656216
#> 1984  -93.4405758 -138.0283886  -65.5174833  -30.9065186   43.4537317
#> 1985  -92.4337834 -149.1214588  -73.5035784  -36.5738092   44.6224107
#> 1986  -95.5356416 -166.0543860  -80.3480411  -42.5403612   36.7625160
#> 1987 -103.0997690 -185.0082069  -85.3507755  -50.8318103   24.4439216
#> 1988 -113.7534696 -201.8431048  -87.2564140  -57.6127241    7.2730851
#> 1989 -123.6783205 -211.2668323  -91.9945746  -62.2209366   -4.0749069
#> 1990 -129.8902698 -217.9137026  -99.8605123  -64.2529559   -7.6213725
#> 1991 -132.5851010 -221.7316606 -109.1395798  -64.6523764   -3.4888467
#> 1992 -135.8907643 -226.7066413 -116.9408237  -62.0710633   -0.7454942
#> 1993 -139.2985328 -229.9282476 -124.7429692  -58.8762733   -0.8425102
#> 1994 -142.8672723 -235.4919708 -127.5525229  -62.0264307   -1.6861693
#> 1995 -140.6730544 -242.1250096 -130.7447905  -66.7947310   -5.3598522
#> 1996 -133.9630161 -251.5667909 -133.1560787  -71.7115206   -9.8237326
#> 1997 -125.4175867 -259.6983452 -142.5984048  -72.8382258  -16.6374929
#> 1998 -121.0108043 -270.9625923 -146.4699895  -76.5219806  -20.2976231
#> 1999 -122.4555763 -285.1852187 -149.4387760  -79.2832036  -23.9936050
#> 2000 -131.1162123 -303.3536215 -148.9702556  -81.6413266  -26.6639892
#> 2001 -142.2276090 -319.1567974 -156.8612899  -82.5213435  -32.8067509
#> 2002 -150.8928624 -333.2099007 -156.1773556  -94.5541164  -41.4499832
#> 2003 -156.1909040 -343.8459604 -160.3630860 -102.2329381  -58.0002798
#> 2004 -158.6064505 -354.3417373 -157.1625026 -112.8418890  -77.3600917
#> 2005 -159.3833392 -361.1624942 -159.6694996 -116.8692263  -95.0632488
#> 2006 -155.2393337 -376.4166073 -154.9106033 -122.5613025 -102.4472736
#> 2007 -146.7424243 -394.1754213 -157.2765040 -120.6028258 -103.5612662
#> 2008 -136.0005933 -414.6812314 -161.4423165 -114.5721692  -99.9459013
#> 2009 -126.8608201 -423.9934186 -171.7282723 -108.5620128  -96.5213635
#> 2010 -120.9315101 -428.8009541 -173.4115152 -111.2051564  -91.6211973
#> 2011 -115.7193339 -424.8101620 -175.6855092 -113.6852201  -91.3279376
#> 2012 -108.8142014 -423.2709682 -173.4179330 -112.7458749  -92.0048849
#> 2013 -100.0959639 -422.5104882 -170.0823348 -113.4426486  -94.8050819
#> 2014  -92.5919383 -431.2902656 -166.0354812 -107.8903331  -97.3653281
#> 2015  -84.5750842 -441.3151357 -166.2890203 -100.5779022 -103.2950393
#> 2016  -80.0912322 -450.1595025 -168.6683661  -89.2050778 -109.2962109
#> 2017  -77.9742516 -454.1664141 -170.3570895  -84.6103901 -113.3055046
#>               Jun          Jul          Aug          Sep          Oct
#> 1982  -51.5580052  -31.8380974  -58.6534670  -43.5331315  -26.1571304
#> 1983  -57.1820610  -31.9862541  -62.6764735  -45.0666053  -25.8073950
#> 1984  -63.4092885  -30.4625299  -71.4920497  -48.6091303  -24.6162610
#> 1985  -67.7702906  -30.7403735  -83.8238451  -50.8166491  -25.6678276
#> 1986  -65.1270320  -36.3862520  -94.1357535  -54.4425762  -29.0961350
#> 1987  -56.6319284  -48.5078110  -99.5763577  -55.7879556  -35.0015517
#> 1988  -46.6197286  -59.9422814  -99.0205364  -61.1712048  -36.9335754
#> 1989  -38.9643687  -72.0197920  -98.8115926  -66.2623046  -33.0542658
#> 1990  -34.2625768  -81.6023255 -101.2454485  -70.8823193  -24.1901127
#> 1991  -31.0879057  -92.8884678 -108.6951969  -69.8521049  -13.9945633
#> 1992  -32.0113641  -96.5945847 -116.1543793  -70.5384230   -7.2957803
#> 1993  -33.8325641  -99.0098491 -121.0634036  -73.4060180   -6.3391974
#> 1994  -43.0484020  -93.2625481 -123.3627004  -76.6155965  -12.1867028
#> 1995  -59.4512128  -80.6716864 -123.8429421  -81.1890320  -17.9359129
#> 1996  -87.1223359  -57.5067563 -126.2999731  -85.5855448  -23.1403084
#> 1997 -100.7441783  -50.6482746 -129.3214929  -86.8954992  -25.6061099
#> 1998 -107.2176678  -51.8660627 -139.6412972  -85.5967913  -27.3710320
#> 1999  -97.7538610  -70.1370216 -147.2607713  -90.2287768  -27.6337245
#> 2000  -87.7146377  -85.6538144 -157.0449390  -99.7049349  -27.2869984
#> 2001  -63.1943052 -107.3187053 -163.3619350 -108.9231389  -27.2478711
#> 2002  -43.2126767 -110.1222693 -174.5533067 -113.5929573  -28.1129888
#> 2003  -22.1494111 -101.3440372 -181.9455544 -120.4423747  -32.5258204
#> 2004   -7.4047580  -81.0327125 -188.4180208 -126.5456477  -40.1523819
#> 2005    2.3584815  -59.5807655 -193.5521705 -131.6454306  -51.9507661
#> 2006   -2.2316344  -35.5915732 -199.9044269 -139.5459505  -61.0656919
#> 2007  -16.3822971  -10.3131253 -207.5676347 -149.8762401  -68.0845230
#> 2008  -30.5119057    4.9881727 -214.1734615 -155.6008573  -71.0885228
#> 2009  -34.5104510    9.6632936 -219.1383904 -154.9145233  -74.2017143
#> 2010  -24.6984141   -6.3535300 -215.5559880 -153.3736462  -74.0508431
#> 2011   -9.5888516  -25.3978932 -212.0597208 -153.9334798  -72.8000472
#> 2012   -3.5914372  -42.1226284 -210.1072365 -157.7638732  -67.3093996
#> 2013   -1.7274909  -53.7611458 -215.8578673 -160.0126969  -60.2298887
#> 2014   -6.8238388  -63.8845959 -223.7922058 -162.9476846  -49.8263996
#> 2015  -10.6308210  -66.4783415 -235.8340136 -162.7649201  -42.2357143
#> 2016  -17.3317478  -64.2804670 -243.9402740 -162.9686889  -38.0389358
#> 2017  -18.7648967  -62.5679202 -247.6187409                          
#>               Nov          Dec
#> 1982   44.6479839  449.9493658
#> 1983   41.8696870  468.8986557
#> 1984   37.2538632  508.9761226
#> 1985   34.7750371  566.5014430
#> 1986   39.5183326  630.1424226
#> 1987   50.2134775  686.2290368
#> 1988   64.3993582  724.4655805
#> 1989   79.3343640  745.8651875
#> 1990   89.8823887  756.0165090
#> 1991   91.5136365  769.9749487
#> 1992   87.5264250  790.6841665
#> 1993   85.9292510  818.1365901
#> 1994   89.1530511  844.6477366
#> 1995   94.6872760  869.6232842
#> 1996  102.8331315  892.7078147
#> 1997  110.0216813  919.2499713
#> 1998  119.4367599  952.0949678
#> 1999  133.2827565  991.4102721
#> 2000  153.0082760 1030.0368607
#> 2001  169.9059936 1062.0955740
#> 2002  180.9376484 1087.4931585
#> 2003  186.9298245 1108.4480955
#> 2004  186.1592063 1130.4571844
#> 2005  177.1085586 1161.1923800
#> 2006  167.6066328 1193.7126062
#> 2007  163.7734197 1220.7873036
#> 2008  162.2805753 1234.9944738
#> 2009  158.5778422 1241.9182656
#> 2010  156.4018121 1237.6532587
#> 2011  156.8765806 1231.1447120
#> 2012  156.3427928 1230.2440175
#> 2013  153.2538480 1242.8809986
#> 2014  150.6042613 1257.8915970
#> 2015  149.9371535 1270.2649518
#> 2016  150.3874691 1276.8386358
#> 2017
compare(s_2_f * b1 , "b10")
#> [1] TRUE
sa_2 <- 1 - s_2_f
sa_2 * b1 # b11
#>            Jan       Feb       Mar       Apr       May       Jun       Jul
#> 1982                                485.4310  470.5066  495.3580  490.9381
#> 1983  474.0073  510.5040  533.0632  530.9941  472.1344  519.5821  500.2863
#> 1984  508.1406  552.5284  550.2175  518.2065  554.4463  563.8093  573.8625
#> 1985  608.7338  601.6215  599.3036  624.2738  655.6776  629.5703  633.5404
#> 1986  666.0356  644.2544  627.7480  636.8404  714.8375  618.5270  699.5863
#> 1987  716.9998  698.2082  685.2508  724.9318  689.5561  727.1319  769.4078
#> 1988  744.7535  752.9431  765.3564  773.3127  733.5269  768.6197  743.4423
#> 1989  755.1783  763.2668  810.9946  759.8209  768.8749  825.2644  787.1198
#> 1990  808.0903  804.1137  826.6605  808.3530  823.1214  866.6626  791.9023
#> 1991  826.5851  826.4317  828.3396  812.8524  831.6888  777.9879  887.3885
#> 1992  875.8908  892.6066  818.4408  893.4711  879.3455  858.0114  884.7946
#> 1993  901.3985  872.9282  878.8430  899.5763  907.4425  920.9326  870.5098
#> 1994  888.5673  899.8920  949.0525  893.7264  909.6862  955.6484  876.1625
#> 1995  893.0731  924.6250  941.9448  972.7947  932.5599  966.2512  961.2717
#> 1996  967.0630  988.6668  945.1561  966.9115  972.6237  995.7223  965.5068
#> 1997  966.3176  987.0983 1000.4984  921.8382 1011.4375  930.9442 1021.7483
#> 1998 1038.3108  987.1626  969.3700 1046.6220  990.4976  956.6177 1094.1661
#> 1999 1064.4556 1023.5852 1052.6388 1032.4832 1035.1936  992.1539 1124.6370
#> 2000 1056.0162 1101.5536 1050.8703 1106.3413 1078.9640 1253.2146  944.9538
#> 2001 1114.1276 1133.7568 1174.3613 1121.7213 1156.3068 1088.0943 1208.1187
#> 2002 1178.7929 1174.6099 1200.0774 1169.8541 1232.3500 1186.2127 1185.8223
#> 2003 1255.4909 1244.3460 1253.0631 1324.6329 1295.1003 1260.0494 1283.3440
#> 2004 1341.5065 1344.1417 1288.5625 1389.9419 1357.6601 1391.5048 1386.9327
#> 2005 1405.6833 1398.4625 1460.4695 1270.5692 1359.2632 1451.8415 1349.6808
#> 2006 1348.9393 1414.1166 1359.4106 1471.1613 1370.0473 1431.2316 1447.5916
#> 2007 1414.0424 1441.1754 1488.8765 1423.2028 1468.6613 1507.8823 1472.6131
#> 2008 1533.8006 1555.1812 1513.1423 1511.1722 1521.0459 1432.1119 1577.3118
#> 2009 1577.8608 1480.5934 1558.6283 1617.6620 1615.9214 1535.0105 1561.0367
#> 2010 1590.0315 1540.7010 1553.3115 1500.9052 1518.8212 1576.0984 1587.3535
#> 2011 1528.3193 1542.3102 1497.2855 1586.2852 1500.2279 1481.4889 1557.8979
#> 2012 1471.2142 1554.9710 1522.6179 1503.9459 1548.9049 1619.9914 1465.5226
#> 2013 1497.4960 1536.1105 1567.3823 1452.5426 1536.7051 1539.1275 1444.3611
#> 2014 1543.5919 1496.1903 1459.2355 1550.7903 1509.1653 1468.4238 1565.4846
#> 2015 1555.7751 1495.1151 1533.4890 1542.7779 1531.9950 1491.5308 1607.3783
#> 2016 1599.2912 1605.9595 1620.1684 1540.2051 1558.9962 1613.4317 1532.5805
#> 2017 1506.4743 1546.5664 1540.6571 1607.2104 1565.7055 1575.9649 1508.0679
#>            Aug       Sep       Oct       Nov       Dec
#> 1982  497.0535  508.6331  478.8571  478.2520  439.3506
#> 1983  520.8765  527.7666  511.1074  526.8303  494.8013
#> 1984  574.8920  571.4091  581.2163  585.9461  530.4239
#> 1985  666.3238  613.9166  662.7678  662.3250  620.9986
#> 1986  675.2358  716.3426  694.6961  661.3817  737.7576
#> 1987  701.1764  728.0880  744.1016  692.9865  773.8710
#> 1988  749.9205  784.4712  766.5336  805.9006  845.5344
#> 1989  822.6116  824.1623  784.7543  844.4656  823.5348
#> 1990  860.6454  811.9823  810.7901  841.6176  807.0835
#> 1991  879.0952  811.3521  872.5946  853.1864  830.3251
#> 1992  839.7544  890.3384  909.7958  881.0736  860.2158
#> 1993  849.7634  918.1060  893.2392  884.0707  892.3634
#> 1994  922.1627  963.6156  946.7867  911.2469  972.8523
#> 1995  997.7429  937.9890  938.5359  972.7127  987.5767
#> 1996 1015.2000  919.2855  956.8403  978.7669  944.8922
#> 1997  965.3215 1025.9955 1002.5061 1001.2783  959.8500
#> 1998 1009.5413 1024.9968 1048.6710 1018.2632 1023.6050
#> 1999 1046.7608 1092.5288 1071.3337 1073.9172 1078.1897
#> 2000 1166.2449 1154.3049 1097.6870 1079.4917 1147.4631
#> 2001 1126.3619 1121.8231 1159.2479 1174.8940 1207.4044
#> 2002 1240.4533 1173.6930 1239.5130 1314.1624 1251.1068
#> 2003 1283.1456 1318.6424 1348.6258 1341.2702 1315.7519
#> 2004 1355.2180 1444.4456 1398.4524 1350.5408 1370.3428
#> 2005 1404.2522 1409.4454 1366.3508 1363.2914 1374.8076
#> 2006 1439.1044 1358.6460 1405.6657 1455.6934 1417.3874
#> 2007 1523.0676 1503.1762 1508.6845 1524.1266 1526.2127
#> 2008 1482.5735 1538.9009 1523.4885 1513.6194 1651.1055
#> 2009 1560.6384 1554.8145 1608.5017 1578.0222 1553.1817
#> 2010 1539.5560 1575.3736 1538.9508 1549.0982 1514.7467
#> 2011 1505.5597 1499.6335 1477.5000 1503.1234 1499.3553
#> 2012 1569.1072 1525.5639 1509.9094 1516.5572 1523.0560
#> 2013 1553.0579 1519.4127 1523.5299 1515.6462 1482.6190
#> 2014 1477.9922 1519.3477 1528.5264 1537.0957 1499.0084
#> 2015 1567.7340 1562.8649 1608.5357 1580.5628 1643.3350
#> 2016 1537.8403 1556.4687 1535.4389 1533.9125 1573.5614
#> 2017 1550.7187
compare(sa_2 * b1 , "b11")
#> [1] TRUE

X-11 with outlier correction

if (!exists("sa_2")) {
  # we redefined the moving averages if they don't exist
  tc_1 <- M2X12 <- (simple_ma(12, - 6) + simple_ma(12, - 5))/2
  si_1 <- 1 - tc_1
  M3X3 <- macurves("S3x3")
  M3X3_s <- to_seasonal(M3X3, 12)
  s_1 <- M3X3_s * si_1
  s_1_norm <- M2X12 * s_1
  s_1_norm <- impute_last_obs(s_1_norm, n = 6, nperiod = 1)
  s_1_demean <- s_1 - s_1_norm
  s_1_f <- impute_last_obs(s_1_demean, n = 6, nperiod = 12)
  sa_1 <- 1- s_1_f
  h13 <- lp_filter(horizon = 6, ic = 3.5)
  tc_2 <- h13 * sa_1
  si_2 <- 1 - tc_2
  M3X5 <- macurves("S3x5")
  M3X5_s <- to_seasonal(M3X5, 12)
  s_2 <- M3X5_s * si_2
  s_2_norm <- M2X12 * s_2
  s_2_norm <- impute_last_obs(s_2_norm, n = 6, nperiod = 1)
  s_2_demean <- s_2 - s_2_norm
  s_2_f <- impute_last_obs(s_2_demean, n = 6, nperiod = 12)
  sa_2 <- 1 - s_2_f
}
compare <- function(x, id, na.rm = TRUE) {
  if (na.rm)
    x <- na.omit(x)
  res <- cbind(x, x11_step$user_defined[[id]])
  all.equal(res[,1], res[,2], check.attributes = FALSE)
}
ud_var <- c("b1", "b2", "b3", "b4", "b4a", "b4d", "b5",
            "b6", "b7", "b8", "b9", "b10", "b11", "b13", "b17", "b20", "c1",
            "c2", "c4", "c5", "c6", "c7", "c9", "c10", "c11", "c13",
            "c17", "c20", "d1", "d2", "d4", "d5", "d6", "d7", "d8",
            "d10", "d11", "d12", "d13", "d10bis", "d11bis")
b1 <- rjd3toolkit::ABS$X0.2.09.10.M  # b1
x11_step <- x11plus_trend(b1, trend.coefs = lp_filter(horizon = 6, ic = 3.5),
                             mul = FALSE,
                             seas.s0 = "S3X3",
                             seas.s1 = "S3X5",
                             userdefined = ud_var)

# B tables
compare(b1, "b1")
#> [1] TRUE
b2 <- tc_1 * b1
compare(b2, "b2")
#> [1] TRUE
b3 <- si_1 * b1
compare(b3, "b3")
#> [1] TRUE

b4a <- M3X3_s * b3
#compare(b4a, "b4a")

b4norm <- b4a - impute_last_obs(finite_filters(M2X12), n = 6, nperiod = 1) * b4a
b4d <- b3 - b4norm
#compare(b4d, "b4d")

corr <- x11_extreme_values_corr(x = b4d,
                                corrected_s = b3, mul = FALSE, start = 6)
b4 <- corr[, "correction_factors"]
b4g <- b3
b4g[!is.nan(b4)] <- b4[!is.nan(b4)]
compare(window(b4, start = start(na.omit(b3)), end = end(na.omit(b3))),
        "b4",
        na.rm = FALSE)
#> [1] TRUE

b5a <- M3X3_s * b4g
b5 <- b5a - impute_last_obs(finite_filters(M2X12), n = 6, nperiod = 1) * b5a
b5 <- filter(b5, impute_last_obs(moving_average(c(rep(0,6),1, rep(0,6)), lags = -6),
                                 n = 6, nperiod = 12), remove_missing = FALSE)
compare(b5, "b5")
#> [1] TRUE
b6 <- b1 - b5
compare(b6, "b6")
#> [1] TRUE
b7 <- h13 * b6
compare(b7, "b7")
#> [1] TRUE

b8 <- b1 - b7
compare(b8, "b8")
#> [1] TRUE

b9a <- M3X5_s * b8
b9c <-  b9a - impute_last_obs(finite_filters(M2X12), n = 6, nperiod = 1) * b9a
b9d <-  b8 - b9c
corr <- x11_extreme_values_corr(x = b9d,
                                corrected_s = b8, mul = FALSE, start = 0)
b9 <- corr[, "correction_factors"]
b9g <- b8
b9g[!is.nan(b9)] <- b9[!is.nan(b9)]
compare(b9, "b9", na.rm = FALSE)
#> [1] TRUE

b10a <- M3X5_s * b9g
b10 <-  b10a - impute_last_obs(finite_filters(M2X12), n = 6, nperiod = 1) * b10a
b11 <-  b1 - b10
b13 <-  b11 - b7
compare(b10,  "b10")
#> [1] TRUE
compare(b11,  "b11")
#> [1] TRUE
compare(b13,  "b13")
#> [1] TRUE


corr <- x11_extreme_values_corr(x = b13, mul = FALSE, start = 0)
b17 <- corr[, "obs_weight"]
b20 <- corr[, "correction_factors"]
compare(b17,  "b17")
#> [1] TRUE
compare(b20,  "b20")
#> [1] TRUE

# C tables
c1 <- b1 - b20
compare(c1,  "c1")
#> [1] TRUE
c2 <- tc_1 * c1
compare(c2,  "c2")
#> [1] TRUE
c4 <- c1 - c2
compare(c4,  "c4")
#> [1] TRUE
c5 <- s_1_f * c1
compare(c5,  "c5")
#> [1] TRUE
c6 <- sa_1 * c1
compare(c6 , "c6")
#> [1] TRUE
c7 <- tc_2 * c1
compare(c7 , "c7")
#> [1] TRUE
c9 <- si_2 * c1
compare(c9 , "c9")
#> [1] TRUE
c10 <- s_2_f * c1
compare(c10 , "c10")
#> [1] TRUE
c11 <- b1 - c10
compare(c11 , "c11")
#> [1] TRUE
c13 <- c11 - c7
compare(c13 , "c13")
#> [1] TRUE

corr <- x11_extreme_values_corr(x = c13, mul = FALSE, start = 0)
c17 <- corr[, "obs_weight"]
c20 <- corr[, "correction_factors"]
compare(c17,  "c17")
#> [1] TRUE
compare(c20,  "c20")
#> [1] TRUE

# D tables
d1 <- b1 - c20
compare(d1,  "d1")
#> [1] TRUE
d2 <- tc_1 * d1
compare(d2,  "d2")
#> [1] TRUE
d4 <- d1 - d2
compare(d4,  "d4")
#> [1] TRUE
d5 <- s_1_f * d1
compare(d5,  "d5")
#> [1] TRUE
d6 <- sa_1 * d1
compare(d6 , "d6")
#> [1] TRUE
d7 <- tc_2 * d1
compare(d7 , "d7")
#> [1] TRUE
d8 <- b1 - d7
compare(d8 , "d8")
#> [1] TRUE
d9bis <- d1 - d7
d10bis <- M3X5_s * d9bis
#compare(d10bis , "d10bis")
d10 <- d10bis - impute_last_obs(finite_filters(M2X12), n = 6, nperiod = 1) * d10bis
compare(d10 , "d10")
#> [1] TRUE
d11bis <- d1 - d10
#compare(d11bis , "d11bis")
d11 <- b1 - d10
compare(d11 , "d11")
#> [1] TRUE
d12 <- h13 * d11bis
compare(d12 , "d12")
#> [1] TRUE
d13 <- d11 - d12
compare(d13 , "d13")
#> [1] TRUE