【问题标题】:Not being able to execute stl decomposition properly无法正确执行 stl 分解
【发布时间】:2024-01-20 04:06:01
【问题描述】:

从这个ts:

australia_data <- tourism %>%
  select(Quarter, Trips) %>%
  summarise(TotalTrips = sum(Trips))

> head(australia_data)
# A tsibble: 6 x 4 [1D]
# Key:       Region, Purpose [1]
# Groups:    Region [1]
  Region   Purpose  Quarter    TotalTrips
  <chr>    <chr>    <date>          <dbl>
1 Adelaide Business 1998-01-01       135.
2 Adelaide Business 1998-04-01       110.
3 Adelaide Business 1998-07-01       166.
4 Adelaide Business 1998-10-01       127.
5 Adelaide Business 1999-01-01       137.
6 Adelaide Business 1999-04-01       200.

我想做一个 STL 分解,以获得季节性调整的数据:

australia_data_dcmp <- australia_data %>%
  model(STL(TotalTrips)) 

但我无法获取组件

> components(australia_data_dcmp)
Error: Problem with `mutate()` column `cmp`.
i `cmp = map(.fit, components)`.
x no applicable method for 'components' applied to an object of class "null_mdl"


> head(augment(australia_data_dcmp))
# A tsibble: 6 x 8 [1D]
# Key:       Region, Purpose, .model [1]
  Region   Purpose  .model          Quarter    TotalTrips .fitted .resid .innov
  <chr>    <chr>    <chr>           <date>          <dbl>   <dbl>  <dbl>  <dbl>
1 Adelaide Business STL(TotalTrips) 1998-01-01       135.      NA     NA     NA
2 Adelaide Business STL(TotalTrips) 1998-04-01       110.      NA     NA     NA
3 Adelaide Business STL(TotalTrips) 1998-07-01       166.      NA     NA     NA
4 Adelaide Business STL(TotalTrips) 1998-10-01       127.      NA     NA     NA
5 Adelaide Business STL(TotalTrips) 1999-01-01       137.      NA     NA     NA
6 Adelaide Business STL(TotalTrips) 1999-04-01       200.      NA     NA     NA

谁能解释一下我所犯的错误?

最好的问候

【问题讨论】:

  • 似乎无法重现您的问题。它在我这边工作得很好。你是加载 fpp3 包还是只加载 fable 和 fabletools?
  • fpp3,类似情况已经不是第一次了
  • 已经卸载并重新安装了软件包,情况仍然存在@phiver
  • 同样的情况持续存在
  • 重启并尝试:library(fable) library(feasts) library(dplyr) data("tourism", package = "tsibble") 然后你的代码。如果这不起作用,请在没有 Rstudio 的情况下启动 R 并尝试此操作。

标签: r stl time-series decomposition


【解决方案1】:

您显示的tourism 对象不是您在使用fpp3 加载的各种包的最新版本时获得的。这就是我得到的。

library(fpp3)
#> ── Attaching packages ──────────────────────────────────────────── fpp3 0.4.0 ──
#> ✓ tibble      3.1.5     ✓ tsibble     1.1.0
#> ✓ dplyr       1.0.7     ✓ tsibbledata 0.3.0
#> ✓ tidyr       1.1.4     ✓ feasts      0.2.2
#> ✓ lubridate   1.8.0     ✓ fable       0.3.1
#> ✓ ggplot2     3.3.5
#> ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
#> x lubridate::date()    masks base::date()
#> x dplyr::filter()      masks stats::filter()
#> x tsibble::intersect() masks base::intersect()
#> x tsibble::interval()  masks lubridate::interval()
#> x dplyr::lag()         masks stats::lag()
#> x tsibble::setdiff()   masks base::setdiff()
#> x tsibble::union()     masks base::union()
australia_data <- tourism %>%
  select(Quarter, Trips) %>%
  summarise(TotalTrips = sum(Trips))
australia_data
#> # A tsibble: 80 x 2 [1Q]
#>    Quarter TotalTrips
#>      <qtr>      <dbl>
#>  1 1998 Q1     23182.
#>  2 1998 Q2     20323.
#>  3 1998 Q3     19827.
#>  4 1998 Q4     20830.
#>  5 1999 Q1     22087.
#>  6 1999 Q2     21458.
#>  7 1999 Q3     19914.
#>  8 1999 Q4     20028.
#>  9 2000 Q1     22339.
#> 10 2000 Q2     19941.
#> # … with 70 more rows

reprex package 创建于 2021-11-01 (v2.0.1)

也许您正在使用分组版本覆盖tourism 对象。或者您可能正在使用旧版本的 tsibble 软件包,其中未使用 summarise() 删除密钥。

无论如何,如果没有可重复的示例,就很难提供更多实质性帮助。

【讨论】: