powered by
Coefficient of determination \(R^{2}\)
R2(Y, Ypred)
a real vector with the values of the output
a real vector with the predicted values at the same inputs
$$\code{R2}= 1 - \frac{SSE}{SST}$$ where \(SSE= \sum_{i=1}^{n} (Y(x_{i}) - \hat{Y}(x_{i})^{2}\) is the residual sum of squares
and \(SST= \sum_{i=1}^{n} (Y(x_{i}) - \bar{Y} )^{2}\) is the total sum of squares.
Note that the order of the input argument is important.
# NOT RUN { X <- seq(-1,1,0.1) Y <- 3*X + rnorm(length(X),0,0.5) Ypred <- 3*X print(R2(Y,Ypred)) # }
Run the code above in your browser using DataLab