我正在尝试在我的数据框上使用月度数据拟合 arima 模型,同时具有fable::ARIMA
和forecast::Arima
函数。
这是13个月的数据
suppressMessages( require(dplyr) )
suppressMessages( require(tsibble) )
suppressMessages( require(fable) )
suppressMessages( require(feasts) )
df <- data.frame(v_index = yearmonth( seq(as.Date("2019-01-01"), as.Date("2020-02-01"), by = "month") ),
y = c(44.4, 47.0, 71.2, 43.4, 46.7, 46.4, 61.5, 34.0, 51.5, 59.7, 88.2, 1.8, 75.0, 82.4))
df <- as_tsibble(df, index = v_index)
因为我适合这类 ARIMA 模型
my_mod <- ARIMA(y ~ pdq(p = 0:2, d = 0:1, q = 0:2) +
PDQ(P = 0:2, D = 0:1, Q = 0:1, period = 12))
out <- model(df, mod = my_mod)
print(out$mod)
#> <lst_mdl[1]>
#> [1] <ARIMA(0,1,2)(0,1,0)[12]>
最好的模型有负方差(sigma2 值),我认为这是不可能的结果
glance(out$mod[[1]])
#> # A tibble: 1 x 7
#> sigma2 log_lik AIC AICc BIC ar_roots ma_roots
#> <dbl> <dbl> <dbl> <dbl> <dbl> <list> <list>
#> 1 -23.1 -2.99 12.0 3.98 5.98 <cpl [0]> <cpl [2]>
作为仔细检查,相同的模型forecast::Arima
返回相同的结果:
out2 <- forecast::Arima(ts(df$y, start = c(2019, 1), end = c(2020, 2), frequency = 12),
order = c(0,1,2), seasonal = c(0,1,0))
print(out2$sigma2)
#> [1] -23.05271
这怎么可能?我错过了重点吗?
由reprex 包于 2021-01-28 创建(v1.0.0)
会话信息sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18363)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=Italian_Italy.1252 LC_CTYPE=Italian_Italy.1252
#> [3] LC_MONETARY=Italian_Italy.1252 LC_NUMERIC=C
#> [5] LC_TIME=Italian_Italy.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] feasts_0.1.6 fable_0.2.1 fabletools_0.3.0 tsibble_0.9.3
#> [5] dplyr_1.0.2
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.5 urca_1.3-0 progressr_0.7.0
#> [4] pillar_1.4.6 compiler_4.0.2 highr_0.8
#> [7] tools_4.0.2 digest_0.6.25 lattice_0.20-41
#> [10] nlme_3.1-148 lubridate_1.7.9 evaluate_0.14
#> [13] lifecycle_0.2.0 tibble_3.0.3 gtable_0.3.0
#> [16] anytime_0.3.9 pkgconfig_2.0.3 rlang_0.4.7
#> [19] reprex_1.0.0 cli_2.0.2 rstudioapi_0.11
#> [22] yaml_2.2.1 xfun_0.15 stringr_1.4.0
#> [25] knitr_1.29 generics_0.0.2 fs_1.4.2
#> [28] vctrs_0.3.2 grid_4.0.2 tidyselect_1.1.0
#> [31] glue_1.4.1 R6_2.4.1 fansi_0.4.1
#> [34] distributional_0.2.1 rmarkdown_2.3 tidyr_1.1.0
#> [37] purrr_0.3.4 farver_2.0.3 ggplot2_3.3.2
#> [40] magrittr_1.5 scales_1.1.1 ellipsis_0.3.1
#> [43] htmltools_0.5.0 assertthat_0.2.1 colorspace_1.4-1
#> [46] utf8_1.1.4 stringi_1.4.6 munsell_0.5.0
#> [49] crayon_1.3.4