| metrics | R Documentation |
Calculation of fit metrics for observed and expected numeric variables
(e.g. R^2, RMSE, MAE, MAPE).
metrics(
observed,
expected,
plot = TRUE,
plot.main = "Observed vs. expected",
xlab = "Observed",
ylab = "Expected",
point.col = "blue",
point.pch = 19,
line.col = "red",
plot_residuals.main = "Residuals",
legend.cex = 0.7
)
observed |
Numeric vector of observed values. |
expected |
Numeric vector of expected or predicted values. |
plot |
Logical. If |
plot.main |
Character string. Title of the observed vs. expected plot. |
xlab |
Character string. Label of the x-axis. |
ylab |
Character string. Label of the y-axis. |
point.col |
Color of points in the observed vs. expected plot. |
point.pch |
Plotting character used for points. |
line.col |
Color of the identity line ( |
plot_residuals.main |
Character string. Title of the residuals bar plot. |
legend.cex |
Numeric. Character expansion factor for legends. |
The function computes several goodness-of-fit metrics comparing observed and
expected numeric values. In addition to classical error measures such as
mean squared error (MSE), root mean squared error (RMSE), mean absolute error (MAE),
and mean absolute percentage error (MAPE), the coefficient of determination
(R^2) is calculated.
If plot = TRUE, the function produces:
a scatter plot of observed versus expected values including the identity line,
a bar plot of relative residual frequencies.
A list with two elements:
fit_metrics |
A |
observed_expected |
A |
Thomas Wieland
Boehmke B, Greenwell B (2020). Hands-On Machine Learning with R (1st ed.). Taylor & Francis, New York, NY.
metrics
obs <- c(10, 12, 15, 18, 20)
exp <- c(11, 13, 14, 17, 21)
metrics(
observed = obs,
expected = exp
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.