Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate relative RMSE in r

To get the relative RMSE of my predicted model and true values,I used the code

ratio<-prediction1/ISEtrain  

rRMSE1<-sqrt(mean((1-ratio)^2))

but I failed , with the output "[1] Inf". What is wrong with my code?

Thank you !

like image 495
nanshen xiaowa Avatar asked Mar 12 '23 23:03

nanshen xiaowa


2 Answers

You are getting Inf because you are dividing by zero.

Following Wikipedia's definition of the normalized RMSE (https://en.wikipedia.org/wiki/Root-mean-square_deviation), you probably want:

sqrt( mean( (prediction1-ISEtrain)^2) ) / ( max(ISEtrain)-min(ISEtrain) )
like image 56
David Heckmann Avatar answered Mar 16 '23 05:03

David Heckmann


There are two ways to get relative RMSE (or normalized RMSE):

  1. Divide RMSE by standard deviation of observed values:

    sqrt(mean((prediction1 - ISEtrain)^2)) / sd(ISEtrain)
    
  2. Divide RMSE by difference between max and min of observed values (as David mentioned):

    sqrt(mean((prediction1 - ISEtrain)^2)) / diff(range(ISEtrain))
    

Both methods exist in "hydroGOF" package and do exactly the same but proper function name to do so is nrmse() not rmse() as mentioned previously.

library("hydroGOF")

nrmse(prediction1, ISEtrain, norm = "sd")
nrmse(prediction1, ISEtrain, norm = "maxmin")
like image 43
George Shimanovsky Avatar answered Mar 16 '23 03:03

George Shimanovsky