parse_model

It parses a fitted R model's structure and extracts the components needed to create a dplyr formula for prediction. The function also creates a data frame using an specific format so that other functions in the future can also pass parsed tables to a given formula creating function.

parse_model(model)

Arguments

model

An R model object. It currently supports lm(), glm() and randomForest() models.

Examples

library(dplyr) df <- mutate(mtcars, cyl = paste0("cyl", cyl)) model <- lm(mpg ~ wt + cyl * disp, offset = am, data = df) parse_model(model)
#> # A tibble: 13 x 14 #> labels estimate type field_1 field_2 field_3 qr_1 qr_2 qr_3 #> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> #> 1 (Intercep~ 39.4 term <NA> <NA> <NA> - 0.177 - 0.591 - 0.126 #> 2 wt - 1.62 term <NA> <NA> {{:}} 0 0.184 0.0101 #> 3 cylcyl6 -18.4 term cyl6 <NA> <NA> 0 0 0.428 #> 4 cylcyl8 -16.2 term cyl8 <NA> <NA> 0 0 0 #> 5 disp - 0.0930 term <NA> {{:}} <NA> 0 0 0 #> 6 cylcyl6:d~ 0.111 term cyl6 {{:}} <NA> 0 0 0 #> 7 cylcyl8:d~ 0.0880 term cyl8 {{:}} <NA> 0 0 0 #> 8 labels 0 variab~ cyl disp wt NA NA NA #> 9 model NA variab~ <NA> <NA> <NA> NA NA NA #> 10 version NA variab~ <NA> <NA> <NA> NA NA NA #> 11 residual NA variab~ <NA> <NA> <NA> NA NA NA #> 12 sigma2 NA variab~ <NA> <NA> <NA> NA NA NA #> 13 offset NA variab~ <NA> <NA> <NA> NA NA NA #> # ... with 5 more variables: qr_4 <dbl>, qr_5 <dbl>, qr_6 <dbl>, qr_7 <dbl>, #> # vals <chr>
Skip to content This repository Search Pull requests Issues Marketplace Explore @edgararuiz Sign out Unwatch 9 Star 5 Fork 5 rstudio/db.rstudio.com Code Issues 6 Pull requests 0 Projects 0 Wiki Insights Settings Tree: 7a7548589f Find file Copy pathdb.rstudio.com/themes/hugo-material-docs/layouts/partials/footer_js.html 7a75485 on Apr 22, 2017 @edgararuiz edgararuiz Fix to theme's scrollspy 1 contributor RawBlameHistory 84 lines (73 sloc) 2.83 KB © 2018 GitHub, Inc. Terms Privacy Security Status Help Contact GitHub API Training Shop Blog About