user9085964
user9085964

Reputation: 49

Not being able to execute stl decomposition properly

from this 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.

I want to do a STL decomposition, in order to get seasonally adjusted data :

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

but I'm not being able to get components

> 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

can someone explain me the mistake I'm commiting please ?

Best regards

Upvotes: 0

Views: 362

Answers (1)

Rob Hyndman
Rob Hyndman

Reputation: 31810

The tourism object you show is not what you get when using the latest versions of the various packages loaded by fpp3. This is what I get.

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

Created on 2021-11-01 by the reprex package (v2.0.1)

Perhaps you are over-writing the tourism object with a grouped version. Or perhaps you are using an old version of the tsibble package where the keys were not dropped using summarise().

In any case, without a reproducible example it is hard to provide more substantial help.

Upvotes: 0

Related Questions