I created several GAMs which include non-smoothed (parametric), continuous variables (besides the s() parameters).
I would like to plot the parametric, continuous variables of two models together. For example:
g1 <- x ~ s(y) + z
g2 <- x ~ s(y1) + z
I want to have z
(continuous variable) from models g1
and g2
in the same plot, similar to what we can do with the gratia::compare_smooths()
. But this function works only for the smoothed parameters, as far as I know. I see only the option for plotting them individually. Any suggestions?
Additionally, if I have two models with the formula:
g3 <- x ~ s(y) + z
g4 <- x ~ s(y1) + z1
Is it possible to get z
and z1
in the same plot?
Thanks in advance!
You could use any of the many packages that produce predicted effects (I use
ggeffects
below, but others such aseffects
andmarginaleffects
would likely work too, though with a different workflow. You can get the effect ofz
from each model, put the two datasets together identifying which model each effect comes from and then make the plot:Created on 2023-04-18 with reprex v2.0.2