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.
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
fc_mean <- meanf(myts, h = 2)
scale_x_yearqtr(format = "%Y-%q") +
labs(x = "", y = "")
SD of Residuals
sd_resid <- fc_mean$model$sd
Value of Point forecast
pf <- fc_mean$mean
Culculate the upper of 95% prediction interval
(ans1 <- pf + sd_resid * qnorm(0.975))
the upper of 95% prediction interval of the model
(ans2 <- fc_mean$upper)