data(simdat)
# Model with random effect and interactions:
m1 <- bam(Y ~ te(Time, Trial)+s(Time, Subject, bs='fs', m=1),
data=simdat)
# Default plot produces only surface of Time x Trial:
plot(m1, select=1)
# Only the Time component:
plot_smooth(m1, view="Time")
# Note the summary that is printed.
# without random effects:
plot_smooth(m1, view="Time", rm.ranef=TRUE)
# Plot summed effects:
dev.new(width=8, height=4) # use x11(,8,4) on Linux
par(mfrow=c(1,2))
fvisgam(m1, view=c("Time", "Trial"),
plot.type='contour', color='topo', main='interaction',
rm.ranef=TRUE)
arrows(x0=0, x1=2200, y0=-5, y1=-5, col='red',
code=2, length=.1, lwd=2, xpd=TRUE)
plot_smooth(m1, view='Time', cond=list(Trial=-5),
main='Trial=-5', rm.ranef=TRUE)
# Model with random effect and interactions:
m2 <- bam(Y ~ Group + s(Time, by=Group)
+s(Time, Subject, bs='fs', m=1),
data=simdat)
# Plot all levels of a predictor:
plot_smooth(m2, view='Time', plot_all="Group",
rm.ranef=TRUE)
# It also possible to combine predictors in plot_all.
# Note: this is not a meaningfull plot,
# just for illustration purposes!
plot_smooth(m2, view='Time', plot_all=c("Group", "Subject"))
# Using transform
# Plot log-transformed dependent predictor on original scale:
plot_smooth(m1, view="Time", rm.ranef=TRUE, transform=exp)
# Notes on transform.view:
# This will generate an error, because x-values <= 0 will result in NaN:
plot_smooth(m1, view="Time", rm.ranef=TRUE, transform.view=log)
# adjusting the x-axis helps:
plot_smooth(m1, view="Time", rm.ranef=TRUE, transform.view=log,
xlim=c(1,2000))
# and for a quick overview of plotfunctions:
vignette("overview", package="itsadug")
Run the code above in your browser using DataLab