modelr-reexport: Reexport of modelr functions

modelr-reexportR Documentation

Reexport of modelr functions

Description

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.

Usage

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)

Arguments

data

A data frame

model

A model that has a predict() method.

var

A string with the name of the predictions or residuals variable (by default, it is "pred" and "resid" respectively)

type

If the model's predict() method has a ⁠type=⁠ argument, you can give it here.

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

Value

A function with argument x that returns the values predicted by the model for these values of x.

Examples

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

SciViews/modelit documentation built on Nov. 24, 2024, 10:23 a.m.