R/rmse.R

Defines functions rmse

Documented in rmse

# Do this in a separate file to see the generated help:
# library(devtools)
# document()
# load_all(as.package("../../onlineforecast"))
# ?rmse

#' Returns the RMSE.
#'
#' Used for forecast evaluation evaluation and optimization of parameters in model fitting.
#'
#' Note that \code{NA}s are ignored (i.e. \code{mean} is called with \code{na.rm=TRUE}).
#'
#' @title Computes the RMSE score.
#' @param x a numerical vector of residuals.
#' @return The RMSE score.
#' @seealso \code{\link{score}()} for calculation of a score for the k'th horizon
#' @name rmse
#' @examples
#'
#'
#'  # Just a vector to be forecasted
#'  y <- c(filter(rnorm(100), 0.95, "recursive"))
#'  # Generate a forecast matrix with a simple persistence model
#'  Yhat <- persistence(y, kseq=1:4)
#'  # The residuals for each horizon
#'  Resid <- residuals(Yhat, y)
#'
#' # Calculate the score for the k1 horizon
#' rmse(Resid$h1)
#'
#' # For all horizons
#' apply(Resid, 2, rmse)
#'
#' 
#' @export

rmse <- function(x) {
    sqrt(mean(x^2, na.rm = TRUE))
}

Try the onlineforecast package in your browser

Any scripts or data that you put into this service are public.

onlineforecast documentation built on Oct. 12, 2023, 5:15 p.m.