# NOT RUN {
data(okc)
# Setup a grid across date but keep the other values fixed
recipe(~ diet + height + date, data = okc) %>%
step_profile(-date, profile = vars(date)) %>%
prep(training = okc, retain = TRUE) %>%
juice
##########
# An *additive* model; not for use when there are interactions or
# other functional relationships between predictors
lin_mod <- lm(mpg ~ poly(disp, 2) + cyl + hp, data = mtcars)
# Show the difference in the two grid creation methods
disp_pctl <- recipe(~ disp + cyl + hp, data = mtcars) %>%
step_profile(-disp, profile = vars(disp)) %>%
prep(training = mtcars, retain = TRUE)
disp_grid <- recipe(~ disp + cyl + hp, data = mtcars) %>%
step_profile(
-disp,
profile = vars(disp),
grid = list(pctl = FALSE, len = 100)
) %>%
prep(training = mtcars, retain = TRUE)
grid_data <- juice(disp_grid)
grid_data <- grid_data %>%
mutate(pred = predict(lin_mod, grid_data),
method = "grid")
pctl_data <- juice(disp_pctl)
pctl_data <- pctl_data %>%
mutate(pred = predict(lin_mod, pctl_data),
method = "percentile")
plot_data <- bind_rows(grid_data, pctl_data)
library(ggplot2)
ggplot(plot_data, aes(x = disp, y = pred)) +
geom_point(alpha = .5, cex = 1) +
facet_wrap(~ method)
# }
Run the code above in your browser using DataLab