Learn R Programming

berryFunctions (version 1.5.2)

rsquare: R squared

Description

R squared (coefficient of determination)

Usage

rsquare(a,b)

Arguments

a
Vector with values.
b
Another vector of the same length.

Value

  • Numeric.

Details

Formula used: cor(a,b)^2

References

http://en.wikipedia.org/wiki/R-squared

See Also

rmse, cor, lm

Examples

Run this code
x <- rnorm(20)
y <- 2*x + rnorm(20)
plot(x,y)
rsquare(x,y)

r2 <- sapply(1:10000, function(i){
   x <- rnorm(20);  y <- 2*x + rnorm(20);  rsquare(x,y) })
hist(r2, breaks=70, col=5,
main= "10'000 times   x <- rnorm(20);  y <- 2*x + rnorm(20);  rsquare(x,y)")

Run the code above in your browser using DataLab