Auto-ARIMA function in R giving odd results - r

I have a day level dataset for 3 years,
I ran auto.arima() in R on it for simple time series forecasting and it gave me a (2,1,2) model.
When I used this model to predict the variable for the next 1 year the plot became constant after a few days, which can't be correct
As I have a daily data for 3 years, and a frequency of 364 days, is ARIMA incapable of handling daily data with large frequencies?
Any help will be appreciated

This sounds like you are trying to forecast too far into the future.
The forecast for tomorrow is going to be accurate, but the forecast for the next day and the day after that are not going to be influenced much by the past data and they will therefore settle around some constant when trying to forecast too far into the future. "Too far into the future" probably means two or more time points.
Lets say you have data up until time point T+100, which you used to estimate your ARIMA(2,1,2) model. You can "forecast" the value for time T+1 by pretending you only have data until point T and use your ARIMA(2,1,2) model to forecast T+1. Then move ahead by one period in your data and pretend you only have data until time T+1 and "forecast" T+2. This way you can assess the forecasting accuracy of your ARIMA(2,1,2) model, for example by calculating the Mean Squared Error (MSE) of the "forecasts".

Related

How can the forecast accuracy of three models for a categorical time series be compared?

This is a general question. Can anybody please point me in the direction of how I can compare the forecasts of a 3 level categorical time series by three competing models? I would like to compare the forecasts to the ground truth of what actually occurred. The forecasts are 1 to 6 days ahead. Is it correct to analyse each day ahead separately? We have forecasts for 4 years. Should they be analysed separately to allow for variation in each year or can the years be used more wholistically? The prediction accuracy for each each model for each day is assessed with the Gerrity score. I am an R user.
I am happy to provide more info if required. Thanking you in advance.

Can one improve coefficients in recursion using some machine learning algorithm?

I've got this prediction problem for daily data across several years. My data has both yearly and weekly seasonality.
I tried using the following recurrence:(which I just came up with, from nowhere if you like) xn = 1/4(xn-738 + xn-364 + xn-7 + 1/6(xn-1+xn-2+xn-3+xn-4+xn-5+xn-6)
Basically, I am taking into consideration some of the previous days in the week before the day I am trying to predict and also the corresponding day a year and two years earlier. I am doing an average over them.
My question is: can one try to improve the prediction by replacing the coefficients 1/4,1/6 etc with coefficients that would make the mean squared residual smaller?
Personally I see your problem as a regression.
If you have enough data I would run for timeseries prediction.
You said that the data has yearly and weekly seasonality. In order to cope with that you can have two models one with weekly window and one dealing with the yearly pattern and then somehow combine them (linear combination or even another model).
However if you don't have you could try passing the above xi as features to a regression model such as linear regression,svm,feed forward neural network and on theory it will find those coefficients that produce small enough loss (error).

Auto.Arima with Daily Sales - Univariate Time Series Error

I'm working with a data set from 2017-01-01 to 2017-10-27, however, the auto.arima says it can only handle univariate time series, despite there being only daily data.
What am I missing?
Reproducible example:
set.seed(25)
datelist<-seq(as.Date("2016-01-01"),as.Date("2017-10-27"),by="day")
salesvals<-round(abs(rnorm(length(datelist)))*1000,digits=2)
salestbl<-data.frame(datelist,salesvals)
salesTS<-ts(salestbl,
start=c(2016,as.numeric(format(salestbl$datelist, "%j"))),
frequency=7)
fit <- auto.arima(salesTS)
Error:
Error in auto.arima(salesTS) :
auto.arima can only handle univariate time series
Overall, I know there's a weekly seasonality, hence the seven days. I know there's also a quarterly seasonality, but I can tackle that another time.
Overall I'm trying to get a forecast for 2017-12-31, using an arima forecast.
The problem is that you are declaring the data.frame as time series wrong. Any way you dont need to do that just omit the ts part like this:
set.seed(25)
datelist<-seq(as.Date("2016-01-01"),as.Date("2017-10-27"),by="day")
salesvals<-round(abs(rnorm(length(datelist)))*1000,digits=2)
salestbl<-data.frame(datelist,salesvals)
fit <- auto.arima(salestbl[,2])
just head(salesTS) and you will see why you get the error.

Forecasting Daily "Count" Data in r

I am trying to fit a time series model on daily data for 2 years. Data is related to daily count of something. I have 731 records (as it includes leap year as well).
I have been using ARIMA Model in r but the forecast are very off. Is there any specific algorithm that takes care of daily data?
Also the forecast can not be in fraction as its the count data. It is always integer.
Any help is appreciated!

forecasting time series by updating in R

I'm working on time series with a monthly demand for 5 years in R. Currently, I'm using naive method to forecast 12 months (h=12)and it does work very well I want to forecast only for one month (h=1) (always with naive method) and then include this predicted value to time series and repeat this process 12 times. For example:
get forecast for January 2013
include this predicted value to time series
apply naive method for the new series
My time series is not stationary and has a trend and seasonality.
What I'm looking to do is to forecast using Naive but step by step (month by month) with updating my time series each step. How can I do that?
Surely you will get the same answer. The naive method uses the most recent observation as the forecast. So your first forecast will be equal to the last observation. Your second forecast will be equal to the first forecast, and so is also equal to the last observation. And so on.
In any case, what you describe is precisely how almost all time series forecasts work. It is called the recursive method of forecasting, where predicted values take the place of observations as you forecast further ahead. In the forecast package for R, all purely time series forecasts are created this way.

Resources