
Fit seasonal ARIMA to the first 48 quarterly observations and compare forecasts with the next eight. Seasonal differencing removes repeated levels.
Run Rscript --vanilla analysis.R results.csv and quarto render dashboard.qmd. The same synthetic result table can be connected to Superset using the SQL below.
Calculated results
| quarter | actual | forecast | absolute_error |
|---|---|---|---|
| 49 | 149.80 | 144.42 | 5.37630 |
| 50 | 140.85 | 140.30 | 0.55018 |
| 51 | 129.46 | 130.43 | 0.97104 |
| 52 | 141.19 | 137.84 | 3.34320 |
| 53 | 149.54 | 144.57 | 4.96390 |
| 54 | 144.10 | 140.40 | 3.70270 |
| 55 | 133.71 | 130.49 | 3.22210 |
| 56 | 144.34 | 137.88 | 6.45790 |
analysis.R
# Синтетические данные и расчёт метрик для обоих дашбордов.
set.seed(2026)
t <- 1:56
observed <- 100 + 0.8 * t + 9 * sin(2 * pi * t / 4) + rnorm(length(t), 0, 2)
series <- ts(observed[1:48], frequency = 4)
model <- arima(series, order = c(1, 0, 0), seasonal = list(order = c(0, 1, 0), period = 4))
forecast <- as.numeric(predict(model, n.ahead = 8)$pred)
result <- data.frame(quarter = 49:56, actual = observed[49:56], forecast,
absolute_error = abs(observed[49:56] - forecast))
# Проверяет конечность основной метрики перед экспортом.
stopifnot(nrow(result) > 1, all(is.finite(result$absolute_error)))
if (sys.nframe() == 0L) {
arguments <- commandArgs(trailingOnly = TRUE)
stopifnot(length(arguments) == 1L)
write.csv(result, arguments[1], row.names = FALSE)
}
dashboard.qmd
---
title: "Сезонная ARIMA"
lang: ru
format: dashboard
execute:
echo: false
---
```{r}
source("analysis.R", local = TRUE)
```
# Результаты
## Row
### График
```{r}
x <- result$quarter
y <- result$absolute_error
if (is.numeric(x)) {
plot(x, y, xlab = "quarter", ylab = "absolute_error", pch = 19, col = "#245d76")
} else {
par(mar = c(7, 4, 2, 1))
barplot(y, names.arg = x, ylab = "absolute_error", las = 2, col = "#245d76")
}
```
### Таблица
```{r}
knitr::kable(result, digits = 3)
```
## Row
### Как читать результат
Сезонная разность устраняет повторяющийся уровень, AR моделирует лаги ряда. Средняя абсолютная ошибка вычисляется на контрольном интервале.
superset.sql
-- Замените portfolio_results именем таблицы, куда импортирован results.csv.
SELECT quarter, absolute_error
FROM portfolio_results
ORDER BY quarter;