Skip to content

The function generates predictions for all models in a tidyfit.models frame and outputs a tidy frame.

Usage

# S3 method for tidyfit.models
predict(object, newdata, ..., .keep_grid_id = FALSE)

Arguments

object

model.frame created using regress, classify or m

newdata

New values at which predictions are to made

...

currently not used

.keep_grid_id

boolean. By default the grid ID column is dropped, if there is only one unique setting per model or group. .keep_grid_id = TRUE ensures that the column is never dropped.

Value

A 'tibble'.

Details

The function uses the 'model_object' column in a tidyfit.model frame to return predictions using the newdata argument for each model.

When the response variable is found in newdata, it is automatically included as a 'truth' column.

Author

Johann Pfitzinger

Examples

data <- dplyr::group_by(tidyfit::Factor_Industry_Returns, Industry)
fit <- regress(data, Return ~ ., m("lm"), .mask = "Date")
predict(fit, data)
#> # A tibble: 7,080 × 4
#> # Groups:   Industry, model [10]
#>    Industry model prediction truth
#>    <chr>    <chr>      <dbl> <dbl>
#>  1 Durbl    lm        -0.939 -0.22
#>  2 Durbl    lm         6.82   6.55
#>  3 Durbl    lm        -2.15  -0.24
#>  4 Durbl    lm         3.09   9.72
#>  5 Durbl    lm        -0.317 -4.84
#>  6 Durbl    lm         1.94   0.27
#>  7 Durbl    lm         3.69   1.19
#>  8 Durbl    lm         3.00   2.14
#>  9 Durbl    lm         3.26   0.93
#> 10 Durbl    lm        -0.814  1.93
#> # ℹ 7,070 more rows