tidypredict_interval
It parses a model or uses an already parsed model to return a Tidy Eval formula that can then be used inside a dplyr command.
tidypredict_interval(model, interval = 0.95)
Arguments
model | An R model or a tibble with a parsed model. It currently supports lm() models only. |
interval | The prediction interval, defaults to 0.95 |
Details
The result still has to be added to the fit to obtain the upper bound, and subtracted from fit to obtain the lower bound.
Examples
library(dplyr)
df <- mutate(mtcars, cyl = paste0("cyl", cyl))
model <- lm(mpg ~ wt + cyl * disp, offset = am, data = df)
tidypredict_interval(model)#> (2.0595385527533) * sqrt(((((((((-0.176776695296637) * (-0.176776695296637) *
#> (5.4148660732425)) + (((-0.590557271637747) + ((wt) * (0.183559646169165))) *
#> ((-0.590557271637747) + ((wt) * (0.183559646169165))) * (5.4148660732425))) +
#> ((((-0.126215672528828) + ((wt) * (0.0101118696567173))) +
#> ((ifelse((cyl) == ("cyl6"), 1, 0)) * (0.428266330860589))) *
#> (((-0.126215672528828) + ((wt) * (0.0101118696567173))) +
#> ((ifelse((cyl) == ("cyl6"), 1, 0)) * (0.428266330860589))) *
#> (5.4148660732425))) + (((((0.386215468111418) + ((wt) *
#> (-0.230516217152034))) + ((ifelse((cyl) == ("cyl6"), 1, 0)) *
#> (0.332336511639638))) + ((ifelse((cyl) == ("cyl8"), 1, 0)) *
#> (0.646203930513815))) * ((((0.386215468111418) + ((wt) *
#> (-0.230516217152034))) + ((ifelse((cyl) == ("cyl6"), 1, 0)) *
#> (0.332336511639638))) + ((ifelse((cyl) == ("cyl8"), 1, 0)) *
#> (0.646203930513815))) * (5.4148660732425))) + ((((((-0.153656347809448) +
#> ((wt) * (0.30544122969658))) + ((ifelse((cyl) == ("cyl6"),
#> 1, 0)) * (0.1509332046154))) + ((ifelse((cyl) == ("cyl8"),
#> 1, 0)) * (0.76082884204827))) + ((disp) * (-0.00517897882607625))) *
#> (((((-0.153656347809448) + ((wt) * (0.30544122969658))) +
#> ((ifelse((cyl) == ("cyl6"), 1, 0)) * (0.1509332046154))) +
#> ((ifelse((cyl) == ("cyl8"), 1, 0)) * (0.76082884204827))) +
#> ((disp) * (-0.00517897882607625))) * (5.4148660732425))) +
#> (((((((-0.0223589233233276) + ((wt) * (-0.0955117420011905))) +
#> ((ifelse((cyl) == ("cyl6"), 1, 0)) * (1.88382983909738))) +
#> ((ifelse((cyl) == ("cyl8"), 1, 0)) * (-0.403967380709359))) +
#> ((disp) * (0.00228914819342199))) + (((disp) * (ifelse((cyl) ==
#> ("cyl6"), 1, 0))) * (-0.0108195644963774))) * ((((((-0.0223589233233276) +
#> ((wt) * (-0.0955117420011905))) + ((ifelse((cyl) == ("cyl6"),
#> 1, 0)) * (1.88382983909738))) + ((ifelse((cyl) == ("cyl8"),
#> 1, 0)) * (-0.403967380709359))) + ((disp) * (0.00228914819342199))) +
#> (((disp) * (ifelse((cyl) == ("cyl6"), 1, 0))) * (-0.0108195644963774))) *
#> (5.4148660732425))) + ((((((((1.04062152259755) + ((wt) *
#> (0.156526972089146))) + ((ifelse((cyl) == ("cyl6"), 1, 0)) *
#> (-1.41229176936981))) + ((ifelse((cyl) == ("cyl8"), 1, 0)) *
#> (-1.64546937617655))) + ((disp) * (-0.0133008166085693))) +
#> (((disp) * (ifelse((cyl) == ("cyl6"), 1, 0))) * (0.0126666778900692))) +
#> (((disp) * (ifelse((cyl) == ("cyl8"), 1, 0))) * (0.0132409552398366))) *
#> (((((((1.04062152259755) + ((wt) * (0.156526972089146))) +
#> ((ifelse((cyl) == ("cyl6"), 1, 0)) * (-1.41229176936981))) +
#> ((ifelse((cyl) == ("cyl8"), 1, 0)) * (-1.64546937617655))) +
#> ((disp) * (-0.0133008166085693))) + (((disp) * (ifelse((cyl) ==
#> ("cyl6"), 1, 0))) * (0.0126666778900692))) + (((disp) *
#> (ifelse((cyl) == ("cyl8"), 1, 0))) * (0.0132409552398366))) *
#> (5.4148660732425))) + (5.4148660732425))