Computes accuracy measurements.

accuracy(pred, obs, na.rm = FALSE, tol = sqrt(.Machine$double.eps))

Arguments

pred

a numeric vector with the predicted values.

obs

a numeric vector with the observed values.

na.rm

a logical indicating whether NA values should be stripped before the computation proceeds.

tol

divide underflow tolerance.

Value

Returns a named vector with the following components:

  • me mean error

  • rmse root mean squared error

  • mae mean absolute error

  • mpe mean percent error

  • mape mean absolute percent error

  • r.squared pseudo R-squared

See also

Examples

set.seed(1)
nobs <- nrow(bodyfat)
itrain <- sample(nobs, 0.8 * nobs)
train <- bodyfat[itrain, ]
test <- bodyfat[-itrain, ]
fit <- lm(bodyfat ~ abdomen + wrist, data = train)
pred <- predict(fit, newdata = test)
obs <- test$bodyfat
pred.plot(pred, obs)

accuracy(pred, obs)
#>           me         rmse          mae          mpe         mape    r.squared 
#>  1.589182743  4.399764982  3.688874689  0.002059976 21.308275784  0.700759788