R2 | R Documentation |
It estimates the R2 for a continuous predicted-observed dataset.
R2(data = NULL, obs, pred, tidy = FALSE, na.rm = TRUE)
data |
(Optional) argument to call an existing data frame containing the data. |
obs |
Vector with observed values (numeric). |
pred |
Vector with predicted values (numeric). |
tidy |
Logical operator (TRUE/FALSE) to decide the type of return. TRUE returns a data.frame, FALSE returns a list; Default : FALSE. |
na.rm |
Logic argument to remove rows with missing values (NA). Default is na.rm = TRUE. |
The R2 is one of the most widely used metrics evaluating models performance. R2 is appropriate to estimate the strength of linear association between two variables. It is positively bounded to 1, but it may produce negative values. The closer to 1 the better linear association between predictions and observations. However, R2 presents a major flaw for prediction performance evaluation: it is not sensitive to lack of accuracy (additive or proportional bias). Thus, R2 only measures precision, but it does not account for accuracy of the predictions. For the formula and more details, see online-documentation
an object of class numeric
within a list
(if tidy = FALSE) or within a
data frame
(if tidy = TRUE).
Yang et al. (2014). An evaluation of the statistical methods for testing the performance of crop models with observed data. Agric. Syst. 127, 81-89. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.agsy.2014.01.008")}
set.seed(1)
X <- rnorm(n = 100, mean = 0, sd = 10)
Y <- X + rnorm(n=100, mean = 0, sd = 3)
R2(obs = X, pred = Y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.