how to use forecast function for simple moving ave

2019-07-11 20:52发布

I want to predict the future values for my simple moving average model. I used the following procedure:

x <- c(14,10,11,7,10,9,11,19,7,10,21,9,8,16,21,14,6,7)   
df <- data.frame(x)    
dftimeseries <- ts(df)  
library(TTR)      
smadf <- SMA(dftimeseries, 4) # lag is 4    
library(forecast)    
forecasteddf <- forecast(smadf, 4) # future 4 values     

When run the above code, my forecast values are the same for all the next 4 days. Am I coding it correctly? Or, am I conceptually wrong?

The same is the case with exponential moving average, weighted moving average, and ARIMA also.

2条回答
狗以群分
2楼-- · 2019-07-11 21:28

The forecast is from the fpp2 package and the moving average function is from the smooth package.

This is an example:

library(smooth) library(fpp2) library(readxl) setwd("C:\Users\lferreira\Desktop\FORECASTING")

data<- read_xlsx("BASE_TESTE.xlsx") ts <- ts(data$1740,start=c(2014,1),frequency=4)

fc <- forecast(sma(ts),h=3) Error: The provided model is not Simple Moving Average!

查看更多
男人必须洒脱
3楼-- · 2019-07-11 21:41

For a moving average model you can read here

"Since the model assumes a constant underlying mean, the forecast for any number of periods in the future is the same...".

So, your result are to be expected considering the characteristics of the moving average mode.

查看更多
登录 后发表回答