gpt4 book ai didi

r - 来自 ARIMA 模型的寓言 : Extracting the p, d,q 规范

转载 作者:行者123 更新时间:2023-12-03 16:33:04 24 4
gpt4 key购买 nike

我一直在使用 tidy 预测包寓言(它非常有用)。
我想知道是否有一种简单的方法可以从 mable 中提取 p、d、q 值。
以本指南中的数据为例 https://www.mitchelloharawild.com/blog/fable/

library(tidyverse)
library(tsibble)
library(fable)

tourism_state <- tourism %>%
group_by(State) %>%
summarise(Trips = sum(Trips))

fit <- tourism_state %>%
model(arima = ARIMA(Trips))
> fit
# A mable: 8 x 2
# Key: State [8]
State arima
<chr> <model>
1 ACT <ARIMA(0,1,1)>
2 New South Wales <ARIMA(0,1,1)(0,1,1)[4]>
3 Northern Territory <ARIMA(1,0,1)(0,1,1)[4]>
4 Queensland <ARIMA(2,1,2)>
5 South Australia <ARIMA(1,0,1)(0,1,1)[4]>
6 Tasmania <ARIMA(0,0,3)(2,1,0)[4]>
7 Victoria <ARIMA(0,1,1)(0,1,1)[4]>
8 Western Australia <ARIMA(0,1,3)>
我知道规范存储在 model[[1]]$fit$spec 下,但如果我有大量模型,我无法找到提取它们的方法
理想情况下我想要
  State                                 arima       p     d       q
<chr> <model>
1 ACT <ARIMA(0,1,1)> 0 1 1
2 New South Wales <ARIMA(0,1,1)(0,1,1)[4]> 0 1 1
3 Northern Territory <ARIMA(1,0,1)(0,1,1)[4]> 1 0 1
4 Queensland <ARIMA(2,1,2)>
5 South Australia <ARIMA(1,0,1)(0,1,1)[4]> and so on....
6 Tasmania <ARIMA(0,0,3)(2,1,0)[4]>
7 Victoria <ARIMA(0,1,1)(0,1,1)[4]>
8 Western Australia <ARIMA(0,1,3)>
谢谢!

最佳答案

那这个呢?

# specificly needed libraries from tidyverse
library(dplyr)
library(purrr)

fit %>%
mutate(map_dfr(arima, c("fit", "spec")))

#> # A mable: 8 x 10
#> # Key: State [8]
#> State arima p d q P D Q constant period
#> <chr> <model> <int> <int> <int> <int> <int> <int> <lgl> <dbl>
#> 1 ACT <ARIMA(0,1,1)> 0 1 1 0 0 0 FALSE 4
#> 2 New South Wales <ARIMA(0,1,1)(0,1,1)[4]> 0 1 1 0 1 1 FALSE 4
#> 3 Northern Territory <ARIMA(1,0,1)(0,1,1)[4]> 1 0 1 0 1 1 FALSE 4
#> 4 Queensland <ARIMA(2,1,2)> 2 1 2 0 0 0 FALSE 4
#> 5 South Australia <ARIMA(1,0,1)(0,1,1)[4]> 1 0 1 0 1 1 FALSE 4
#> 6 Tasmania <ARIMA(0,0,3)(2,1,0)[4]> 0 0 3 2 1 0 FALSE 4
#> 7 Victoria <ARIMA(0,1,1)(0,1,1)[4]> 0 1 1 0 1 1 FALSE 4
#> 8 Western Australia <ARIMA(0,1,3)> 0 1 3 0 0 0 FALSE 4
它适用于 R >= 4.0dplyr >= 1.0 . arima列是一个列表。我们可以使用 map从列表中提取数据。 map将返回一个列表本身,但带有 map_dfr您可以返回一个数据帧,其中 mutate将解释为一组新的列添加到原始数据帧。
请注意,使用此代码,输出和输入保持相同的类( mable )。

关于r - 来自 ARIMA 模型的寓言 : Extracting the p, d,q 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63392700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com