error with list and seasonal in purrr

Hello,
I am performing a simple seasonal adjustment.
Here is the code that works ok.

library(seasonal)
library(purrr)

datos <- ts(rnorm(700), frequency = 12,start = 1960)
ajuste <- seas(datos, arima.model = c(0, 1, 1,0, 1, 1))
ajuste

But after running the code from above, I tried a loop with map.
I defined the arima models in a list.
When I run map using seas and arima model, It fails.

regresion_list <- list("c(1 1 1,0 1 1)","c(3 1 2,0 1 3)")
aj_map <- map(regresion_list, ~ seas(datos, arima.model =  .x))

I know the reason.
Each element from regresion_list is recognized as character and not numeric:

str(c(0, 1, 1,0, 1, 1))

str(regresion_list)

I just don't know how to tell inside map that each element from .x or regresion_list is a numeric vector and not a character one.

Can you help me?
Thanks for your time and interest.
Have a nice week.

I updated the code, but still fails

regresion_list <- list(c(1,1,1,0,1,1),c(2,1,2,0,1,2))

seas(datos, arima.model = as_vector(regresion_list[[1]]))
seas(datos, arima.model = as_vector(regresion_list[[2]]))

 map(regresion_list, ~ seas(datos, arima.model =.x))

As you can check, I can run the seas command using regresion_list[[1]] or regresion_list[[2]].
But using map and the whole list regresion_list crashes.

...map.poly(database, regions, exact, xlim_tmp, ylim, boundary,  : 
  no recognized region names

One exist is writing a loop, but I try to avoid them:

for (i in 1:2){
  m_d<-seas(datos, arima.model = regresion_list[[i]])
  print(m_d)
  }

I really want the purrr approach.

Try:

regresion_list <- list("c(1, 1, 1,0, 1 ,1)","c(3, 1, 2,0, 1, 3)")
eval(parse(text = regresion_list[[1]]))

Then make it fit with what you want to do.

-- edit: I've seen your edited dataset. Will have a look at that.

This seems to work:

map(1:length(regresion_list), ~seas(datos, arima.model = regresion_list[.x][[1]]))

But then, so does this:

 map(regresion_list, ~ seas(datos, arima.model =  .x))

The both produce the message:

Model used in SEATS is different: (2 1 2)(0 1 1)

See {fpp3}, which has a complete set of tidy-friendly time series packages, including generating multiple models on the same data set. There’s also an accompanying online text. See Sec 5.1 for how to run multiple time series in the same model.

The book doesn't discuss about X13 and SEATS with many examples.
It shows how to perform a sarima model like I'd like, but not using X13 or X11.
Very good book by the way.

For those see this reference., which goes into the algos in depth. No code, but my recall is that it wasn't difficult to apply.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.