data(simdat)
# Model with interaction:
m1 <- bam(Y ~ s(Time) + s(Trial)
+ti(Time, Trial),
data=simdat)
# get partial prediction of the ti-term:
pp <- get_modelterm(m1, select=3, as.data.frame=TRUE)
head(pp)
# plot surface:
plotsurface(pp, view=c('Time', "Trial"), predictor='fit')
# ...is the same as:
pvisgam(m1,view=c('Time', "Trial"), select=3)
# add main effects of Time and Trial:
pp1 <- get_modelterm(m1, select=1, as.data.frame=TRUE)
pp2 <- get_modelterm(m1, select=2, as.data.frame=TRUE)
pp$fit.sum <- pp$fit + rep(pp1$fit, 30) + rep(pp2$fit, each=30)
plotsurface(pp, view=c('Time', "Trial"), predictor='fit.sum')
# ...is not same as fvisgam, because in previous plot the intercept
# is not included:
fvisgam(m1, view=c('Time', "Trial"))
# This is same as fvisgam:
pp <- get_predictions(m1, cond=list(Time=seq(0,2000, length=30),
Trial=seq(-10,10,length=30)))
plotsurface(pp, view=c('Time', "Trial"), predictor='fit', valCI='CI')
# Just contour plot:
plotsurface(pp, view=c('Time', "Trial"), predictor='fit', valCI='CI',
main='contour', color=NULL, col=1, add.color.legend=FALSE)
Run the code above in your browser using DataLab