Description Usage Details Value Examples
View source: R/ts_preprocess.R
Can be used to flexibly transforming and backtransforming data. Generally all functions - including custom ones in the current environment are supported.
The function assumes that each transformation funcotion (e.g. normalize <- function (x, ...) {}
) has a backtransformation function with the same name
but a inv_
prefix (e.g. inv_normalize <- function(x, param, ...){}
). All parameter used for transforming the variables can be stored in the
param variable; which will be passed automatically back to the backtransformation function.
1 |
The preprocessor has to "instantiated" and can then be called using the following parameters:
"y"time series or forecast to be transformed/backtransformed
"action"action to be taked, either 'transform' or 'backtransform'
"operations"transformatoin operations to be takes (functions to be called)
"n.diffs"integer default (NA). Sets the number of differencing to be taken (used only when diff is part of operator)
"auto"boolean, default (T), whether the number of differencing is to be determined automatically
"is_fcs"boolean ,default (T), wheter it is forecast or in-sample data to be transformed
"frequency"inteher, default (NA), the frequency of the time series (used for seasonal adjustment)
"h"horizon, default (1)
returns either transformed or backtransformed time series vector
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # not run
# load demo data
library(Mcomp)
# get demo time series
demo_ts <- M3[[1560]]$x
# show demo ts
demo_ts
# get preprocessor "object" (environment)
pp <- preprocessor()
# preprocess time series
y_pp <- pp(y = demo_ts,
action = 'transform',
operations = c('seasonal_adjustment', 'scale'),
frequency = frequency(demo_ts))
# show preprocessed time series
y_pp
# ok, now go back to the roots
y_back <- pp(y = y_pp, action = 'backtransform', is_fcs = F)
y_back - demo_ts
# end not run
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.