impute_last_obs: Impute Incomplete Finite Filters

View source: R/2_finite_filters.R

impute_last_obsR Documentation

Impute Incomplete Finite Filters

Description

Impute Incomplete Finite Filters

Usage

impute_last_obs(x, n, nperiod = 1, backward = TRUE, forward = TRUE)

Arguments

x

a finite_filters() object.

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. nperiod = 1 means imputation using last filtered data (1 period backward), nperiod = 12 with monthly data means imputation using last year filtered data, etc.

backward, forward

boolean indicating if the imputation should be done backward (on left filters), forward (on right filters).

Details

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.

Examples

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

palatej/rjdfilters documentation built on May 8, 2023, 6:28 a.m.