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.
Related
I'm trying to estimate VAR model using vars package. I have a problem with differencing my multivariate time series.
First time series looks like this
the second one looks like this
I have tried to use diffM() from MTS package to difference by 1 lag in all of them, but still, some of them are non-stationary.
I am trying to forecast next-day hourly electricity prices for 2016 using the exponential smoothing method. The data-set that I am using contains hourly price data for the period 2014-01-01 00:00 to 2016-12-31 23:00. My goal is to reproduce the results in Beigaitė & Krilavičius (2018)
As electricity price data exhibits multiple seasonalities (daily, weekly, and yearly), I have defined a msts object for the period 2014-01-01 to 2015-12-31
msts.elspot.prices.2014_2015 <- msts(df.elspot.prices.2014_2015$Price, seasonal.periods = c(24, 168, 8760), ts.frequency = 8760, start = 2014)
I want to use this msts object to forecast the next day (2016-01-01) hourly electricity prices using the hw() function from the forecast package and store the point forecasts in the data frame containing the actual hourly electricity prices for the year 2016.
df.elspot.prices.2016$pred.hw <- hw(msts.elspot.prices.2014_2015, h = 24)$mean
However, I am unable to use the hw() function as I get the following error message:
Error in ets(x, "AAA", alpha = alpha, beta = beta, gamma = gamma, phi = phi, : `
Frequency too high
After looking online, it appears that the ets() function can only accept the parameter frequency to be max 24. As I am working with hourly data, this is much far below the frequency of my data.
Is there a way I can achieve my desired results using the hw() function? Are there any other packages/functions that could help me achieve my desired results?
I appreciate your help!
After looking a bit more, I've came across this question where a user wanted to use the hw method to forecast half-hourly electricity demand using the taylor dataset available in the forecast package.
As Professor Rob Hyndman suggest in the response to the linked question, the double seasonal Holt Winters model method dshw from the forecast package can be used to deal with half-hourly data.
After removing the yearly seasonality parameter (seasonal.periods = 8760) in the definition of my msts object, I've ran the model and it provided a pretty accurate result.
I have a problem with my code. I want to forecast stock returns with an ARIMA model in R but I can not get my data stationary. Besides transforming the stock prices into returns, I also tried the diff function for differencing my time-series. I always assumed that data becomes stationary by using one of the 2 methods. However, when I run an augmented dickey fuller test (adf.test in R) my p-value shows me that the data remains non-stationary. What am I doing wrong?
enter image description here
Thanks in advance.
You must perform time series decomposition into data, seasonal, trend and residuals:
library('forecast')
library('tseries')
data$moving_average=ma(data$original, order=7)
moving_average = ts(na.omit(data$moving_average), frequency=30)
decomposition = stl(moving_average, s.window="periodic")
stationary <- seasadj(decomposition)
plot(decomposition)
You will get:
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".
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.