# NOT RUN {
# Adjusted Prediction for every row of the original dataset
mod <- lm(mpg ~ hp + factor(cyl), data = mtcars)
pred <- predictions(mod)
head(pred)
# Adjusted Predictions at User-Specified Values of the Regressors
predictions(mod, newdata = datagrid(hp = c(100, 120), cyl = 4))
# Average Adjusted Predictions (AAP)
library(dplyr)
mod <- lm(mpg ~ hp * am * vs, mtcars)
pred <- predictions(mod, newdata = datagrid(am = 0, grid_type = "counterfactual")) %>%
summarize(across(c(predicted, std.error), mean))
predictions(mod, newdata = datagrid(am = 0:1, grid_type = "counterfactual")) %>%
group_by(am) %>%
summarize(across(c(predicted, std.error), mean))
# Conditional Adjusted Predictions
plot_cap(mod, condition = "hp")
# }
Run the code above in your browser using DataLab