R/MEF.R

MEF <-function(
  ##title<< Compute the modelling efficiency (MEF)
  prediction    ##<< numeric: array 1
  , observation ##<< numeric: array 2
)
  ##description<< Calculates the modelling efficiency (MEF) of two arrays 
{
  if (length(prediction) != length(observation))
    stop('Vectors need to of the same length!')
  
  valid <- !is.na(prediction) &  !is.na(observation)
  prediction <-  prediction[valid]
  observation  <-  observation[valid]

  
  if (length(prediction) == 0 | length(observation) == 0) {
    value_out = NaN
  } else {
    value_out=  (1 - (sum(( prediction  - observation) ^ 2)) / 
          (sum((observation - mean(observation)) ^ 2)))
  }     
  ##value<< MEF of the two vectors
  return(value_out)
}

Try the JBTools package in your browser

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

JBTools documentation built on May 2, 2019, 8:20 a.m.