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) + s(Subject, bs='re'),
data=simdat)
# All data points, without clustering:
plot_data(m1, view="Time")
# All data, clustered by Trial (very small dots):
plot_data(m1, view="Time", split_by="Trial",
cex=.25)
# Add a smooth for each trial:
plot_smooth(m1, view="Time", plot_all="Trial",
add=TRUE, rm.ranef=TRUE)
# Add the model predictions in same color:
plot_smooth(m1, view="Time", plot_all="Trial", add=TRUE, rm.ranef=TRUE)
# Alternatively, use data to select events:
plot_data(m1, view="Time", split_by=list(Event=simdat$Event),
type='l')
# which is the same as:
plot_data(m1, view="Time", split_by=list(Subject=simdat$Subject, Trial=simdat$Trial),
type='l')
# Only for Trial=0
plot_data(m1, view="Time", split_by=list(Event=simdat$Event),
cond=list(Trial=0), type='l')
# This is the same:
plot_data(m1, view="Time", split_by="Subject",
cond=list(Trial=0), type='l')
# Add subject smooths:
plot_smooth(m1, view="Time", plot_all="Subject",
cond=list(Trial=0), add=TRUE)
# Change the colors:
plot_data(m1, view="Time", split_by="Subject",
cond=list(Trial=0), type='l', col='gray', alpha=1)
Run the code above in your browser using DataLab