# NOT RUN {
data(simdat)
# }
# NOT RUN {
# Model with random effect and interactions:
m1 <- bam(Y ~ s(Time) + s(Trial)
+ti(Time, Trial)
+s(Time, Subject, bs='fs', m=1),
data=simdat)
# Get data frame with predictions:
p <- get_modelterm(m1, select=1)
emptyPlot(range(p$terms), range(p$fit), h=0)
plot_error(p$terms, p$fit, p$se.fit, shade=TRUE, xpd=TRUE)
# Plot random effects in separate panels:
pp <- get_modelterm(m1, select=4, as.data.frame=TRUE)
require(lattice)
lattice::xyplot(fit~Time|Subject,
data=pp, type='l',
xlab='Time', ylab='Partial effect')
# Plot selection of subjects:
pp <- get_modelterm(m1, select=4,
cond=list(Subject=c('a01', 'a03', 'c16')),
as.data.frame=TRUE)
lattice::xyplot(fit~Time|Subject,
data=pp, type='l',
xlab='Time', ylab='Partial effect')
# Or using the package ggplot2:
require(ggplot2)
pp <- get_modelterm(m1, select=4, as.data.frame=TRUE)
pg <- ggplot2::qplot(Time, fit, data = pp,
geom = c('point', 'line'), colour = Subject)
pg + ggplot2::guides(col = guide_legend(nrow = 18))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab