Skip to contents

Computes the normalized mean squared error (NMSE) between predictions and reference values.

Usage

nmse(x, ref, trainY, na.rm = FALSE)

Arguments

x

numeric vector of predicted values

ref

numeric vector of reference (true) values

trainY

numeric vector used as the normalization baseline

na.rm

logical; whether to remove incomplete cases before the computation. Defaults to FALSE, in which case a missing value anywhere makes the result NA.

Value

a numeric scalar containing the normalized mean squared error

Details

The normalized mean squared error is defined as: $$ \frac{\sum (ref - x)^2}{\sum (ref - mean(trainY))^2} $$

The denominator represents the squared deviation from the mean of the training response, providing a baseline for comparison.

If the denominator is zero, NA is returned.

Examples

x <- c(2.5, 3.0, 2.8)
ref <- c(3.0, 2.5, 3.0)
trainY <- c(2, 3, 4, 3)

nmse(x, ref, trainY)
#> [1] 2.16