# NOT RUN {
data(simdat)
# }
# NOT RUN {
# Model with random effect and interactions:
m1 <- bam(Y ~ te(Time, Trial)+s(Time, Subject, bs='fs', m=1),
data=simdat, discrete=TRUE)
# 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, discrete=TRUE)
# 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, because Subjects
# fall in only one group. Just for illustration purposes!
plot_smooth(m2, view='Time', plot_all=c('Group', 'Subject'))
# Clearly visible difference in confidence interval, because
# a01 does not occur in Group 'Children':
# (Note that this plot generates warning)
plot_smooth(m2, view='Time', plot_all=c('Group', 'Subject'), cond=list(Subject='a01'))
# Using sim.ci: simultaneous CI instead of pointwise CI
dev.new(width=8, height=4) # use x11(,8,4) on Linux
par(mfrow=c(1,2))
plot_smooth(m2, view='Time', plot_all='Group', rm.ranef=TRUE)
plot_smooth(m2, view='Time', rm.ranef=TRUE, plot_all='Group', sim.ci=TRUE,
add=TRUE, shade=FALSE, xpd=TRUE)
plot_smooth(m2, view='Time', rm.ranef=TRUE, sim.ci=TRUE, col='red')
# 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))
# }
# NOT RUN {
# and for a quick overview of plotfunctions:
vignette('overview', package='itsadug')
# }
Run the code above in your browser using DataLab