Last data update: 2014.03.03

R: Relative Maximal Absolute Error
RMAR Documentation

Relative Maximal Absolute Error

Description

Relative Maximal Absolute Error

Usage

RMA(Y, Ypred)

Arguments

Y

a real vector with the values of the output

Ypred

a real vector with the predicted values at the same inputs

Value

The RMA criterion represents the maximum of errors between exact values and predicted one:

RMA = max[(Y-Ypred)/sd(Y)]

where Y is the output variable, Ypred is the fitted model and sd(Y) denotes the standard deviation of Y.

The output of this function is a list with the following components:

max.value

the value of the RMA criterion

max.data

an integer i indicating the data x^{i} for which the RMA is reached

index

a vector containing the data sorted according to the value of the errors

error

a vector containing the corresponding value of the errors

Author(s)

D. Dupuy

See Also

other validation criteria as MAE or RMSE.

Examples

X     <- seq(-1,1,0.1)
Y     <- 3*X + rnorm(length(X),0,0.5)
Ypred <- 3*X
print(RMA(Y,Ypred))

# Illustration on Branin function
Branin <- function(x1,x2) {
   x1 <- x1*15-5   
   x2 <- x2*15
   (x2 - 5/(4*pi^2)*(x1^2) + 5/pi*x1 - 6)^2 + 10*(1 - 1/(8*pi))*cos(x1) + 10
}
X <- matrix(runif(24),ncol=2,nrow=12)
Z <- Branin(X[,1],X[,2])
Y <- (Z-mean(Z))/sd(Z)

# Fitting of a Linear model on the data (X,Y)
modLm <- modelFit(X,Y,type = "Linear",formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))

# Prediction on a grid
u <- seq(0,1,0.1)
Y_test_real <- Branin(expand.grid(u,u)[,1],expand.grid(u,u)[,2])
Y_test_pred <- modelPredict(modLm,expand.grid(u,u))
Y_error <- matrix(abs(Y_test_pred-(Y_test_real-mean(Z))/sd(Z)),length(u),length(u))
contour(u, u, Y_error,45)
Y_pred <- modelPredict(modLm,X)
out <- RMA(Y,Y_pred)
for (i in 1:dim(X)[1]){
    points(X[out$index[i],1],X[out$index[i],2],pch=19,col='red',cex=out$error[i]*10)
}

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(DiceEval)
Loading required package: DiceKriging
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DiceEval/RMA.Rd_%03d_medium.png", width=480, height=480)
> ### Name: RMA
> ### Title: Relative Maximal Absolute Error
> ### Aliases: RMA
> ### Keywords: models
> 
> ### ** Examples
> 
> X     <- seq(-1,1,0.1)
> Y     <- 3*X + rnorm(length(X),0,0.5)
> Ypred <- 3*X
> print(RMA(Y,Ypred))
$max.value
[1] 0.6304328

$max.data
[1] 2

$index
 [1]  2 10 15  3  5 20 12  6 17 14  8 19 13 11 18  7  9 16  1 21  4

$error
 [1] 0.63043285 0.58717198 0.47953858 0.47353435 0.39140382 0.36109144
 [7] 0.32442157 0.29470489 0.28670894 0.28029323 0.22279881 0.18748803
[13] 0.17552278 0.15985644 0.08411707 0.07953145 0.07743252 0.06232748
[19] 0.05640422 0.05620275 0.03838084

> 
> # Illustration on Branin function
> Branin <- function(x1,x2) {
+    x1 <- x1*15-5   
+    x2 <- x2*15
+    (x2 - 5/(4*pi^2)*(x1^2) + 5/pi*x1 - 6)^2 + 10*(1 - 1/(8*pi))*cos(x1) + 10
+ }
> X <- matrix(runif(24),ncol=2,nrow=12)
> Z <- Branin(X[,1],X[,2])
> Y <- (Z-mean(Z))/sd(Z)
> 
> # Fitting of a Linear model on the data (X,Y)
> modLm <- modelFit(X,Y,type = "Linear",formula=Y~X1+X2+X1:X2+I(X1^2)+I(X2^2))
> 
> # Prediction on a grid
> u <- seq(0,1,0.1)
> Y_test_real <- Branin(expand.grid(u,u)[,1],expand.grid(u,u)[,2])
> Y_test_pred <- modelPredict(modLm,expand.grid(u,u))
> Y_error <- matrix(abs(Y_test_pred-(Y_test_real-mean(Z))/sd(Z)),length(u),length(u))
> contour(u, u, Y_error,45)
> Y_pred <- modelPredict(modLm,X)
> out <- RMA(Y,Y_pred)
> for (i in 1:dim(X)[1]){
+     points(X[out$index[i],1],X[out$index[i],2],pch=19,col='red',cex=out$error[i]*10)
+ }
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>