Created
July 7, 2016 01:05
-
-
Save sillasgonzaga/f0a1d033ab9d6d7b7f4dd03f8c27464e to your computer and use it in GitHub Desktop.
Prediction intervals for forecasting models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pi_accuracy <- function(fc, yobs){ | |
# source: http://ellisp.github.io/blog/2016/01/30/hybrid-forecasts | |
# checks the success of prediction intervals of an object of class | |
# forecast with actual values | |
if(length(yobs) != length(fc$mean)){ | |
stop("yobs needs to be the same length as the forecast period.") | |
} | |
n <- length(yobs) | |
yobsm <- cbind(yobs, yobs) | |
In <- (yobsm > fc$lower & yobsm < fc$upper) | |
colnames(In) <- c("Series 1", "Series 2") | |
Success <- colMeans(In) | |
return(list(In = In, Success = Success, n = n)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment