# NOT RUN {
M3Forecast[["NAIVE2"]][1,]
# }
# NOT RUN {
# calculate errors using the accuracy function
# from the forecast package
errors <- lapply(M3Forecast, function(f) {
res <- NULL
for(x in 1:length(M3)) {
curr_f <- unlist(f[x,])
if(any(!is.na(curr_f))) {
curr_res <- accuracy(curr_f, M3[[x]]$xx)
} else {
# if no results are available create NA results
curr_res <- accuracy(M3[[x]]$xx, M3[[x]]$xx)
curr_res <- rep(NA, length(curr_res))
}
res <- rbind(res, curr_res)
}
rownames(res) <- NULL
res
})
ind_yearly <- which(unlist(lapply(M3, function(x) {x$period == "YEARLY"})))
ind_quarterly <- which(unlist(lapply(M3, function(x) {x$period == "QUARTERLY"})))
ind_monthly <- which(unlist(lapply(M3, function(x) {x$period == "MONTHLY"})))
ind_other <- which(unlist(lapply(M3, function(x) {x$period == "OTHER"})))
yearly_errors <- t(as.data.frame(lapply(errors, function(x) {colMeans(x[ind_yearly,])})))
quarterly_errors <- t(as.data.frame(lapply(errors, function(x) {colMeans(x[ind_quarterly,])})))
monthly_errors <- t(as.data.frame(lapply(errors, function(x) {colMeans(x[ind_monthly,])})))
other_errors <- t(as.data.frame(lapply(errors, function(x) {colMeans(x[ind_other,])})))
yearly_errors
quarterly_errors
monthly_errors
other_errors
# }
Run the code above in your browser using DataLab