library(mgcv)
set.seed(10)
sim_data <- gamSim(4)
model_1 <- gam(y ~ s(x2, by = fac) + s(x0), data = sim_data)
preds_1 <- predict_gam(model_1, length_out = 50, exclude_terms = "s(x0)")
plot(preds_1, "x2")
preds_2 <- predict_gam(model_1, length_out = 100, values = list(x0 = 0))
plot(preds_2, "x2", "fac")
library(ggplot2)
plot(preds_2, "x2", "fac") +
scale_fill_brewer(type = "qual") +
scale_color_brewer(type = "qual")
# Plotting tensor product smooths/interactions
model_2 <- gam(y ~ te(x0, x2, by = fac), data = sim_data)
preds_3 <- predict_gam(model_2)
preds_3 %>% plot(series = c("x0", "x2"), comparison = "fac")
Run the code above in your browser using DataLab