r - 无法正确执行 stl 分解
问题描述
从这个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
有人可以解释一下我所犯的错误吗?
此致
解决方案
您显示的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 包于 2021-11-01 创建(v2.0.1)
tourism
也许您正在使用分组版本覆盖对象。或者您可能正在使用旧版本的tsibble
包,其中未使用summarise()
.
无论如何,如果没有可重现的例子,就很难提供更多实质性的帮助。
推荐阅读
- ruby-on-rails - 如何防止 Paper Trail 在触摸时进行版本控制?
- javascript - 打字稿:检查子类的静态属性?
- python - 如何在pygame中添加检测碰撞
- amazon-web-services - Is creating an Organization disruptive to an existing production environment
- c++ - 我如何将枚举更改为字符?我正在尝试投射它,但它给了我一个错误
- java - 具有多个升序值列表的数值排序
- r - R删除数据框中的公共列
- python - AttributeError:“索引”对象没有属性“天”Python
- javascript - 我将如何“刷新”嵌入 discord.js 的不和谐?更多信息下来 vv
- linux - 将大量页面的office文档拆分为多个文件