1. Load and extract data for navive and theta method from m3 yearly data
library(forvision)
ts <- m3_yearly_ts
fc <- m3_yearly_fc
af <- createAFTS(ts, fc)
naive_data <- dplyr::filter(af, method_id=="NAIVE2")
theta_data <- dplyr::filter(af, method_id=="THETA")
knitr::kable(head(naive_data))
| Y1 |
MICRO |
5379.75 |
1989 |
NAIVE2 |
4936.99 |
1 |
1988 |
| Y1 |
MICRO |
6158.68 |
1990 |
NAIVE2 |
4936.99 |
2 |
1988 |
| Y1 |
MICRO |
6876.58 |
1991 |
NAIVE2 |
4936.99 |
3 |
1988 |
| Y1 |
MICRO |
7851.91 |
1992 |
NAIVE2 |
4936.99 |
4 |
1988 |
| Y1 |
MICRO |
8407.84 |
1993 |
NAIVE2 |
4936.99 |
5 |
1988 |
| Y1 |
MICRO |
9156.01 |
1994 |
NAIVE2 |
4936.99 |
6 |
1988 |
knitr::kable(head(theta_data))
| Y1 |
MICRO |
5379.75 |
1989 |
THETA |
5414.60 |
1 |
1988 |
| Y1 |
MICRO |
6158.68 |
1990 |
THETA |
5934.47 |
2 |
1988 |
| Y1 |
MICRO |
6876.58 |
1991 |
THETA |
6331.96 |
3 |
1988 |
| Y1 |
MICRO |
7851.91 |
1992 |
THETA |
6822.35 |
4 |
1988 |
| Y1 |
MICRO |
8407.84 |
1993 |
THETA |
7140.76 |
5 |
1988 |
| Y1 |
MICRO |
9156.01 |
1994 |
THETA |
7602.15 |
6 |
1988 |
2. Вычисление ошибки и построение графика
naive_data$error <- naive_data$value - naive_data$forecast
theta_data$error <- theta_data$value - theta_data$forecast
knitr::kable(head(naive_data))
| Y1 |
MICRO |
5379.75 |
1989 |
NAIVE2 |
4936.99 |
1 |
1988 |
442.76 |
| Y1 |
MICRO |
6158.68 |
1990 |
NAIVE2 |
4936.99 |
2 |
1988 |
1221.69 |
| Y1 |
MICRO |
6876.58 |
1991 |
NAIVE2 |
4936.99 |
3 |
1988 |
1939.59 |
| Y1 |
MICRO |
7851.91 |
1992 |
NAIVE2 |
4936.99 |
4 |
1988 |
2914.92 |
| Y1 |
MICRO |
8407.84 |
1993 |
NAIVE2 |
4936.99 |
5 |
1988 |
3470.85 |
| Y1 |
MICRO |
9156.01 |
1994 |
NAIVE2 |
4936.99 |
6 |
1988 |
4219.02 |
knitr::kable(head(theta_data))
| Y1 |
MICRO |
5379.75 |
1989 |
THETA |
5414.60 |
1 |
1988 |
-34.85 |
| Y1 |
MICRO |
6158.68 |
1990 |
THETA |
5934.47 |
2 |
1988 |
224.21 |
| Y1 |
MICRO |
6876.58 |
1991 |
THETA |
6331.96 |
3 |
1988 |
544.62 |
| Y1 |
MICRO |
7851.91 |
1992 |
THETA |
6822.35 |
4 |
1988 |
1029.56 |
| Y1 |
MICRO |
8407.84 |
1993 |
THETA |
7140.76 |
5 |
1988 |
1267.08 |
| Y1 |
MICRO |
9156.01 |
1994 |
THETA |
7602.15 |
6 |
1988 |
1553.86 |
For naive method
library(ggplot2)
graph <- ggplot(naive_data, aes(x = value, y = abs(error))) +
geom_point(colour = "blue", size = 1.5) +
stat_smooth(method = "loess",
col = "#C42126",
size = 1.5)
graph

For theta method
library(ggplot2)
graph <- ggplot(theta_data, aes(x = value, y = abs(error))) +
geom_point(colour = "blue", size = 1.5) +
stat_smooth(method = "loess",
col = "#C42126",
size = 1.5)
graph

for naive and theta methods
data <- rbind(naive_data, theta_data)
library(ggplot2)
graph <- ggplot(data, aes(x = value, y = abs(error), shape = method_id, colour = method_id)) +
geom_point(size = 1.5) +
stat_smooth(method = "loess")
graph
