Learn R Programming

BAT (version 2.9.6)

r2: Model R2.

Description

Calculates R2 from the summed squared differences between observed and estimated values.

Usage

r2(obs, est = NULL, param = 0)

Value

The r2 value.

Arguments

obs

Either a model or a vector with observed values.

est

A vector with estimated values. Only used if obs is not a model.

param

Number of parameters in the model to calculate the adjusted R2 if > 0. If obs is a model param will be ignored and the number of parameters will be calculated from the model.

Details

Useful for models or functions that do not provide r2 values.

Examples

Run this code
obs = c(1,4,5,6)
est = c(0,1,4,7)

#example using values
r2(obs, est)
r2(obs, est, param = 1)

#example using model
mod = lm(obs ~ est)
r2(mod)
summary(mod)$r.squared
r2(mod, param = 1)
summary(mod)$adj.r.squared

Run the code above in your browser using DataLab