'lambda' not found in model fitting

265 views Asked by At

I m using tsibble package tourism .

trying to do transformation and fit models to it.

library(tsibble)
library(feasts)
library(dplyr)

sum_tourism <- tourism %>% 
  group_by(Region) %>% 
  summarise(sum_trips=sum(Trips))
fit <- function(ts, col){
  lambda <- ts %>% 
    features(col, features=guerrero) %>% 
    pull(lambda_guerrero)
  mod <- model(ts, arima=ARIMA(box_cox(col, lambda=lambda)))
  return(mod)
}
models <- sum_tourism %>% 
  split(sum_tourism$Region) %>% 
  map(~fit(.x, .x$sum_trips))

it gives me error. pls help. thx

! object 'lambda' not found
1

There are 1 answers

4
Wael On

To have the lambda object you need some modification in your code read this answer Using rlang's injection paradigm.

with this modification, the lambda vector is calculated and could be returned by the function.

I have some errors with your model please provide the r packages used in your code

library(tsibble)
library(feasts)
library(dplyr)

sum_tourism <- tourism %>% 
  group_by(Region) %>% 
  summarise(sum_trips=sum(Trips))

fit <- function(ts, col){
  lambda <- ts %>% 
    features(!!as.symbol(col), features=guerrero) %>% 
    pull(lambda_guerrero)
  return(lambda)
}
fit(sum_tourism,"sum_trips")
#>  [1]  1.999926773 -0.549847967 -0.168440573  0.666662207 -0.005751637
#>  [6]  0.398992355 -0.221036172 -0.899926773  0.033105893  0.026759753
#> [11] -0.552176875 -0.732231571  0.443440107 -0.657039779  0.677437056
#> [16]  0.788476241  0.838297770  0.147628493 -0.899926773  0.185737932
#> [21] -0.007981998  0.387056949 -0.491568669  0.443289198  0.376520326
#> [26] -0.899926773 -0.899926773 -0.872745709 -0.038044620  0.044313692
#> [31]  0.762098703  0.030736135 -0.899926773  0.455422071  1.160665179
#> [36]  0.096452846 -0.535855516  0.738756222  0.090007587  0.689406832
#> [41]  0.407197974 -0.584847430  0.049477387 -0.304122383 -0.769245111
#> [46]  0.121514057  0.803968558 -0.426019305 -0.899926773 -0.531133400
#> [51]  0.667325493  0.109044833 -0.195416339  1.096501192  0.457220688
#> [56]  1.565333102  0.166391665  1.999926773 -0.013414117 -0.221385671
#> [61]  0.218667327 -0.899926773 -0.306734388 -0.473628340  1.045258935
#> [66]  0.365400240  0.068291558  0.670362886  1.127973610  0.626529021
#> [71] -0.439209555 -0.116154482  0.493627942  0.450986664 -0.353838979
#> [76]  0.232408170

Created on 2023-04-16 with reprex v2.0.2