parse_model: Converts an R model object into a table.

Description Usage Arguments Examples

View source: R/parsemodel.R

Description

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 a specific format so that other functions in the future can also pass parsed tables to a given formula creating function.

Usage

1
parse_model(model)

Arguments

model

An R model object.

Examples

1
2
3
4
library(dplyr)
df <- mutate(mtcars, cyl = paste0("cyl", cyl))
model <- lm(mpg ~ wt + cyl * disp, offset = am, data = df)
parse_model(model)

Example output

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

# 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 (Inte~  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 cylcy~ -18.4    term  cyl6    <NA>    <NA>      0       0       0.428 
 4 cylcy~ -16.2    term  cyl8    <NA>    <NA>      0       0       0     
 5 disp    -0.0930 term  <NA>    {{:}}   <NA>      0       0       0     
 6 cylcy~   0.111  term  cyl6    {{:}}   <NA>      0       0       0     
 7 cylcy~   0.0880 term  cyl8    {{:}}   <NA>      0       0       0     
 8 labels   0      vari~ cyl     disp    wt       NA      NA      NA     
 9 model   NA      vari~ <NA>    <NA>    <NA>     NA      NA      NA     
10 versi~  NA      vari~ <NA>    <NA>    <NA>     NA      NA      NA     
11 resid~  NA      vari~ <NA>    <NA>    <NA>     NA      NA      NA     
12 sigma2  NA      vari~ <NA>    <NA>    <NA>     NA      NA      NA     
13 offset  NA      vari~ <NA>    <NA>    <NA>     NA      NA      NA     
# ... with 5 more variables: qr_4 <dbl>, qr_5 <dbl>, qr_6 <dbl>, qr_7 <dbl>,
#   vals <chr>

tidypredict documentation built on Oct. 28, 2020, 9:07 a.m.