Remove outliers keeping other relevant variables in the model

I was trying to remove outliers from my model according described in this session: 13.9 Dealing with outliers and missing values | Forecasting: Principles and Practice (3rd ed), however i want to keep other relevant variables to fit in my model, when i do this procedure, I lost my "value2".

Here some dummy data ilustrating:

library(fpp3)

serie <- tibble(data = seq(as.Date("1949-01-01"), length = 24, by = "month"),
value1 = sample(1:24),
value2 = sample(1:24)) %>%
as_tsibble() %>%
fill_gaps(.full = TRUE)

serie <- serie %>%
mutate(value1 = na_if(value1, 0.0)) %>%
mutate(value2 = na_if(value2, 0.0)) %>%
na_interpolation()

decomp <- serie %>%
model(
stl = STL(value1, robust = TRUE)) %>%
components()

outliers <- decomp %>%
filter(
remainder < quantile(remainder, 0.25) - 3IQR(remainder) |
remainder > quantile(remainder, 0.75) + 3
IQR(remainder)
)

miss <- serie %>%
anti_join(outliers) %>%
fill_gaps()

serie_fill <- miss %>%
model(ARIMA(value1)) %>%
interpolate(miss)

If someone could help will be appreciated

Lucas

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.