modelr-reexport | R Documentation |
add_predictions()
and add_residuals()
are pipe-friendly
functions to add predictions or residuals to a data frame.
geom_ref_line()
adds a vertical of horizontal reference line. rmse()
(the root-mean-squared-error), [mae[]] (the mean absolute error), qae()
(the quantiles of absolute error) and rsquare()
(the variance of the
predictions divided by the variance of the response) are useful model
metrics.
add_predictions(data, model, var = "pred", type = NULL)
add_residuals(data, model, var = "resid")
geom_ref_line(h, v, color = "red", colour = color, size = 1)
rmse(model, data)
mae(model, data)
qae(model, data, probs = c(0.05, 0.25, 0.5, 0.75, 0.95))
rsquare(model, data)
data |
A data frame |
model |
A model that has a |
var |
A string with the name of the predictions or residuals variable
(by default, it is |
type |
If the model's |
h |
Position of the horizontal reference line |
v |
Position of the vertical reference line |
color |
The color of the reference line |
colour |
Same as above (use the one you prefer) |
size |
The width of the reference line |
probs |
A numeric vector of probabilities |
A function with argument x
that returns the values predicted by the
model for these values of x
.
data(trees, package = "datasets")
trees_lm <- lm(Volume ~ Girth + I(Girth^2), data = trees)
rmse(trees_lm, trees)
rsquare(trees_lm, trees)
mae(trees_lm, trees)
qae(trees_lm, trees, probs = c(0, 0.25, 0.5, 0.75, 1)) # Resids five numbers
add_predictions(trees, trees_lm)
add_residuals(trees, trees_lm)
library(chart)
chart(trees_lm) +
geom_ref_line(h = 0) # Not particularly useful here, just an example
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.