Open raneameya opened 3 years ago
I think it was made to be used alongside mutate
library(tsibble)
library(fable)
library(tidyverse)
addCombn <- function(m, name) {
mv <- mable_vars(m)
m |>
mutate(!!name := Reduce(f = '+', as.list(m[, mv])) / length(mv))
}
m <- tourism %>%
dplyr::filter(Region == 'Adelaide' & Purpose == 'Business') %>%
model(
E = ETS(Trips),
A = ARIMA(Trips),
T = THETA(Trips)
) %>%
addCombn('EAT')
That seems a bit restrictive to me. It does work without mutate, provided one uses the $
way of subsetting & assignment. for example, if I would have m$name <- Reduce(f = '+', as.list(m[, mv])) / length(mv)
, then it would work no problem. But programatically providing the name is where I ran into an issue.
Having a function automatically create a simple average combination model would be very convenient. Here's a simple way it could work -
This almost works as desired. See below -
I think there's something subtle that I'm missing, maybe some shallow copies?