I am working on a project where I have implemented the ARDL model and was hoping to see the past values on the regression line in black and the forecasted values generated by the model on the same line in blue but getting the error: Error in is.constant(y): 'list' object cannot be coerced to type 'double'
. I am attaching a sample of the data, any assistance will be highly appreciated.
Data Sample:
structure(list(Row = c("2021-01-01", "2021-01-02", "2021-01-03",
"2021-01-04", "2021-01-05", "2021-01-06", "2021-01-07", "2021-01-08",
"2021-01-09", "2021-01-10", "2021-01-11", "2021-01-12", "2021-01-13",
"2021-01-14", "2021-01-15", "2021-01-16", "2021-01-17", "2021-01-18",
"2021-01-19", "2021-01-20", "2021-01-21", "2021-01-22", "2021-01-23",
"2021-01-24", "2021-01-25", "2021-01-26", "2021-01-27", "2021-01-28",
"2021-01-29", "2021-01-30"), Date = structure(c(18628, 18629,
18630, 18631, 18632, 18633, 18634, 18635, 18636, 18637, 18638,
18639, 18640, 18641, 18642, 18643, 18644, 18645, 18646, 18647,
18648, 18649, 18650, 18651, 18652, 18653, 18654, 18655, 18656,
18657), class = "Date"), Inflation = c(136, 136.3, 136.4, 136.5,
136.6, 136.8, 136.9, 137, 137.2, 137.3, 137.4, 137.5, 137.7,
137.8, 137.9, 138.1, 138.2, 138.3, 138.5, 138.6, 138.7, 138.8,
139, 139.1, 139.2, 139.4, 139.5, 139.6, 139.7, 139.9), ATOM_Complete = c(0,
-0.453943, 0.399285, 0.182872, 0.220046, 0.463671000000001, -0.405467000000001,
-0.323575, 0.587951, -0.109354, -0.708655, -0.0216700000000003,
0.522982000000001, 0.216621999999999, 1.499416, 1.090329, -0.522449,
0.987390999999999, -0.516599999999999, -0.0742460000000005, -1.749442,
0.859947, 0.297435999999999, -0.0705479999999987, -0.481712000000001,
-0.0388529999999996, -0.731108, 1.140646, -0.146628000000001,
0.0664419999999994)), row.names = c(NA, -30L), class = c("data.table",
"data.frame"), .internal.selfref = <pointer: 0x000002b44e2ee710>)
ardl_model1 <- dLagM::ardlDlm(ATOM_Complete ~ Inflation, data = data_1, p = 3, q = 5)
Code:
Model1_fcst_7_days <- dLagM::forecast(ardl_model1, x = data_1$Inflation, h = 7)
model1_fccst7 <- Model1_fcst_7_days$forecasts
model1_fccst7
# Predict actual and forecasted values
actual_values <- data_1$ATOM_Complete
forecasted_values <- predict(ardl_model1, newdata = data_1)
# Combine actual and forecasted values
all_values <- c(actual_values, forecasted_values)
# Create a date sequence for the x-axis
dates <- seq(as.Date("2023-01-17"), by = "day", length.out = length(all_values))
# Plot the actual and forecasted values with regression line
plot(dates, all_values, type = "l", col = "black", xlab = "Date", ylab = "ATOM_Complete")
lines(dates[-(1:length(actual_values))], forecasted_values, col = "blue")