View source: R/2_finite_filters.R
impute_last_obs | R Documentation |
Impute Incomplete Finite Filters
impute_last_obs(x, n, nperiod = 1, backward = TRUE, forward = TRUE)
x |
a |
n |
integer specifying the number of imputed periods. By default all the missing moving averages are imputed. |
nperiod |
integer specifying how to imput missing date.
|
backward, forward |
boolean indicating if the imputation should be done backward (on left filters), forward (on right filters). |
When combining finite filters and a moving average, the first and/or the last points cannot be computed.
For example, using the M2X12 moving average (symmetric moving average with coefficients \theta = \begin{pmatrix} 1/24 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/24 \end{pmatrix}
), the first and last 6 points cannot be computed.
impute_last_obs()
allows to impute the first/last points using the nperiod
previous filtered data. With nperiod = 1
, the last filtered data is used for the imputation, with nperiod = 12
and monthly data, the last year filtered data is used for the imputation, etc.
y <- window(retailsa$AllOtherGenMerchandiseStores, start = 2008)
M3X3 <- macurves("S3X3")
M2X12 <- (simple_ma(12, -6) + simple_ma(12, -5)) / 2
composite_ma <- M3X3 * M2X12
# The last 6 points cannot be computed
composite_ma
composite_ma * y
# they can be computed using the last filtered data
# e.g. to impute the first 3 missing months with last period:
impute_last_obs(composite_ma, n = 3, nperiod = 1) * y
# or using the filtered data of the same month in previous year
impute_last_obs(composite_ma, n = 6, nperiod = 12) * y
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.