tidyverts / fable

Tidy time series forecasting
https://fable.tidyverts.org
GNU General Public License v3.0
564 stars 66 forks source link

Non-normally distributed innovations? #380

Open cryptoguy4561 opened 1 year ago

cryptoguy4561 commented 1 year ago

Wondering if we can specify any non-normally distributed innovation/noise terms. Specifically want to use a t distribution. If not, is there a Python or R package that allows it?

mitchelloharawild commented 1 year ago

You can provide innovations of any shape to the generate() function via the .innov column of new_data. https://fabletools.tidyverts.org/reference/generate.mdl_df.html#details

For example,

library(fable)
#> Loading required package: fabletools
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
uad <- as_tsibble(USAccDeaths)

fit <- uad %>% 
  model(ETS(value))

innovations <- mutate(new_data(uad, n = 12), .innov = rt(12, 1))

fit %>% 
  generate(new_data = innovations)
#> # A tsibble: 12 x 5 [1M]
#> # Key:       .model, .rep [1]
#>    .model     .rep     index    .innov   .sim
#>    <chr>      <chr>    <mth>     <dbl>  <dbl>
#>  1 ETS(value) 1     1979 Jan   -8.47    8389.
#>  2 ETS(value) 1     1979 Feb -125.      7469.
#>  3 ETS(value) 1     1979 Mar   -0.210   8317.
#>  4 ETS(value) 1     1979 Apr   -0.253   8567.
#>  5 ETS(value) 1     1979 May   -0.744   9363.
#>  6 ETS(value) 1     1979 Jun    1.15    9814.
#>  7 ETS(value) 1     1979 Jul   -3.07   10737.
#>  8 ETS(value) 1     1979 Aug    0.0219 10026.
#>  9 ETS(value) 1     1979 Sep    0.139   8934.
#> 10 ETS(value) 1     1979 Oct   -0.545   9273.
#> 11 ETS(value) 1     1979 Nov   -0.596   8798.
#> 12 ETS(value) 1     1979 Dec    0.142   9004.

Created on 2022-12-02 by the reprex package (v2.0.1)

You can also provide a .rep column to new_data to identify the replicate, allowing multiple paths to be produced from the desired innovations.