How to forecast season and trend of data using STL and ARIMA in R?

0 votes

Consider a data series that has a seasonal component, a trend, and an ARIMA part. I want to forecast this series.

data_ts <- ts(data, frequency = 24)
data_deseason <- stl(data_ts, t.window=50, s.window='periodic', robust=TRUE) 
f <- forecast(data_deseason, method='arima', h = N)

By implementing the above code, I am not able to choose the parameters of the ARIMA part, which I would like to.

I tried splitting the data into a season a trend and a remainder part. But then how do I forecast it?

Should I make an ARIMA model for both the trend and the remainder?

trend_arima <- Arima(data_deseason$time.series[,'trend'], order = c(1,1,1))
remainder_arima <- Arima(data_deseason$time.series[,'remainder'], order = c(1,1,1))

and then use forecast() and add the two above components and the season. 

Or is there some way to extract the trend model that STL has found?

May 18, 2018 in Data Analytics by darklord
• 6,140 points
370 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You can use the forecast.stl function for the reminder series. It is fast because it need not consider seasonal ARIMA models.

You can select a specific model with specific parameters via the forecast function argument. 

For example, suppose you wanted to use an AR(1) with parameter 0.5, the following code will do it:

data_ts <- ts(data, frequency = 24)
data_deseason <- stl(data_ts, t.window=50, s.window='periodic', robust=TRUE) 
f <- forecast(data_deseason, h=N,
        forecastfunction=function(x,h,level){
        fit <- Arima(x, order=c(1,0,0), fixed=0.5, include.mean=FALSE)
        return(forecast(fit,h=N,level=level))})
plot(f)

If you just want to select the ARIMA order, but not the parameters, then leave out the fixed argument.

answered May 18, 2018 by DataKing99
• 8,100 points

Related Questions In Data Analytics

0 votes
1 answer

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
47 views
0 votes
1 answer
0 votes
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,140 points
61 views
0 votes
1 answer

How to calculate group mean and assign it to new data in R

You can use something like this: df$grp.mean.values <- ...READ MORE

answered Jun 27, 2018 in Data Analytics by darklord
• 6,140 points
36 views
0 votes
1 answer

Plot two variables as lines on the same graph using ggplot

If you have small number of variables, ...READ MORE

answered Apr 17, 2018 in Data Analytics by kappa3010
• 2,010 points
650 views
0 votes
1 answer

R lag irregular time series data

You could try using: library(dplyr) library(zoo) na.locf(ts$value[sapply(ts$time, function(x) min(which(ts$time - ...READ MORE

answered May 11, 2018 in Data Analytics by darklord
• 6,140 points
67 views
0 votes
1 answer

R plot arima fitted model with the original series

This question has many ways to answer, ...READ MORE

answered May 18, 2018 in Data Analytics by DataKing99
• 8,100 points
763 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 17, 2017 in Data Analytics by Sudhir
• 1,610 points
27 views
0 votes
1 answer

How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

answered May 16, 2018 in Data Analytics by DataKing99
• 8,100 points
45 views
0 votes
1 answer

How to cluster center mean of DBSCAN in R?

Just index back into the original data ...READ MORE

answered Jun 25, 2018 in Data Analytics by DataKing99
• 8,100 points
31 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.