tidypredict_to_column

Adds a new column with the results form tidypredict_fit() to a piped command set. If add_interval is set to TRUE, then it will add two additional columns, one for the lower and another for the upper prediction interval bounds.

tidypredict_to_column(df, model, add_interval = FALSE, interval = 0.95,
  vars = c("fit", "upper", "lower"))

Arguments

df

A data.frame or tibble

model

An R model or a parsed model inside a data frame

add_interval

Switch that indicates if the prediction interval columns should be added. Defaults to FALSE

interval

The prediction interval, defaults to 0.95. It is ignored if add_interval is set to FALSE

vars

The name of the variables that this function will produce. It defaults to "fit", "upper", and "lower".

Examples

library(dplyr) df <- mutate(mtcars, cyl = paste0("cyl", cyl)) model <- lm(mpg ~ wt + cyl * disp, offset = am, data = df) df %>% tidypredict_to_column(model, add_interval = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb fit upper #> 1 21.0 cyl6 160.0 110 3.90 2.620 16.46 0 1 4 4 20.69119 26.00630 #> 2 21.0 cyl6 160.0 110 3.90 2.875 17.02 0 1 4 4 20.27830 25.52816 #> 3 22.8 cyl4 108.0 93 3.85 2.320 18.61 1 1 4 1 26.61461 31.62299 #> 4 21.4 cyl6 258.0 110 3.08 3.215 19.44 1 0 3 1 20.52709 26.75735 #> 5 18.7 cyl8 360.0 175 3.15 3.440 17.02 0 0 3 2 15.82795 20.97583 #> 6 18.1 cyl6 225.0 105 2.76 3.460 20.22 1 0 3 1 19.52450 25.02440 #> 7 14.3 cyl8 360.0 245 3.21 3.570 15.84 0 0 3 4 15.61746 20.69633 #> 8 24.4 cyl4 146.7 62 3.69 3.190 20.00 1 0 4 2 20.60766 26.14493 #> 9 22.8 cyl4 140.8 95 3.92 3.150 22.90 1 0 4 2 21.22100 26.63698 #> 10 19.2 cyl6 167.6 123 3.92 3.440 18.30 1 0 4 4 18.50300 23.74995 #> 11 17.8 cyl6 167.6 123 3.92 3.440 18.90 1 0 4 4 18.50300 23.74995 #> 12 16.4 cyl8 275.8 180 3.07 4.070 17.40 0 0 3 3 15.23080 20.66118 #> 13 17.3 cyl8 275.8 180 3.07 3.730 17.60 0 0 3 3 15.78131 21.03825 #> 14 15.2 cyl8 275.8 180 3.07 3.780 18.00 0 0 3 3 15.70036 20.97641 #> 15 10.4 cyl8 472.0 205 2.93 5.250 17.98 0 0 3 4 12.33469 17.84292 #> 16 10.4 cyl8 460.0 215 3.00 5.424 17.82 0 0 3 4 12.11323 17.62078 #> 17 14.7 cyl8 440.0 230 3.23 5.345 17.42 0 0 3 4 12.34160 17.75855 #> 18 32.4 cyl4 78.7 66 4.08 2.200 19.47 1 1 4 1 29.53319 34.82871 #> 19 30.4 cyl4 75.7 52 4.93 1.615 18.52 1 1 4 2 30.75934 36.04173 #> 20 33.9 cyl4 71.1 65 4.22 1.835 19.90 1 1 4 1 30.83082 36.20469 #> 21 21.5 cyl4 120.1 97 3.70 2.465 20.01 1 0 3 1 24.25479 29.33519 #> 22 15.5 cyl8 318.0 150 2.76 3.520 16.87 0 0 3 2 15.90938 20.93389 #> 23 15.2 cyl8 304.0 150 3.15 3.435 17.30 0 0 3 2 16.11733 21.18139 #> 24 13.3 cyl8 350.0 245 3.73 3.840 15.41 0 0 3 4 15.23051 20.20036 #> 25 19.2 cyl8 400.0 175 3.08 3.845 17.05 0 0 3 2 14.97127 20.16232 #> 26 27.3 cyl4 79.0 66 4.08 1.935 18.90 1 1 4 1 29.93437 35.15973 #> 27 26.0 cyl4 120.3 91 4.43 2.140 16.70 0 1 5 2 25.76243 30.92560 #> 28 30.4 cyl4 95.1 113 3.77 1.513 16.90 1 1 5 2 29.12071 34.32546 #> 29 15.8 cyl8 351.0 264 4.22 3.170 14.50 0 1 5 4 17.31033 22.58713 #> 30 19.7 cyl6 145.0 175 3.62 2.770 15.50 0 1 5 6 20.17291 25.62115 #> 31 15.0 cyl8 301.0 335 3.54 3.570 14.60 0 1 5 8 16.91381 21.97875 #> 32 21.4 cyl4 121.0 109 4.11 2.780 18.60 1 1 4 2 24.66107 29.76653 #> lower #> 1 15.376074 #> 2 15.028434 #> 3 21.606232 #> 4 14.296834 #> 5 10.680066 #> 6 14.024609 #> 7 10.538581 #> 8 15.070397 #> 9 15.805026 #> 10 13.256059 #> 11 13.256059 #> 12 9.800409 #> 13 10.524376 #> 14 10.424299 #> 15 6.826451 #> 16 6.605668 #> 17 6.924645 #> 18 24.237658 #> 19 25.476942 #> 20 25.456952 #> 21 19.174399 #> 22 10.884864 #> 23 11.053260 #> 24 10.260663 #> 25 9.780226 #> 26 24.709016 #> 27 20.599260 #> 28 23.915956 #> 29 12.033531 #> 30 14.724658 #> 31 11.848862 #> 32 19.555614
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