# NOT RUN {
data(simdat)
# }
# NOT RUN {
m1 <- bam(Y ~ Group + s(Time, by=Group), data=simdat)
# Time value is automatically set:
pp <- get_predictions(m1, cond=list(Group='Adults'))
head(pp)
# Range of time values:
pp <- get_predictions(m1,
cond=list(Group='Adults', Time=seq(0,500,length=100)))
# plot:
emptyPlot(500, range(pp$fit), h=0)
plot_error(pp$Time, pp$fit, pp$CI, shade=TRUE, xpd=TRUE)
# Warning: also unrealistical values are possible
range(simdat$Time)
pp <- get_predictions(m1,
cond=list(Group='Adults', Time=seq(-500,0,length=100)))
# plot of predictions that are not supported by data:
emptyPlot(c(-500,0), range(pp$fit), h=0)
plot_error(pp$Time, pp$fit, pp$CI, shade=TRUE, xpd=TRUE)
m2 <- bam(Y ~ Group + s(Time, by=Group)
+ s(Time, Subject, bs='fs', m=1),
data=simdat, discrete=TRUE)
# Simultaneous CI vs pointwise CI
# NOTE: USE AT LEST 200 DATAPOINTS FOR SIMULTANEOUS CI
pp <- get_predictions(m2,
cond=list(Group='Adults', Time=seq(0,2000,length=200)),
rm.ranef=TRUE, sim.ci=TRUE)
head(pp)
# plot:
emptyPlot(2000, range(pp$fit), h=0)
plot_error(pp$Time, pp$fit, pp$CI, shade=TRUE, xpd=TRUE)
plot_error(pp$Time, pp$fit, pp$sim.CI, shade=FALSE, col=2, xpd=TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab