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 19, 2018 in Data Analytics by Sahiti
• 6,370 points
2,195 views

1 answer to this question.

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 19, 2018 by DataKing99
• 8,250 points

Related Questions In Data Analytics

+1 vote
3 answers

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$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,865 views
0 votes
1 answer
+1 vote
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 14, 2018 in Data Analytics by Sahiti
• 6,370 points
7,098 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 Sahiti
• 6,370 points
1,905 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,090 points
5,072 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 Sahiti
• 6,370 points
1,047 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 19, 2018 in Data Analytics by DataKing99
• 8,250 points
4,544 views
0 votes
1 answer

Big Data transformations with R

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

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,570 points
1,046 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 17, 2018 in Data Analytics by DataKing99
• 8,250 points
1,918 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 26, 2018 in Data Analytics by DataKing99
• 8,250 points
849 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP