library(ggeffects)
set.seed(1234)
x <- rnorm(200)
z <- rnorm(200)
# quadratic relationship
y <- 2 * x + x^2 + 4 * z + rnorm(200)
d <- data.frame(x, y, z)
model <- lm(y ~ x + z, data = d)
pr <- predict_response(model, c("x [all]", "z"))
head(residualize_over_grid(pr, model))
Run the code above in your browser using DataLab