Calculates an R-squared value. Vectors for observed and predicted values must be the same length. Missing values are allowed. Any observed-predicted pairs with missing values are removed before computations are done.

getR2(obs, pred)

Arguments

obs

Vector of observed values.

pred

Vector of predicted values.

Value

The R-squared value.

Details

Returned R-squared might be negative. This indicates that the prediction is worse than using the mean. This function specifically computes: $$R^2=1-SS_{err}/SS_{y}$$ which is equivalent to $$R^2=1-MSE/Var_{y}$$

See also