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

Augment() fails #399

Closed
USMortality opened this issue Mar 12, 2024 · 1 comment
Closed

Augment() fails #399

USMortality opened this issue Mar 12, 2024 · 1 comment

Comments

@USMortality
Copy link

USMortality commented Mar 12, 2024

Not really sure why the agument function fails here:

library(fable)
library(tsibble)
library(dplyr)

y <- c(878.6, 866.4, 864.9, 1017.8, 1029.5, 961.5, 896.2)
h <- 2

z <- length(y) - h

df_bl <- tibble(x = seq.int(1, length(y)), y = y) |> as_tsibble(index = x)
# Split data into training and test
df_train <- df_bl |> filter(x <= z)
df_test <- df_bl |> filter(x > z)

df_train |>
  as_tsibble(index = x) |>
  model(lm = TSLM(y ~ trend())) |>
  augment()
Error in `mutate()`:
ℹ In argument: `dplyr::across(...)`.
Caused by error in `across()`:
! Can't compute column `lm`.
Caused by error in `mutate()`:
ℹ In argument: `.fitted = fitted(x, ...)[[".fitted"]]`.
Caused by error in `object$fitted`:
! $ operator is invalid for atomic vectors
Run `rlang::last_trace()` to see where the error occurred.

Just plotting works:

df_train |>
  as_tsibble(index = x) |>
  model(lm = TSLM(y ~ trend())) |>
  forecast(h = h) |>
  autoplot(bind_rows(df_train, df_test))
@USMortality
Copy link
Author

Looks like this may have todo with the column naming. Replacing x/y with something more arbitrary works. Probably an internation collision.

library(fable)
library(tsibble)
library(dplyr)

y <- c(878.6, 866.4, 864.9, 1017.8, 1029.5, 961.5, 896.2)
h <- 2

z <- length(y) - h

df_bl <- tibble(year = seq.int(1, length(y)), asr = y) |> as_tsibble(index = year)
# Split data into training and test
df_train <- df_bl |> filter(year <= z)
df_test <- df_bl |> filter(year > z)

df_train |>
  as_tsibble(index = year) |>
  model(lm = TSLM(asr ~ trend())) |>
  augment()

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

1 participant