Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Support for automatic box_cox transformation while specifying models #322

Closed
raneameya opened this issue Jul 23, 2021 · 2 comments
Closed

Comments

@raneameya
Copy link

While dealing with keyed tsibbles that contain many time series, it is useful to compare the forecast (and distributional) accuracy across model specifications relying on untransformed vs transformed time series.

Consider the example below -

library(tsibble)
library(fable)
m <- list()
m[['Untransformed']] <- tourism %>% # This works
  model(
    E = ETS(Trips), 
    A = ARIMA(Trips), 
    T = THETA(Trips)
  )
m[['Transformed']] <- tourism %>% # Can this be made to work?
  model(
    E = ETS(box_cox(Trips, lambda = 'auto')), 
    A = ARIMA(box_cox(Trips, lambda = 'auto')), 
    T = THETA(box_cox(Trips, lambda = 'auto'))
  )

Can m[['Transformed]] be made to work?

@adgustaf
Copy link

I'd also find this quite useful. Now I have to run a for loop through each series which defeats the utility of the fable(tools) library

@mitchelloharawild
Copy link
Member

Yes, this is now possible since length 1 variables used in the transformation of the response variable are now cached. So you can use feasts::guerrero(resp) to calculate the optimal box-cox transformation parameter.

library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
library(fable)
#> Loading required package: fabletools
library(feasts)

UKLungDeaths <- as_tsibble(cbind(mdeaths, fdeaths))

m <- list()
m[['Untransformed']] <- UKLungDeaths %>% # This works
  model(
    E = ETS(value), 
    A = ARIMA(value), 
    T = THETA(value)
  )
m[['Transformed']] <- UKLungDeaths %>% # Can this be made to work?
  model(
    E = ETS(box_cox(value, lambda = guerrero(value))), 
    A = ARIMA(box_cox(value, lambda = guerrero(value))), 
    T = THETA(box_cox(value, lambda = guerrero(value)))
  )

m
#> $Untransformed
#> # A mable: 2 x 4
#> # Key:     key [2]
#>   key                E                                  A       T
#>   <chr>        <model>                            <model> <model>
#> 1 fdeaths <ETS(M,N,M)>          <ARIMA(0,0,0)(1,1,1)[12]> <THETA>
#> 2 mdeaths <ETS(M,A,A)> <ARIMA(2,0,0)(2,1,0)[12] w/ drift> <THETA>
#> 
#> $Transformed
#> # A mable: 2 x 4
#> # Key:     key [2]
#>   key                E                                  A       T
#>   <chr>        <model>                            <model> <model>
#> 1 fdeaths <ETS(A,N,A)> <ARIMA(0,0,1)(0,1,1)[12] w/ drift> <THETA>
#> 2 mdeaths <ETS(A,N,A)> <ARIMA(0,0,1)(1,1,1)[12] w/ drift> <THETA>

Created on 2024-03-02 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants