问题
I am working with 30 days (monthly) per cycle and thus have approximately 2 cycles in my historical dataset.
R
script is,
library(forecast)
value <- c(117.2 , 224.2 , 258.0 , 292.1 , 400.1 , 509.9 , 626.8 , 722.9 , 826.1 , 883.6,916.6, 1032.1, 1151.2, 1273.4 ,1391.8, 1499.2, 1532.5 ,1565.9 ,1690.9, 1813.6,1961.4 ,2102.8 ,2208.2, 2256.8, 2290.8 ,2413.7, 2569.4 ,2730.3, 2882.9 ,2977.5, 117.2 , 224.2 , 258.0 , 292.1 , 400.1 , 509.9 , 626.8 , 722.9 , 826.1 , 883.6,916.6, 1032.1, 1151.2, 1273.4 ,1391.8, 1499.2, 1532.5 ,1565.9 ,1690.9, 1813.6,1961.4 ,2102.8 ,2208.2, 2256.8, 2290.8 ,2413.7, 2569.4 ,2730.3, 2882.9 ,2977.5)
sensor<-ts(value,frequency=30)#daily data of month,here only 2 month's data
fit <- auto.arima(sensor)
LH.pred<-predict(fit,n.ahead=30)
plot(sensor,ylim=c(0,4000),xlim=c(0,5),type="o", lwd="1")
lines(LH.pred$pred,col="red",type="o",lwd="1")
grid()
The resulting graph is
But I am not satisfied with the prediction. Is there any way to make the prediction look similar to the value trends preceding it (see graph)?
回答1:
You are asking a lot of auto.arima()
to find a model using only two months of data. At least help it out a little by suggesting a seasonal difference. Further, don't use predict
. The forecast
function is much nicer.
For reasons why forecast()
is "nicer", see the Journal of Statistical Software of July 2008, in particular section 4.4:
The forecast() function is generic and has S3 methods for a wide range of time series models. It computes point forecasts and prediction intervals from the time series model. Methods exist for models fitted using ets(), auto.arima(), Arima(), arima(), ar(), HoltWinters() and StructTS().
There is also a method for a ts object. If a time series object is passed as the first argument to forecast(), the function will produce forecasts based on the exponential smoothing algorithm of Section 2.
In most cases, there is an existing predict() function which is intended to do much the same thing. Unfortunately, the resulting objects from the predict() function contain different information in each case and so it is not possible to build generic functions (such as plot() and summary()) for the results. So, instead, forecast() acts as a wrapper to predict(), and packages the information obtained in a common format (the forecast class). We also define a default predict() method which is used when no existing predict() function exists, and calls the relevant forecast() function. Thus, predict() methods parallel forecast() methods, but the latter provide consistent output that is more usable.
Try the following.
fit <- auto.arima(sensor,D=1)
LH.pred <- forecast(fit,h=30)
plot(LH.pred)
grid()
来源:https://stackoverflow.com/questions/14331314/time-series-prediction-of-daily-data-of-a-month-using-arima