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

Passing formula variables to combination_model fails #415

Closed
jfeltonnee opened this issue May 30, 2024 · 1 comment
Closed

Passing formula variables to combination_model fails #415

jfeltonnee opened this issue May 30, 2024 · 1 comment

Comments

@jfeltonnee
Copy link

Error in combination_model():
! combination_model() must use component models with the same response variable.

Example to reproduce error:
library(fable)
library(tsibbledata)

f1 <- formula(Tobacco ~ Beer)
f2 <- formula(Tobacco ~ Gas)

fabletools::model(aus_production
, cmbn1 = combination_model(
NNETAR(formula = f1)
, NNETAR(formula = f2)
, cmbn_args = list(weights = "inv_var")))
__

@mitchelloharawild
Copy link
Member

This isn't working because it is treating f1 and f2 as response variables, rather than formulas.
You need to use !!f1 and !!f2 to substitute the names f1 and f2 with their values.

library(fable)
#> Loading required package: fabletools
library(tsibbledata)

f1 <- formula(Tobacco ~ Beer)
f2 <- formula(Tobacco ~ Gas)

aus_production |> 
  model(
    cmbn1 = combination_model(
      NNETAR(formula = !!f1),
      NNETAR(formula = !!f2), 
      cmbn_args = list(weights = "inv_var")
    )
  )
#> # A mable: 1 x 1
#>           cmbn1
#>         <model>
#> 1 <COMBINATION>

Created on 2024-06-02 with reprex v2.1.0

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

2 participants