3

I am currently working on a project for school that requires me to perform time series forecasting in R on a given set of data. I have looked up countless examples on how to do this, but every example I find contains a dataset that records data, for example, once a month over the course of 15 years. The dataset given to me by my professor has recorded data for every .001 seconds, and there are multiple data entries for the same second. For example, at the end of the data there are five different entries for .02500 seconds.

My understanding of a univariate time series is a time series that takes measurements at a specific period of time, like every month or every thousandth of a second. Whenever I try to do time series forecasting on the dataset (adeno), I get the error shown below under the code.

> fit <- auto.arima(adeno)
Error in auto.arima(adeno) : 
  auto.arima can only handle univariate time series

Can anyone tell me where I'm going wrong or if I'm misunderstanding something? I've tried trying to convert the dataset into a time series by using the ts() command in R but I must be doing something wrong because even after that it says it's not aunivariate time series.

www
  • 38,575
  • 12
  • 48
  • 84
Tom D
  • 65
  • 1
  • 1
  • 4
  • 2
    Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – David Heckmann Apr 25 '17 at 23:25
  • @useR, thank you so much that worked! I just had one more question if you can help. My project requires graphs of the time series forecasting, how could I get a plot of the auto.arima(ts(adeno[,1])) – Tom D Apr 27 '17 at 02:38

2 Answers2

7

The error means what it says, auto.arima can only handle univariate time series. Since you mentioned that your dataset has multiple entries for each time unit, it is a multivariate time series if you convert it using ts. You can do something along the lines of:

adenoTS = ts(adeno)
arima_fit = auto.arima(adenoTS[,1])

To address your second question in the comment section, I used the airquality dataset for demonstration:

library(forecast)

# Convert as time series
airTS = ts(airquality)

# Plot multivariate ts
plot(airTS[,1:4])

# Run auto.arima on a single ts
arima_fit = auto.arima(airTS[,3])

# Forecast for the next 10 time units
arima_forecast = forecast(arima_fit, h = 10)

# Plot forecasts
plot(arima_forecast)

forecast() from the forecast package allows you to forecast for the next h time units. What "time units" mean in this case depends on how you defined your time series in the airTS = ts(airquality) step. Here I didn't bother converting it properly, but you can add the start = and frequency = arguments in ts() to specify the start time and frequency of your ts.

The plot method for forecast lets you plot your forecast results. See ?plot.forecast.

enter image description here

acylam
  • 18,231
  • 5
  • 36
  • 45
1

Although my dataset has not have multiple entries for each time unit, it was purely univariate, the function didn't work.

Adding [,1] in the auto.arima argument helped to solve the problem:: autoarima1 <- auto.arima(TR_2015_2019_ts [,1])

Alexei
  • 11
  • 2