oscarperpinan / tdr

Target Diagrams
GNU General Public License v2.0
2 stars 1 forks source link

The Target Diagram is derived from the relation between the unbiased RMSE, MBE, and RMSE. In a Cartesian coordinate system, the x-axis represents the unbiased RMSE (variance of the error), and the y-axis represents the MBE. Therefore the distance between any point to the origin is equal to the RMSE. Because the unbiased RMSE is always positive, the left area of the coordinate system is empty with this scheme. With additional information this region may be also used: the unbiased RMSE is multiplied by the sign of the difference between the standard deviations of model and observations.

The resulting diagram provides three different measures: whether the model overestimates or underestimates (positive or negative values of the MBE on the y-axis, respectively), whether the model standard deviation is larger or smaller than the standard deviation of the measurements (positive or negative values on the x-axis, respectively), and the error performance as quantified by the RMSE represented as the distance to the coordinates origin. This tool is particularly powerful when comparing competing models.

** Installation The stable release of =tdr= can be found at [[http://cran.r-project.org/web/packages/tdr][CRAN]]. The development version is at [[https://github.com/oscarperpinan/tdr][GitHub]].

Install the stable version with:

+begin_src R

install.packages('tdr)

+end_src

To install the development version you need the devtools package:

+begin_src R

install.packages('devtools') devtools::install_github('tdr', 'oscarperpinan')

+end_src

** Usage

There are two main functions, =targetDiagram= for =lattice= users, and =target_diagram= for =ggplot2= users. Both of them have a =data= argument, a =data.frame= with three columns containing the error statistics between a set of models and a vector of observations. This =data.frame= can be produced with the =applyStats= function included in the package.

There is an example data set in the package.

+begin_src R

library(tdr)

data(modelEx)

+end_src

Now in your environment you will find a =data.frame= named =pvModels= and a vector named =pvObs=.

+begin_src R

library(zoo)

z <- zoo(cbind(pvModels, pvObs), order = as.Date(rownames(pvModels))) plot(z, plot.type = 'single', col = c(rep('gray', 22), 'red'), ylab = '', xlab = '')

+end_src

[[file:figs/z.png]]

The =applyStats= function computes the error statistics between models and observations required by the target diagram:

+begin_src R

errModel <- applyStats(pvModels, pvObs)

+end_src

We are ready to display the result, using =lattice=:

+begin_src R

targetDiagram(errModel, groups = model)

+end_src

[[file:figs/targetDiagram.png]]

or =ggplot2=:

+begin_src R

target_diagram(errModel, fill = 'model')

+end_src

[[file:figs/target_diagram.png]]