Skip to contents

R2() is the model-efficiency coefficient and is identical to nse() and mec() in this package. It compares the squared prediction error with the squared deviation of the observations from their mean:

Usage

R2(obs, pred, na.rm = TRUE)

Arguments

obs

Numeric observation vector.

pred

Numeric prediction vector paired with obs.

na.rm

Logical; remove incomplete pairs?

Value

One numeric value. The optimum is 1; values may be negative and are not bounded below.

Details

$$ R^2 = 1 - \frac{ \sum_{i=1}^{n}(obs_i-pred_i)^2 }{ \sum_{i=1}^{n}(obs_i-\bar{obs})^2 }. $$

The statistic has a direct benchmark interpretation. A value of 1 indicates perfect agreement between observations and predictions. A value of 0 means that predicting the observed mean for every observation performs equally well according to squared error. Negative values indicate that the observed mean provides a better prediction than the model.

Uppercase R2() must not be confused with lowercase r2(), which is the squared Pearson correlation coefficient. Squared Pearson correlation measures the strength of linear association and is insensitive to additive and proportional differences between observations and predictions. It can therefore equal one even for strongly biased predictions. In contrast, R2() is sensitive to deviations from the line of equality and therefore measures predictive performance rather than linear association alone.

Because R2() is based on squared errors, individual large prediction errors can have a disproportionate influence on its value. It should therefore generally be interpreted together with complementary measures such as bias(), mae(), rmse(), and r2() rather than as a standalone measure of predictive performance.

R2() returns NA with a warning when fewer than two valid observation- prediction pairs remain or when the observations have zero variance. Missing-value handling follows bias().

References

Wadoux, A. M. J.-C., Walvoort, D. J. J. and Brus, D. J. (2022). An integrated approach for the evaluation of quantitative soil maps through Taylor and solar diagrams. Geoderma, 405, 115332. doi:10.1016/j.geoderma.2021.115332

Janssen, P. H. M. and Heuberger, P. S. C. (1995). Calibration of process-oriented models. Ecological Modelling, 83, 55-66. doi:10.1016/0304-3800(95)00084-9

Nash, J. E. and Sutcliffe, J. V. (1970). River flow forecasting through conceptual models part I: A discussion of principles. Journal of Hydrology, 10, 282-290. doi:10.1016/0022-1694(70)90255-6

Legates, D. R. and McCabe, G. J. (1999). Evaluating the use of goodness-of-fit measures in hydrologic and hydroclimatic model validation. Water Resources Research, 35(1), 233-241. doi:10.1029/1998WR900018

See also

Examples

obs <- c(1, 2, 3, 4, 5)

# Perfect predictions
R2(obs, obs)
#> [1] 1

# Additive bias: r2 remains 1, whereas R2 decreases
pred <- obs + 1
r2(obs, pred)
#> [1] 1
R2(obs, pred)
#> [1] 0.5

# Predictions can perform worse than using the observed mean
R2(obs, rev(obs))
#> [1] -3