hzambran / hydroGOF

Goodness-of-fit functions for comparison of simulated and observed hydrological time series
https://CRAN.R-project.org/package=hydroGOF
39 stars 13 forks source link

The R2 metric only works for linear models #16

Closed eugenioLR closed 11 months ago

eugenioLR commented 1 year ago

The R2 metric is implemented as the square of the pearson coefficient, this is only correct when evaluating a linear model.

When you have a non-linear model, the R2 metric will be different, and the one implemented will give incorrect results, which is what was happening to me when i used it.

The correct way of implementing the R2 metric without assuming a linear model is: $$R^2(y, \hat{y}) = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}$$ where $y$ is the real data, $\hat{y}$ is the prediction and $\bar{y}$ is the mean of the samples.

hzambran commented 11 months ago

Thank you very much.

Nos is corrected in the new github version hydroGOF_0.4-10.tar.gz