I work for an auditing firm and perform time series analysis with reference to the online training("Forecasting Using R" at DataCamp) and the books.
In order to deepen my understanding, I have recalculated various methods myself, but I cannot reproduce the prediction interval of the meanf function.
Perhaps my formula is wrong, but it would be helpful if someone could teach me the correct formula.
Packages
library(fpp2)
library(zoo)
Create a data
mydata <- c(10, 20, 30, 40)
Create a ts object called myts
myts <- ts(mydata, start = c(2019, 1), frequency = 4)
Create an autoplot
autoplot(myts)
meanf
fc_mean <- meanf(myts, h = 2)
autoplot(fc_mean) +
scale_x_yearqtr(format = "%Y-%q") +
labs(x = "", y = "")
Thank you for your reply!!
I understand very well.
Another question came to mind, but in the case of the ses method, it seems that the normal distribution is used and the parameter estimation error is not taken into account.
Is the same consideration as the meanf method unnecessary?
It would probably be better to use qt rather than qnorm in all these functions.
Taking parameter estimation into account is very difficult except for some simple methods such as linear models. So we usually ignore it.
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:
I have another question.
I cannot reproduce the prediction interval of the holt-winters' multiplicative function.
(Although, I can do that of the holt-winters' additive function.)
What is the cause?
Packages
library(fpp2)
Create a data
mydata <- c(10,30,20,40,20,50,40,60,50,70,60,90)
Create a ts object called myts
myts <- ts(mydata, start = c(2019, 1), frequency = 4)
Holt-Winters' additive
fc_hwa <- hw(myts, seasonal = "additive", h = 4)
autoplot(fc_hwa) # Create an autoplot
sd_resid <- sqrt(fc_hwa$model$sigma2) # SD of Residuals
pf <- fc_hwa$mean[1] # Value of Point forecast
(ans1 <- pf + sd_resid * qnorm(0.975)) # Culculate the upper of 95% prediction interval
(ans2 <- as.numeric(fc_hwa$upper[1, 2])) # The upper of 95% prediction interval of the model
identical(ans1, ans2) # Identical