# NOT RUN {
# load data:
data(simdat)
# }
# NOT RUN {
# Condition as factor, to have a random intercept
# for illustration purposes:
simdat$Condition <- as.factor(simdat$Condition)
# Model with random effect and interactions:
m2 <- bam(Y ~ s(Time) + s(Trial)
+ ti(Time, Trial)
+ s(Condition, bs='re')
+ s(Time, Subject, bs='fs', m=1),
data=simdat)
# extract with wrong select value:
newd <- inspect_random(m2, select=4)
# results in warning, automatically takes select=5
head(newd)
inspect_random(m2, select=5, cond=list(Subject=c('a01','a02','a03')))
# Alternatively, fix random effect of Condition, and plot
# random effects for subjects with lattice:
newd <- inspect_random(m2, select=5,
cond=list(Subject=unique(simdat[simdat$Condition==0,'Subject'])),
plot=FALSE)
# Make lattice plot:
require(lattice)
lattice::xyplot(fit~Time | Subject,
data=newd, type='l',
xlab='Time', ylab='Partial effect')
# Using argument 'fun':
inspect_random(m2, select=5, fun=mean,
cond=list(Subject=unique(simdat[simdat$Condition==0,'Subject'])))
inspect_random(m2, select=5, fun=mean,
cond=list(Subject=unique(simdat[simdat$Condition==2,'Subject'])),
col='red', add=TRUE)
# }
# NOT RUN {
# see the vignette for examples:
vignette('overview', package='itsadug')
# }
Run the code above in your browser using DataLab