Learn R Programming

berryFunctions (version 1.11.0)

rsquare: Rsquare

Description

R squared (coefficient of determination)

Usage

rsquare(a, b, quiet = FALSE)

Arguments

a
Vector with values.
b
Another vector of the same length.
quiet
Should NA-removal warnings be suppressed? Helpful within functions. DEFAULT: FALSE

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