我一直在閱讀這本書并嘗試使用一些相同的代碼,這些代碼要求您將資料存盤為tsibble。然而,當我嘗試在我自己的資料上使用第 3 章中的特定代碼時,我無法讓它作業。
首先我加載自己的資料,然后將其存盤在 tsibble 中并嘗試將其轉換為 tsibble(我不知道這是否是最佳方式),但似乎在此程序中的某個時刻,我不不澄清季度日期是正確的。
#The packages i have
library(seasonal)
library(tsibble)
library(feasts)
library(ggplot2)
library(fpp3)
library(dplyr)
library(lubridate)
#My data x=values and y=dates
x <- c(-4.2,3.1,-1.3,6.3,-6.5,2.6,-0.7,5.1,-6.5,4.2,-2.1,4.6,
-5.2,1.8,-1.3,6.8,-5.3,3.6,-1.6,5.9,-6.7,6.9,-2.6,5,
-4.4,6.2,-2.4,4.1,-5.2,2.6,-0.5,5.1,-6.1,3.5,-2.5,1.5,
-6.6,0.7,-0.7,3.8,-4.6,3.9,0.2,3.5,-4.8,3.6,-2.2,4.4,
-4.9,2.6,-1,3.4,-5,4.3,-1.2,3.5,-4.6,3,0.3,3.7,-4.2,
3.9,-1.3,3.5,-4.1,5.9,-1.6,4.1,-4.1,4.8,-2.5,4.4,-4.8,
5.1,-2.1,4.4,-4.4,4.4,-2,3.9,-5.7,-2.8,3.4,4.9,-5.5,7.3)
y <- c("2000 Q1", "2000 Q2", "2000 Q3", "2000 Q4", "2001 Q1", "2001 Q2",
"2001 Q3", "2001 Q4", "2002 Q1", "2002 Q2", "2002 Q3", "2002 Q4", "2003 Q1",
"2003 Q2", "2003 Q3", "2003 Q4", "2004 Q1", "2004 Q2", "2004 Q3", "2004 Q4",
"2005 Q1", "2005 Q2", "2005 Q3", "2005 Q4", "2006 Q1", "2006 Q2", "2006 Q3",
"2006 Q4", "2007 Q1", "2007 Q2", "2007 Q3", "2007 Q4", "2008 Q1", "2008 Q2",
"2008 Q3", "2008 Q4", "2009 Q1", "2009 Q2", "2009 Q3", "2009 Q4", "2010 Q1",
"2010 Q2", "2010 Q3", "2010 Q4", "2011 Q1", "2011 Q2", "2011 Q3", "2011 Q4",
"2012 Q1", "2012 Q2", "2012 Q3", "2012 Q4", "2013 Q1", "2013 Q2", "2013 Q3",
"2013 Q4", "2014 Q1", "2014 Q2", "2014 Q3", "2014 Q4", "2015 Q1", "2015 Q2",
"2015 Q3", "2015 Q4", "2016 Q1", "2016 Q2", "2016 Q3", "2016 Q4", "2017 Q1",
"2017 Q2", "2017 Q3", "2017 Q4", "2018 Q1", "2018 Q2", "2018 Q3", "2018 Q4",
"2019 Q1", "2019 Q2", "2019 Q3", "2019 Q4", "2020 Q1", "2020 Q2", "2020 Q3",
"2020 Q4", "2021 Q1", "2021 Q2")
#Convert to a tibble (i couldn't get the dates to work, so i created a sequence)
GDP <- tibble(
GDPNumbers = x,
Quarter = seq(as.Date("2000-01-01"), as.Date("2021-05-05"), by = "1 quarter")
)
#Convert to a tsibble
GDP_tsbl <- as_tsibble(GDP,
key = GDPNumbers,
index = Quarter)
# Then i want to use two codes, which doesn't work for me
x11_dcmp <- GDP_tsbl %>%
model(x11 = X_13ARIMA_SEATS(x ~ x11())) %>%
components()
autoplot(x11_dcmp)
labs(tittle =
"Decomposition using X-11.")
當我到達最后兩個代碼時,我收到錯誤訊息。顯然最后一個給出了錯誤訊息,因為以前的不起作用。
Error: Problem with `mutate()` input `cmp`.
x no applicable method for 'components' applied to an object of class "null_mdl"
i Input `cmp` is `map(.fit, components)`.
Run `rlang::last_error()` to see where the error occurred.
In addition: Advarselsbesked:
57 errors (4 unique) encountered for x11
[6] .data contains implicit gaps in time. You should check your data and convert implicit gaps into explicit missing values using `tsibble::fill_gaps()` if required.
[15] Internal error in `df_slice()`: Columns must match the data frame size.
[11] X-13 run failed
Errors:
- 1. Check input file and format.
- Time series could not be read due to previously found errors
- Specify series before user-defined adjustments
- Need to specify a series to identify outliers
Notes:
- Correct input errors in the order they are detected since the first one or two may be
responsible for the others (especially if there are errors in the SERIES or COMPOSITE
spec).
[25] X-13 run failed
Errors:
- Seasonal period must be 4 or 12 if a seasonal adjustment is done.
Notes:
- Correct input errors in the order they are detected since the first one or two may be
responsible for the others (especially if there are errors in the SERIES or COMPOSITE
spec).
據我所知,R 認為資料存在差距。我認為這是由于日期的原因,我環顧了互聯網,包括 stackoverflow,但我還沒有找到任何有效的解決方案。在一個站點上,有人建議使用,fill_gaps(.full = TRUE)但這最終在我的資料中插入了大約 440000 個元素,這看起來很奇怪,因為我只有 86 個觀察值。
任何幫助,將不勝感激。
uj5u.com熱心網友回復:
您需要更改代碼中的一些內容。
- 創建索引時洗掉鍵。您想預測 GDP 數字。它們不是關鍵值。鍵將被自動選擇,或者如果您想指定它,它需要唯一確定時間索引。
所以對于 1 你:
GDP_tsbl <- as_tsibble(GDP,
index = Quarter)
正確設定季度。您需要使用函式設定季度
yearquarter。x11_dcmp <- GDP_tsbl %>% mutate(Quarter = yearquarter(Quarter)) %>% model(x11 = X_13ARIMA_SEATS(GDPNumbers ~ x11())) %>% components()
這些更改將確保您的自動繪圖按預期作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/354550.html
