AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
But there is no justification that it can measure the goodness of out-of-sample prediction. R squared can be a (but not the best) measure of "goodness of fit". But only when such an estimate is statistically justified. The R squared is reported by summary functions associated with regression functions. R - Calculate Test MSE given a trained model from a training set and a test set.So it is a weak or even useless measure on "goodness of prediction". Think twice!! R squared between x + a and y + b are identical for any constant shift a and b. R squared between two arbitrary vectors x and y (of the same length) is just a goodness measure of their linear relationship. Lemma 1: a regression y ~ x is equivalent to y - mean(y) ~ x - mean(x) Sandipan's answer will return you exactly the same result (see the following proof), but as it stands it appears more readable (due to the evident $r.squared).īasically we fit a linear regression of y over x, and compute the ratio of regression sum of squares to total sum of squares. So you can define you function as: rsq <- function (x, y) cor(x, y) ^ 2 R squared between two vectors is just the square of their correlation. You need a little statistical knowledge to see this.
0 Comments
Read More
Leave a Reply. |