# NOT RUN {
data(simdat)
# }
# NOT RUN {
# no random smooths:
m1 <- bam(Y ~ Group + s(Time, by=Group) + s(Trial) + s(Subject, bs='re'), data=simdat)
diagnostics(m1)
# only plot residuals by predictor:
diagnostics(m1, plot=2)
# without prompts:
par(mfrow=c(2,2))
diagnostics(m1, plot=1:4, ask=FALSE)
# only plot random smooths:
diagnostics(m1, plot=5)
# Note: the plot does not change,
# because there are no random smooths to plot.
# with random smooths
m2 <- bam(Y ~ Group + s(Time, by=Group) + s(Time, Subject, bs='fs', m=1), data=simdat)
diagnostics(m2)
## INSPECTION OF RANDOM SMOOTHS
## ----------------------------
# In this underspecified model (too much smoothing for the interaction)
# part of the effect of Time is captured by the random smooths:
m3 <- bam(Y ~ te(Time, Trial, k=c(3,3)) + s(Time, Subject, bs='fs', m=1), data=simdat)
# The plot shows a clear trend in the average of the random smooths,
# and the amplitude of the mean (!) curve is almost as large as the
# amplitude of the 'fixed' effect of Time:
diagnostics(m3, plot=5, ask=FALSE)
# Compare with the following models:
m4 <- bam(Y ~ te(Time, Trial, k=c(10,5)) + s(Time, Subject, bs='fs', m=1), data=simdat)
diagnostics(m4, plot=5, ask=FALSE)
m5 <- bam(Y ~ s(Time) + s(Trial) + ti(Time, Trial)
+ s(Time, Subject, bs='fs', m=1), data=simdat)
diagnostics(m5, plot=5, ask=FALSE)
# }
Run the code above in your browser using DataLab