rforecastingfable

Why is this fitting model giving 1 model per df line


in a normal model fit on a dataset that looks like this :

> head(total)
# A tsibble: 6 x 15 [1D]
# Key:       id [6]
  Date       Close Interest_Rate Consumer_Inflation `CPI(YOY)` `Wage_Index(QoQ)` `Wage_Index(YoY)` AiG_idx TD_Inflation CFTC_AUD_net_positions `RBA_Mean_CPI(Yo~ Commonwealth_Ba~
  <date>     <dbl>         <dbl>              <dbl>      <dbl>             <dbl>             <dbl>     <dbl>        <dbl>                  <dbl>             <dbl>            <dbl>
1 2009-04-01  69.4             0                  0          0                 0                 0         0            0                      0                 0                0
2 2009-04-02  71.6             0                  0          0                 0                 0         0            0                      0                 0                0
3 2009-04-03  71.0             0                  0          0                 0                 0         0            0                      0                 0                0
4 2009-04-06  71.0             0                  0          0                 0                 0         0            0                      0                 0                0
5 2009-04-07  71.6             3                  0          0                 0                 0         0            0                      0                 0                0
6 2009-04-08  71.1             3                  0          0                 0                 0         0            0                      0                 0                0

the training model :

fit <- total_axy %>%
  model(
    fable::TSLM(Close)
    )

report(axy_fit)

is training

1-10 of 3,409 rows | 1-10 of 16 columns

1 model per row! how can I solve this ? I just want 1 model for all rows!!!


Solution

  • You get one model per row because your key is set to id, which I guess is set to a unique value per row. You can see that there are 6 rows and 6 unique values of id.

    According to the package website a tsibble has a key attribute which should be:

    a set of variables that define observational units over time

    To fix it, try changing the key or removing it.

    An example:

    library(dplyr)
    library(tsibble)
    library(fpp3)
    
    total <- 
      tibble(
      Date = seq.Date(from = as.Date("2009-04-01"), to = as.Date("2009-04-08"), by = 1),
      Close = rnorm(length(Date))
    ) %>% 
      # Make a tsibble with no key
      as_tsibble(index = Date)
    
    fit <- 
      total %>% 
      model(
        fable::TSLM(Close)
      )
    
    report(fit)
    

    This gives only one model.