se: Squared Error

View source: R/se.R

seR Documentation

Squared Error

Description

This function calculates the Squared Error (SE) given observations of an univariate variable and samples of a predictive distribution.

Usage

se(y, x, na.action = na.omit, aggregate = FALSE, ...)

Arguments

y

vector of observations

x

matrix of samples of a predictive distribution or vector containing the means of a predictive distribution (depending on y; see details)

na.action

function to handle the NA's. Default: na.omit.

aggregate

logical or function for aggregating the single scores, e.g. sum, mean, weighted.mean, .... Default: FALSE, i.e. no aggregation function.

...

further arguments passed to the aggregate function.

Details

For a vector y of length n, x can be given as matrix of samples of a predictive distribution with n rows, where the i-th entry of y belongs to the i-th row of x. The columns of x represent the samples of a predictive distribution. The row-wise means are determined by its sample version.

If the means of a predictive distribution are directly available, x can be given as vector of means, where the i-th entry of y belongs to the i-th entry of x.

In addition, with this function, the Mean Squared Error (MSE) by specifying aggregate = mean and Root Mean Squares Error (RMSE) can be calculated (see examples).

A lower SE indicates a better forecast.

Value

Vector of score value(s).

Author(s)

David Jobst

References

Gneiting, T. (2011). Making and Evaluating Point Forecasts. Journal of the American Statistical Association, 106(494), 746-762.

Examples

# simulated data
n <- 30
m <- 50
y <- rnorm(n)
x1 <- matrix(rnorm(n*m), ncol = m)
x2 <- apply(x1, 1, mean)

# ae calculation
se(y = y, x = x1)
se(y = y, x = x1, aggregate = mean)

se(y = y, x = x2)
(mse <- se(y = y, x = x2, aggregate = mean))
(rmse <- sqrt(mse))


jobstdavid/eppverification documentation built on May 13, 2024, 5:20 p.m.