tidyverts / tidyverts/fabletools

Add function to create combination model, given a mable

Open
#323 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
98
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Having a function automatically create a simple average combination model would be very convenient. Here's a simple way it could work -

library(tsibble)
library(fable)

addCombn <- function(m, name) {
  mv <- mable_vars(m)
  m[[name]] <- Reduce(f = '+', as.list(m[, mv])) / length(mv)
  return(m)
}

m <- tourism %>%
  dplyr::filter(Region == 'Adelaide' & Purpose == 'Business') %>%
  model(
    E = ETS(Trips), 
    A = ARIMA(Trips), 
    T = THETA(Trips)
  ) %>%
  addCombn('EAT')

This almost works as desired. See below -

mable_vars(m) # misses 'EAT'
[1] "E" "A" "T"
m$cc <- 1L
m$cc <- NULL
mable_vars(m) # desired outcome
[1] "E" "A" "T" "EAT"

I think there's something subtle that I'm missing, maybe some shallow copies?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the example in the issue and inspect how mable_vars() identifies model columns and how model() constructs a mable. Determine how a newly added combination model can be registered so mable_vars(m) includes it; done means the proposed helper creates the simple average model and the resulting mable reports the new name.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.