tidyverts / fasster

Forecasting with Additive Switching of Seasonality, Trend and Exogenous Regressors
https://fasster.tidyverts.org/
150 stars 15 forks source link

Dynamically specifying the formula says 'No supported inverse for this function' #28

Closed ashraaghav closed 6 years ago

ashraaghav commented 6 years ago

Hi, Great work on the package by the way.

I want to generate my formula dynamically from a list of variable names. So I tried to paste them into a string and convert that into a formula. However, this is throwing an error saying "No supported inverse for this function"

Example:

# Preparing the data
airquality %>% mutate(
    date = as.Date(paste('2018', Month, Day, sep = '-')), 
    Ozone = round(imputeTS::na.interpolation(Ozone, option = 'stine')),
    Solar.R = round(imputeTS::na.interpolation(Solar.R, option = 'stine'))
  ) %>% 
  as_tsibble()

# Creating formula
f <- as.formula('y ~ Wind + Temp + Solar.R + trig(12) + poly(1) + ARMA(1, 1)')

# Building fasster without formula parsing
fsModel <- FASSTER(data = train, 
    formula = y ~ Wind + Temp + Solar.R + trig(12) + poly(1) + ARMA(1, 1))

# Building fasster - throws an error 
fsModel <- FASSTER(data = train, formula = f)

I am not sure if I am doing anything wrong here. The same formula when passed directly worked perfectly fine.

mitchelloharawild commented 6 years ago

Working on a fix now, something is not correct with the parsing of the formula.


A few changes to your example:


library(fasster)
library(fable)
library(tsibble)

# Preparing the data
train <- airquality %>% mutate(
  date = as.Date(paste('2018', Month, Day, sep = '-')), 
  Ozone = round(imputeTS::na.interpolation(Ozone, option = 'stine')),
  Solar.R = round(imputeTS::na.interpolation(Solar.R, option = 'stine'))
) %>% 
  as_tsibble()

# Creating formula
f <- as.formula('Ozone ~ Wind + Temp + Solar.R + trig(12) + poly(1) + ARMA(1, 1)')

# Building fasster without formula parsing
fsModel <- FASSTER(data = train, 
                   formula = Ozone ~ Wind + Temp + Solar.R + trig(12) + poly(1) + ARMA(1, 1))

# Building fasster - throws an error 
fsModel <- FASSTER(data = train, formula = f)
mitchelloharawild commented 6 years ago

Resolved in https://github.com/tidyverts/fable/commit/4e1521f3612e237fa99fa7fcc12321f0f1b8c694

ashraaghav commented 6 years ago

Apologies for the typo. Thanks for the fix!