Create trend and seasonality features for univariate time series

createtrendseason(y)

Arguments

y

a univariate time series

Value

a vector or matrix of features

Examples


y <- ts(rnorm(100), start = 1, frequency = 12)
createtrendseason(y)
#>       trend    sin_season    cos_season
#> Jan 1     1  5.000000e-01  8.660254e-01
#> Feb 1     2  8.660254e-01  5.000000e-01
#> Mar 1     3  1.000000e+00  6.123234e-17
#> Apr 1     4  8.660254e-01 -5.000000e-01
#> May 1     5  5.000000e-01 -8.660254e-01
#> Jun 1     6  1.224647e-16 -1.000000e+00
#> Jul 1     7 -5.000000e-01 -8.660254e-01
#> Aug 1     8 -8.660254e-01 -5.000000e-01
#> Sep 1     9 -1.000000e+00 -1.836970e-16
#> Oct 1    10 -8.660254e-01  5.000000e-01
#> Nov 1    11 -5.000000e-01  8.660254e-01
#> Dec 1    12 -2.449294e-16  1.000000e+00
#> Jan 2    13  5.000000e-01  8.660254e-01
#> Feb 2    14  8.660254e-01  5.000000e-01
#> Mar 2    15  1.000000e+00  1.194340e-15
#> Apr 2    16  8.660254e-01 -5.000000e-01
#> May 2    17  5.000000e-01 -8.660254e-01
#> Jun 2    18  3.673940e-16 -1.000000e+00
#> Jul 2    19 -5.000000e-01 -8.660254e-01
#> Aug 2    20 -8.660254e-01 -5.000000e-01
#> Sep 2    21 -1.000000e+00 -4.286264e-16
#> Oct 2    22 -8.660254e-01  5.000000e-01
#> Nov 2    23 -5.000000e-01  8.660254e-01
#> Dec 2    24 -4.898587e-16  1.000000e+00
#> Jan 3    25  5.000000e-01  8.660254e-01
#> Feb 3    26  8.660254e-01  5.000000e-01
#> Mar 3    27  1.000000e+00  5.510911e-16
#> Apr 3    28  8.660254e-01 -5.000000e-01
#> May 3    29  5.000000e-01 -8.660254e-01
#> Jun 3    30  2.388680e-15 -1.000000e+00
#> Jul 3    31 -5.000000e-01 -8.660254e-01
#> Aug 3    32 -8.660254e-01 -5.000000e-01
#> Sep 3    33 -1.000000e+00  1.102801e-15
#> Oct 3    34 -8.660254e-01  5.000000e-01
#> Nov 3    35 -5.000000e-01  8.660254e-01
#> Dec 3    36 -7.347881e-16  1.000000e+00
#> Jan 4    37  5.000000e-01  8.660254e-01
#> Feb 4    38  8.660254e-01  5.000000e-01
#> Mar 4    39  1.000000e+00  2.572377e-15
#> Apr 4    40  8.660254e-01 -5.000000e-01
#> May 4    41  5.000000e-01 -8.660254e-01
#> Jun 4    42  8.572528e-16 -1.000000e+00
#> Jul 4    43 -5.000000e-01 -8.660254e-01
#> Aug 4    44 -8.660254e-01 -5.000000e-01
#> Sep 4    45 -1.000000e+00  8.578717e-16
#> Oct 4    46 -8.660254e-01  5.000000e-01
#> Nov 4    47 -5.000000e-01  8.660254e-01
#> Dec 4    48 -9.797174e-16  1.000000e+00
#> Jan 5    49  5.000000e-01  8.660254e-01
#> Feb 5    50  8.660254e-01  5.000000e-01
#> Mar 5    51  1.000000e+00  2.817307e-15
#> Apr 5    52  8.660254e-01 -5.000000e-01
#> May 5    53  5.000000e-01 -8.660254e-01
#> Jun 5    54  1.102182e-15 -1.000000e+00
#> Jul 5    55 -5.000000e-01 -8.660254e-01
#> Aug 5    56 -8.660254e-01 -5.000000e-01
#> Sep 5    57 -1.000000e+00 -2.939771e-15
#> Oct 5    58 -8.660254e-01  5.000000e-01
#> Nov 5    59 -5.000000e-01  8.660254e-01
#> Dec 5    60 -4.777360e-15  1.000000e+00
#> Jan 6    61  5.000000e-01  8.660254e-01
#> Feb 6    62  8.660254e-01  5.000000e-01
#> Mar 6    63  1.000000e+00 -4.904777e-16
#> Apr 6    64  8.660254e-01 -5.000000e-01
#> May 6    65  5.000000e-01 -8.660254e-01
#> Jun 6    66 -2.205602e-15 -1.000000e+00
#> Jul 6    67 -5.000000e-01 -8.660254e-01
#> Aug 6    68 -8.660254e-01 -5.000000e-01
#> Sep 6    69 -1.000000e+00 -3.184701e-15
#> Oct 6    70 -8.660254e-01  5.000000e-01
#> Nov 6    71 -5.000000e-01  8.660254e-01
#> Dec 6    72 -1.469576e-15  1.000000e+00
#> Jan 7    73  5.000000e-01  8.660254e-01
#> Feb 7    74  8.660254e-01  5.000000e-01
#> Mar 7    75  1.000000e+00 -2.455483e-16
#> Apr 7    76  8.660254e-01 -5.000000e-01
#> May 7    77  5.000000e-01 -8.660254e-01
#> Jun 7    78  5.144755e-15 -1.000000e+00
#> Jul 7    79 -5.000000e-01 -8.660254e-01
#> Aug 7    80 -8.660254e-01 -5.000000e-01
#> Sep 7    81 -1.000000e+00 -3.429630e-15
#> Oct 7    82 -8.660254e-01  5.000000e-01
#> Nov 7    83 -5.000000e-01  8.660254e-01
#> Dec 7    84 -1.714506e-15  1.000000e+00
#> Jan 8    85  5.000000e-01  8.660254e-01
#> Feb 8    86  8.660254e-01  5.000000e-01
#> Mar 8    87  1.000000e+00  7.104808e-15
#> Apr 8    88  8.660254e-01 -5.000000e-01
#> May 8    89  5.000000e-01 -8.660254e-01
#> Jun 8    90 -1.715743e-15 -1.000000e+00
#> Jul 8    91 -5.000000e-01 -8.660254e-01
#> Aug 8    92 -8.660254e-01 -5.000000e-01
#> Sep 8    93 -1.000000e+00 -3.674559e-15
#> Oct 8    94 -8.660254e-01  5.000000e-01
#> Nov 8    95 -5.000000e-01  8.660254e-01
#> Dec 8    96 -1.959435e-15  1.000000e+00
#> Jan 9    97  5.000000e-01  8.660254e-01
#> Feb 9    98  8.660254e-01  5.000000e-01
#> Mar 9    99  1.000000e+00  2.443104e-16
#> Apr 9   100  8.660254e-01 -5.000000e-01

createtrendseason(USAccDeaths)
#>          trend    sin_season    cos_season
#> Jan 1973     1  5.000000e-01  8.660254e-01
#> Feb 1973     2  8.660254e-01  5.000000e-01
#> Mar 1973     3  1.000000e+00  6.123234e-17
#> Apr 1973     4  8.660254e-01 -5.000000e-01
#> May 1973     5  5.000000e-01 -8.660254e-01
#> Jun 1973     6  1.224647e-16 -1.000000e+00
#> Jul 1973     7 -5.000000e-01 -8.660254e-01
#> Aug 1973     8 -8.660254e-01 -5.000000e-01
#> Sep 1973     9 -1.000000e+00 -1.836970e-16
#> Oct 1973    10 -8.660254e-01  5.000000e-01
#> Nov 1973    11 -5.000000e-01  8.660254e-01
#> Dec 1973    12 -2.449294e-16  1.000000e+00
#> Jan 1974    13  5.000000e-01  8.660254e-01
#> Feb 1974    14  8.660254e-01  5.000000e-01
#> Mar 1974    15  1.000000e+00  1.194340e-15
#> Apr 1974    16  8.660254e-01 -5.000000e-01
#> May 1974    17  5.000000e-01 -8.660254e-01
#> Jun 1974    18  3.673940e-16 -1.000000e+00
#> Jul 1974    19 -5.000000e-01 -8.660254e-01
#> Aug 1974    20 -8.660254e-01 -5.000000e-01
#> Sep 1974    21 -1.000000e+00 -4.286264e-16
#> Oct 1974    22 -8.660254e-01  5.000000e-01
#> Nov 1974    23 -5.000000e-01  8.660254e-01
#> Dec 1974    24 -4.898587e-16  1.000000e+00
#> Jan 1975    25  5.000000e-01  8.660254e-01
#> Feb 1975    26  8.660254e-01  5.000000e-01
#> Mar 1975    27  1.000000e+00  5.510911e-16
#> Apr 1975    28  8.660254e-01 -5.000000e-01
#> May 1975    29  5.000000e-01 -8.660254e-01
#> Jun 1975    30  2.388680e-15 -1.000000e+00
#> Jul 1975    31 -5.000000e-01 -8.660254e-01
#> Aug 1975    32 -8.660254e-01 -5.000000e-01
#> Sep 1975    33 -1.000000e+00  1.102801e-15
#> Oct 1975    34 -8.660254e-01  5.000000e-01
#> Nov 1975    35 -5.000000e-01  8.660254e-01
#> Dec 1975    36 -7.347881e-16  1.000000e+00
#> Jan 1976    37  5.000000e-01  8.660254e-01
#> Feb 1976    38  8.660254e-01  5.000000e-01
#> Mar 1976    39  1.000000e+00  2.572377e-15
#> Apr 1976    40  8.660254e-01 -5.000000e-01
#> May 1976    41  5.000000e-01 -8.660254e-01
#> Jun 1976    42  8.572528e-16 -1.000000e+00
#> Jul 1976    43 -5.000000e-01 -8.660254e-01
#> Aug 1976    44 -8.660254e-01 -5.000000e-01
#> Sep 1976    45 -1.000000e+00  8.578717e-16
#> Oct 1976    46 -8.660254e-01  5.000000e-01
#> Nov 1976    47 -5.000000e-01  8.660254e-01
#> Dec 1976    48 -9.797174e-16  1.000000e+00
#> Jan 1977    49  5.000000e-01  8.660254e-01
#> Feb 1977    50  8.660254e-01  5.000000e-01
#> Mar 1977    51  1.000000e+00  2.817307e-15
#> Apr 1977    52  8.660254e-01 -5.000000e-01
#> May 1977    53  5.000000e-01 -8.660254e-01
#> Jun 1977    54  1.102182e-15 -1.000000e+00
#> Jul 1977    55 -5.000000e-01 -8.660254e-01
#> Aug 1977    56 -8.660254e-01 -5.000000e-01
#> Sep 1977    57 -1.000000e+00 -2.939771e-15
#> Oct 1977    58 -8.660254e-01  5.000000e-01
#> Nov 1977    59 -5.000000e-01  8.660254e-01
#> Dec 1977    60 -4.777360e-15  1.000000e+00
#> Jan 1978    61  5.000000e-01  8.660254e-01
#> Feb 1978    62  8.660254e-01  5.000000e-01
#> Mar 1978    63  1.000000e+00 -4.904777e-16
#> Apr 1978    64  8.660254e-01 -5.000000e-01
#> May 1978    65  5.000000e-01 -8.660254e-01
#> Jun 1978    66 -2.205602e-15 -1.000000e+00
#> Jul 1978    67 -5.000000e-01 -8.660254e-01
#> Aug 1978    68 -8.660254e-01 -5.000000e-01
#> Sep 1978    69 -1.000000e+00 -3.184701e-15
#> Oct 1978    70 -8.660254e-01  5.000000e-01
#> Nov 1978    71 -5.000000e-01  8.660254e-01
#> Dec 1978    72 -1.469576e-15  1.000000e+00