由于future
用于参数new_data
in的数据集forecast()
太短,因此返回警告。为了摆脱警告并考虑到P = 1
,可以扩展未来的数据集。附有可重现的示例。
library(lubridate)
#>
#> Attache Paket: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library(tidyverse)
library(tsibble)
#>
#> Attache Paket: 'tsibble'
#> The following object is masked from 'package:lubridate':
#>
#> interval
library(fable)
#> Lade nötiges Paket: fabletools
#
past <- tibble(yyyy_mm = seq(as.Date("1900-01-01"),as.Date("2020-05-01"),"month"),
avg_d = runif(1445,1000000,2500000)) %>%
mutate(yyyy_mm = yearmonth(yyyy_mm)) %>%
as_tsibble()
#> Using `yyyy_mm` as index variable.
future <- tibble(yyyy_mm = seq(as.Date("2020-06-01"),as.Date("2020-12-01"),"month")) %>%
mutate(yyyy_mm = yearmonth(yyyy_mm)) %>%
as_tsibble()
#> Using `yyyy_mm` as index variable.
fit <- past %>% model(nnar = NNETAR(avg_d ~ AR(p=2,P=1,period=12)))
forecast(fit,future)
#> Warning: Series too short for seasonal lags
#> # A fable: 7 x 4 [1M]
#> # Key: .model [1]
#> .model yyyy_mm avg_d .mean
#> <chr> <mth> <dist> <dbl>
#> 1 nnar 2020 Jun sample[1000] 1758676.
#> 2 nnar 2020 Jul sample[1000] 1743311.
#> 3 nnar 2020 Aug sample[1000] 1766885.
#> 4 nnar 2020 Sep sample[1000] 1764609.
#> 5 nnar 2020 Okt sample[1000] 1744808.
#> 6 nnar 2020 Nov sample[1000] 1715543.
#> 7 nnar 2020 Dez sample[1000] 1738346.
# reason for the warning message:
# inside forecast.NNETAR specials_nnetar() is called:
P <- 1
period <- 12
# taken from specials_nnetar():
if (P > 0 && NROW(future) < period * P + 2) {
rlang::warn("Series too short for seasonal lags")
P <- 0
}
#> Warning: Series too short for seasonal lags
# extend future; NROW(future) must be equal to period * P + 2 = 14:
future2 <- tibble(yyyy_mm = seq(as.Date("2020-06-01"),as.Date("2021-07-01"),"month")) %>%
mutate(yyyy_mm = yearmonth(yyyy_mm)) %>%
as_tsibble()
#> Using `yyyy_mm` as index variable.
P <- 1
period <- 12
# taken from specials_nnetar():
if (P > 0 && NROW(future2) < period * P + 2) {
rlang::warn("Series too short for seasonal lags")
P <- 0
}
forecast(fit,future2)
#> # A fable: 14 x 4 [1M]
#> # Key: .model [1]
#> .model yyyy_mm avg_d .mean
#> <chr> <mth> <dist> <dbl>
#> 1 nnar 2020 Jun sample[1000] 1726252.
#> 2 nnar 2020 Jul sample[1000] 1733855.
#> 3 nnar 2020 Aug sample[1000] 1750326.
#> 4 nnar 2020 Sep sample[1000] 1752966.
#> 5 nnar 2020 Okt sample[1000] 1759741.
#> 6 nnar 2020 Nov sample[1000] 1729142.
#> 7 nnar 2020 Dez sample[1000] 1746633.
#> 8 nnar 2021 Jan sample[1000] 1756297.
#> 9 nnar 2021 Feb sample[1000] 1738609.
#> 10 nnar 2021 Mrz sample[1000] 1748182.
#> 11 nnar 2021 Apr sample[1000] 1719133.
#> 12 nnar 2021 Mai sample[1000] 1718844.
#> 13 nnar 2021 Jun sample[1000] 1745875.
#> 14 nnar 2021 Jul sample[1000] 1730472.
由reprex 包于 2020-07-01 创建(v0.3.0)