How to address NA Values when using lead values from the predictor variable in the ARIMAX model in R

Data info-
I have a weekly dataset with "Replenishment" being the dependent variable and "ADJUSTEDSALESUNITS" being the Independent variable. I'm trying to use the lead values from the Independent variable as a co-variate to fit the model in order to predict the dependent variable.

The reason I went with lead is positive lag values(2Week and 1Week lead values) of independent variable from the ccf function has a better correlation with the dependent variable.

I have included only 13 weeks of data here as the Original data set contain 156 weeks.

Query-
My concern is the model I tried to fit considering the lead values of ind. variable as covariate is leaving NAs at the last weeks on the dependent variable(based on the leads specified).

Even the forecast output using the forecast function is generating N/As at the last weeks

Is there a way to address these N/As on the output of Dependent variable when using lag/lead predictors on the forecast model.

library(tidyverse)
library(tibbletime)
library(lubridate)
library(tibble)
library(norm)
library(tsibble)
library(fpp3)
library(ISOweek)

Df <- structure(list(`Ship-To.Party` = c("C200", "C200", "C200", "C200", 
                                         "C200", "C200", "C200", "C200", "C200", "C200", "C200", "C200", 
                                         "C200", "A442", "A442", "A442", "A442", "A442", "A442", "A442", 
                                         "A442", "A442", "A442", "A442", "A442", "A442"), Replenishment = c(92, 
                                                                                                            206, 112, 82, 60, 168, 168, 70, 126, 114, 148, 44, 108, 29, 82, 
                                                                                                            33, 52, 103, 62, 82, 59, 38, 96, 58, 112, 127), ADJUSTEDSALESUNITS = c(28.953193, 
                                                                                                                                                                                   48.953204, 44.953199, 42.953197, 58.953203, 38.012019, 69.012008, 
                                                                                                                                                                                   46.012003, 91.326704, 37.326699, 69.326687, 59.326571, 158.326551, 
                                                                                                                                                                                   1.859804, 40.8598, 58.859792, 64.859794, 17.859795, 88.150199, 
                                                                                                                                                                                   74.150197, 76.15019, 29.138793, 41.138794, 84.138788, 76.138778, 
                                                                                                                                                                                   81.138793), Week = c("201901", "201902", "201903", "201904", 
                                                                                                                                                                                                        "201905", "201906", "201907", "201908", "201909", "201910", "201911", 
                                                                                                                                                                                                        "201912", "201913", "201901", "201902", "201903", "201904", "201905", 
                                                                                                                                                                                                        "201906", "201907", "201908", "201909", "201910", "201911", "201912", 
                                                                                                                                                                                                        "201913")), row.names = c(NA, 26L), class = "data.frame")
#Converting to week format
Df<- Df <- Df %>%
  mutate(
    isoweek =stringr::str_replace(Week, "^(\\d{4})(\\d{2})$", "\\1-W\\2-1"),
    date = ISOweek::ISOweek2date(isoweek)
  )

Df <- Df %>% 
  mutate(Week.1 = yearweek(ISOweek::ISOweek(date))) %>% 
  group_by(`Ship-To.Party`,Week.1) %>%
  dplyr::select(-Week,-date,-isoweek) %>%
  as_tsibble(key = `Ship-To.Party`,index = Week.1)

#Model fitting
fit.1 <- Df %>% filter(`Ship-To.Party`== "C200") %>% as_tsibble() %>%
  model(ARIMA(Replenishment ~lead(ADJUSTEDSALESUNITS,2)))

fit.2 <- Df %>% filter(`Ship-To.Party`== "A442") %>% as_tsibble() %>%
  model(ARIMA(Replenishment ~lead(ADJUSTEDSALESUNITS,1)))

fitted.Df.1<- fitted(fit.1)
fitted.Df.1

fitted.Df.2<- fitted(fit.2)
fitted.Df.2

Df.future<- new_data(Df,5) %>% 
              mutate(ADJUSTEDSALESUNITS = 12) %>% 
  group_by(`Ship-To.Party`,Week.1) %>%
  as_tsibble(key = `Ship-To.Party`, index = Week.1)

forecast.1<- fit.1 %>% forecast(Df.future)

forecast.1

As you see from the Fitted output and the forecast output- the last week's values are NA as lead predictors have no values

Could you please let me know how to handle N/A's generating on the models for dependent variable

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.