此错误消息不提供信息且具有误导性。这已在https://github.com/tidyverts/fable/commit/4b9ae292f940c6e99b05a62cf3e76519fcac67b0中得到修复(上游原因已在 https://github.com/tidyverts/fabletools/commit/4f7738bcb9b1c2b482937abd50c7e63fb80d4c55 中修复)。
问题是由于您构建了 tsibble。通过用 Date 类表示 tsibble 的索引,数据的时间粒度为 1 天。但是每隔几年就会观察一次选举,因此索引应该存储为整数或数字。检查这一点的一个好方法是查看 tsibble 的间隔(在表格输出的顶部):
library(tsibble)
library(lubridate)
pvidata<-readr::read_csv("https://www.dropbox.com/s/xmr4m3d4ksngurs/PVI%20Data%20arranged%20cols-dates.csv?dl=1",col_names = TRUE)
pvidata$Date<-as.Date(mdy(pvidata$Date))
pvidata<-as_tsibble(pvidata,index=Date)
pvidata<- tidyr::pivot_longer(pvidata,-Date, names_to = "State",values_to="PVI")
pvidata
#> # A tsibble: 750 x 3 [1461D]
#> # Key: State [50]
#> Date State PVI
#> <date> <chr> <dbl>
#> 1 1962-01-01 Alabama 0.12
#> 2 1962-01-01 Alaska 0.03
#> 3 1962-01-01 Arizona -0.04
#> 4 1962-01-01 Arkansas 0.07
#> 5 1962-01-01 California 0.01
#> 6 1962-01-01 Colorado -0.04
#> 7 1962-01-01 Connecticut -0.01
#> 8 1962-01-01 Delaware 0.02
#> 9 1962-01-01 Florida 0.16
#> 10 1962-01-01 Georgia 0.17
#> # … with 740 more rows
由reprex 包(v0.3.0)于 2020-06-12 创建
是自动识别的[1461D]
数据区间,应该是[4Y]
。将日期设置为整数可解决此问题:
library(tsibble)
library(lubridate)
pvidata<-readr::read_csv("https://www.dropbox.com/s/xmr4m3d4ksngurs/PVI%20Data%20arranged%20cols-dates.csv?dl=1",col_names = TRUE)
pvidata$Date<-year(mdy(pvidata$Date))
pvidata<-as_tsibble(pvidata,index=Date)
pvidata<- tidyr::pivot_longer(pvidata,-Date, names_to = "State",values_to="PVI")
pvidata
#> # A tsibble: 750 x 3 [4Y]
#> # Key: State [50]
#> Date State PVI
#> <dbl> <chr> <dbl>
#> 1 1962 Alabama 0.12
#> 2 1962 Alaska 0.03
#> 3 1962 Arizona -0.04
#> 4 1962 Arkansas 0.07
#> 5 1962 California 0.01
#> 6 1962 Colorado -0.04
#> 7 1962 Connecticut -0.01
#> 8 1962 Delaware 0.02
#> 9 1962 Florida 0.16
#> 10 1962 Georgia 0.17
#> # … with 740 more rows
由reprex 包(v0.3.0)于 2020-06-12 创建
使用更正的数据,模型运行没有问题:
library(fable)
#> Loading required package: fabletools
pvidata %>% model(ets = ETS(PVI),arima = ARIMA(PVI))
#> # A mable: 50 x 3
#> # Key: State [50]
#> State ets arima
#> <chr> <model> <model>
#> 1 Alabama <ETS(A,N,N)> <ARIMA(0,1,0)>
#> 2 Alaska <ETS(A,N,N)> <ARIMA(1,0,0)>
#> 3 Arizona <ETS(A,N,N)> <ARIMA(0,0,2) w/ mean>
#> 4 Arkansas <ETS(A,N,N)> <ARIMA(1,0,1)>
#> 5 California <ETS(A,N,N)> <ARIMA(0,1,0) w/ drift>
#> 6 Colorado <ETS(A,N,N)> <ARIMA(0,0,2)>
#> 7 Connecticut <ETS(A,N,N)> <ARIMA(1,1,0)>
#> 8 Delaware <ETS(A,N,N)> <ARIMA(0,1,1)>
#> 9 Florida <ETS(A,N,N)> <ARIMA(1,0,0)>
#> 10 Georgia <ETS(A,N,N)> <ARIMA(0,0,1)>
#> # … with 40 more rows
由reprex 包(v0.3.0)于 2020-06-12 创建
有关更多详细信息,您可以参考https://otexts.com/fpp3/tsibble-objects.html和https://pkg.earo.me/tsibble/articles/faq.html