The table present the different plot functions in the packages
mgcv
(Wood 2006,
2011) and itsadug
for visualizing GAMM models.
Partial effect | Sum of all effects | Sum of “fixed” effects1 | |
---|---|---|---|
surface | plot.gam() | vis.gam() | |
pvisgam() | fvisgam() | ||
smooth | plot.gam() | plot_smooth() | |
group estimates | plot.gam()2 | plot_parametric() | |
random smooths | get_random(), inspect_random() |
1: include rm.ranef=TRUE
to zero all random
effects.
2: include all.terms=TRUE
to visualize
parametric terms.
library(itsadug)
library(mgcv)
data(simdat)
## Not run:
# Model with random effect and interactions:
m1 <- bam(Y ~ Group + te(Time, Trial, by=Group)
+ s(Time, Subject, bs='fs', m=1, k=5),
data=simdat)
# Simple model with smooth:
m2 <- bam(Y ~ Group + s(Time, by=Group)
+ s(Subject, bs='re')
+ s(Subject, Time, bs='re'),
data=simdat)
Summary model m1
:
gamtabs(m1, type='html')
Summary model m2
:
gamtabs(m2, type='html')
Plotting the partial effects of
te(Time,Trial):GroupAdults
and
te(Time,Trial):GroupChildren
.
par(mfrow=c(1,2), cex=1.1)
pvisgam(m1, view=c("Time", "Trial"), select=1,
main="Children", zlim=c(-12,12))
pvisgam(m1, view=c("Time", "Trial"), select=2,
main="Adults", zlim=c(-12,12))
Notes:
Plots same data as plot(m1, select=1)
: partial
effects plot, i.e., the plot does not include intercept or any
other effects.
Make sure to set the zlim values the same when comparing surfaces
Use the argument cond
to specify the value of other
predictors in a more complex interaction. For example, for plotting a
modelterm te(A,B,C)
use something like
pvisgam(model, view=c("A", "B"), select=1, cond=list(C=5))
.
Plotting the fitted effects of
te(Time,Trial):GroupAdults
and
te(Time,Trial):GroupChildren
.
par(mfrow=c(1,2), cex=1.1)
fvisgam(m1, view=c("Time", "Trial"), cond=list(Group="Children"),
main="Children", zlim=c(-12,12), rm.ranef=TRUE)
fvisgam(m1, view=c("Time", "Trial"), cond=list(Group="Adults"),
main="Adults", zlim=c(-12,12), rm.ranef=TRUE)