# NOT RUN {
data(simdat)
# Create grouping predictor for time series:
simdat$Event <- interaction(simdat$Subject, simdat$Trial)
# model without random effects:
m1 <- bam(Y ~ te(Time, Trial),
data=simdat)
plot_modelfit(m1, view='Time', event=simdat$Event)
# colorizing residuals:
plot_modelfit(m1, view='Time', event=simdat$Event, fill=TRUE)
# All trials of one subject:
# }
# NOT RUN {
# this produces error:
plot_modelfit(m1, view='Time', event=simdat$Event,
cond=list(Subject='a01'), n=-1)
# }
# NOT RUN {
# instead try this:
simdat$Subj <- ifelse(simdat$Subject=='a01', TRUE, FALSE)
plot_modelfit(m1, view='Time', event=simdat$Event,
cond=list(Subject=simdat$Subj), n=-1)
# }
# NOT RUN {
# Model with random intercepts for subjects:
m2 <- bam(Y ~ te(Time, Trial)+s(Subject, bs='re'),
data=simdat)
# now selecting a subject works, because it is in the model:
plot_modelfit(m2, view='Time', event=simdat$Event,
cond=list(Subject='a01'), n=-1, ylim=c(-13,13))
# Model with random effect and interactions:
m3 <- bam(Y ~ te(Time, Trial)+s(Time, Subject, bs='fs', m=1),
data=simdat)
plot_modelfit(m3, view='Time', event=simdat$Event,
cond=list(Subject='a01'), n=-1, ylim=c(-13,13))
# }
Run the code above in your browser using DataLab