3
$\begingroup$

I am working with daily data (variables include: temperature, salinity, wind, etc...) from 2002-2013 (msts), and I want to identify the ARIMA equation describing the whole data set, while also considering covariates unique to each variable, then use the ARIMA equation to predict each variables' values 7 days into the future from specific starting points in the data set. Thus, tbats is not appropriate for me.

First I need to define the "order" and "seasonal" values for my Arima equation using auto.arima. Additionally, I believe there is seasonality in the data that is weekly, monthly and yearly so I am defining multiple "seasonal periods" in auto.arima. Starting with predicting the temperature variable values, I am using xreg in the auto.arima function to include specified covariates, and want to also include the fourier/fourierf function for the dummy variables of month and year as well as a method for determining K.

Ultimately, my R code should be written to consider long-term data (2002-2013), seasonality (3), dummy variables (Month and Year), and identify the K value for predictive purposes.

Although I have found a lot of great help online, I cannot get my more complex code to work. http://robjhyndman.com/hyndsight/longseasonality/ (and other Hyndman posts for complex seasonality, forecasting, detecting seasonality, daily data, etc...) and Time Series Forecasting with Daily Data: ARIMA with regressor

I am using these packages for various parts of the code development:

library(MASS)
library(mgcv)
library(lattice)
library(epicalc)
library(caTools)
library(forecast)
library(McSpatial)

My simple R CODE below works - although only has one seasonal period, and no fourier function or dummy variables included.

Season<- msts(PaulsData$Temperature, seasonal.periods=30)
auto.arima(Season,stepwise=TRUE,approximation=TRUE,xreg=Covariates)
# Temperature: ARIMA(4,1,0)(1,0,0)[30]
fit<-Arima(June2009EventA$Temperature,order=c(4,1,0),seasonal=c(1,0,0))
plot(forecast(fit, h=7)) # fit is not very dynamic
dev.off()
View(forecast(fit))

The complex code below has the equation components I think I need, but it does not work... The K part is where things keep getting hung up... "Error in fourier(y, K = i) : unused argument (K = i)". This happens anytime I use fourier.

y<- msts(PaulsData$Temperature, seasonal.periods=c(7,30,365.25)) #Daily Temperature (w/NAs) 2002-2012
bestfit<-list(aicc=Inf) # Select K value
for(i in 1:25)
{
fit<- auto.arima(y, xreg=fourier(y, K=i), seasonal=FALSE) # need the K-value, error in fourier function - K unused arugument
 if(fit$aicc<bestfit$aicc)
   bestfit<-fit
 else break;
}
dummyMonth<- fourier(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=30),K=bestfit)   # need the K-value, error in fourier function - K unused argument
ZdummyMonth<- fourierf(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=30, h=7),K=bestfit)
dummyYear<- fourier(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=365.25),K=bestfit)
ZdummyYear<- fourierf(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=365.25, h=7),K=bestfit)
fit<- auto.arima(y,xreg=cbind(dummyMonth,dummyYear,Covariates),seasonal=FALSE)
plot(forecast(fit, h=7))

Even if I use the code below to exclude the selection of the K value, it does not work?!

y<- msts(PaulsData$Temperature, seasonal.periods=c(7,30,365.25)) #Daily Temperature (w/NAs) 2002-2012
dummyMonth<- fourier(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=30),K=5)   # need the K-value, error in fourier function - K unused argument
ZdummyMonth<- fourierf(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=30, h=7),K=5)
dummyYear<- fourier(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=365.25),K=5)
ZdummyYear<- fourierf(msts(PaulsData$Temperature,seasonal.periods=cbind(7,30,365.25), ts.frequency=365.25, h=7),K=5)
fit<- auto.arima(y,xreg=cbind(dummyMonth,dummyYear,Covariates),seasonal=FALSE)
plot(forecast(fit, h=7))

Where: Temperature = a column of values in deg C with x-rows
Month = matrix of zeros and ones with x-rows
Year = matrix of zeros and ones with x-rows
Covariates = columns of values in appropriate units (i.e. Salinity (ppt), Wind (m/s)) with x-rows

Thank you in advance for your help!

$\endgroup$
  • 1
    $\begingroup$ Load forecast library and type ?fourier to see the help page for this function. The last example there is for multivariate time series. It looks like you need to supply a vector K, not a scalar K. Maybe that is why you are getting an error. $\endgroup$ – Richard Hardy Jan 30 '15 at 9:23
2
$\begingroup$

Try:

library(forecast)
ts_ <- ts(PaulsData$Temperature, frequency = 1)
msts_ <- msts(ts_, c(7,30,365))
fit <- auto.arima(ts_, seasonal=F, xreg=fourier(msts_, K=c(3,5,10)))  # i,j,k

If this works, you may loop through (i,j,k) to find the "best" model. Make it sure (i,j,k) is no more than half of (7,30,365) correspondingly.

$\endgroup$
  • $\begingroup$ what it means > k=c(3,5,10) i am having daily temperature data for 25 years how can use this ? because when ever i am forecasting it is showing me error let say arima1 is fitted so when i used to forecast arima1.forecast=forecast.Arima(arima1,h=306) It shows me below error Error in forecast.Arima(fit, h = 306) : No regressors provided $\endgroup$ – Hiren Mar 15 '17 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.