One-stop shopping to fit a model and return the model output on the training data.
Usage
model_values(data, tilde, family = c("linear", "prob", "counts"))
Arguments
- data
A data frame containing the training data. When used with
mutate()
,data
will hold the model specification, instead oftilde
.- tilde
A model specification in the form of a tilde expression
- family
The type of model architecture:
"linear"
,"prob"
, or"counts"
Value
A vector (not a data frame) of the model evaluated on the training data.
This is intended mainly for use within mutate()
, so that a general model can be used in
the place of simple reduction verbs like mean()
, median()
Examples
mtcars |> mutate(mpg_mod = model_values(mpg ~ hp + wt)) |> select(hp, wt, mpg_mod) |> head()
#> hp wt mpg_mod
#> Mazda RX4 110 2.620 23.57233
#> Mazda RX4 Wag 110 2.875 22.58348
#> Datsun 710 93 2.320 25.27582
#> Hornet 4 Drive 110 3.215 21.26502
#> Hornet Sportabout 175 3.440 18.32727
#> Valiant 105 3.460 20.47382