0% found this document useful (0 votes)
87 views

Accuracy Function - R Documentation

The accuracy function calculates and compares the accuracy of different model fits. It takes a list of model fits as the first argument and calculates metrics like mean absolute error (MAE) to evaluate how close the model predictions are to the actual values. By default, it will also produce a plot to visually compare the models. The documentation provides examples comparing linear models, generalized linear models, and non-linear least squares fits, as well as examples with perfect and poor fits to demonstrate the accuracy metrics.

Uploaded by

Ayad M Al-Awsi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Accuracy Function - R Documentation

The accuracy function calculates and compares the accuracy of different model fits. It takes a list of model fits as the first argument and calculates metrics like mean absolute error (MAE) to evaluate how close the model predictions are to the actual values. By default, it will also produce a plot to visually compare the models. The documentation provides examples comparing linear models, generalized linear models, and non-linear least squares fits, as well as examples with perfect and poor fits to demonstrate the accuracy metrics.

Uploaded by

Ayad M Al-Awsi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

accuracy function | R Documentation https://www.rdocumentation.org/packages/rcompanion/versions/2.3.25/t...

accuracy(fits, plotit = TRUE, digits = 3, ...)

TRUE

plot

MAE = mean(abs(predy - actual))

1 of 3 4/12/2020, 4:45 AM
accuracy function | R Documentation https://www.rdocumentation.org/packages/rcompanion/versions/2.3.25/t...

lm

compareLM compareGLM nagelkerke

# NOT RUN {
data(BrendonSmall)
BrendonSmall$Calories = as.numeric(BrendonSmall$Calories)
BrendonSmall$Calories2 = BrendonSmall$Calories ^ 2
model.1 = lm(Sodium ~ Calories, data = BrendonSmall)
model.2 = lm(Sodium ~ Calories + Calories2, data = BrendonSmall)
model.3 = glm(Sodium ~ Calories, data = BrendonSmall, family="Gamma")
quadplat = function(x, a, b, clx) {
ifelse(x < clx, a + b * x + (-0.5*b/clx) * x * x,
a + b * clx + (-0.5*b/clx) * clx * clx)}
model.4 = nls(Sodium ~ quadplat(Calories, a, b, clx),
data = BrendonSmall,
start = list(a=519, b=0.359, clx = 2300))
accuracy(list(model.1, model.2, model.3, model.4), plotit=FALSE)

### Perfect and poor model fits


X = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
Y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)

2 of 3 4/12/2020, 4:45 AM
accuracy function | R Documentation https://www.rdocumentation.org/packages/rcompanion/versions/2.3.25/t...

Z = c(1, 12, 13, 6, 10, 13, 4, 3, 5, 6, 10, 14)


perfect = lm(Y ~ X)
poor = lm(Z ~ X)
accuracy(list(perfect, poor), plotit=FALSE)

# }

3 of 3 4/12/2020, 4:45 AM

You might also like