plot_data: Visualization of the model fit for time series data.

View source: R/inspect.R

plot_dataR Documentation

Visualization of the model fit for time series data.


Plots the data, fitted values, or residuals.


  split_by = NULL,
  cond = NULL,
  input = "data",
  rm.ranef = NULL,
  alpha = NULL,
  col = NULL,
  add = FALSE,
  eegAxis = FALSE,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  ylim = NULL,
  h0 = 0,
  v0 = NULL,
  hide.label = FALSE,
  transform = NULL,
  transform.view = NULL,
  print.summary = getOption("itsadug_print"),



A lm or gam object, produced by gam or bam, lm, glm.


Text string containing the predictor or column in the data to be displayed on the x-axis. Note that variables coerced to factors in the model formula won't work as view variables.


Vector with names of model predictors that determine the time series in the data, or should be used to split the ACF plot by. Alternatively, split_pred can be a named list (each with equal length as the data) that group the data, fitted values or residuals values of x into trials or timeseries events. Generally other columns from the same data frame as the model was fitted on.


A named list of the values to use for the other predictor terms (not in view) or to select specific trials or time series to plot.


Text string: 'data' (default) plots the data, 'resid' plots the model residuals, and 'fitted' plots the fitted values.


Logical: whether or not to include the random effects in the model predictions. Default is TRUE. Relevant for input='fitted' and input='resid' (i.e., whether or not the residuals contain the random effects, TRUE and FALSE respectively ).


Value between 0 and 1 indicating the transparency. A value of 0 is completely transparant, whereas a value of 1 is completely untransparant.


Vector with one color value (i.e., all data points will have the same color), color values for each grouping condition specified in split_by or a vector with color values for each data point.


Logical: whether or not to add the lines/points to an existing plot, or start a new plot (default).


Logical: whether or not to reverse the y-axis, plotting the negative amplitudes upwards as traditionally is done in EEG research. If eeg.axes is TRUE, labels for x- and y-axis are provided, when not provided by the user. Default value is FALSE.


Changing the main title for the plot, see also title.


Changing the label for the x axis, defaults to a description of x.


Changing the label for the y axis, defaults to a description of y.


the y limits of the plot.


A vector indicating where to add solid horizontal lines for reference. By default no values provided.


A vector indicating where to add dotted vertical lines for reference. By default no values provided.


Logical: whether or not to hide the label (i.e., 'fitted values'). Default is FALSE.


Function for transforming the fitted values. Default is NULL.


Function for transforming the view values. Default is NULL.


Logical: whether or not to print a summary. Default set to the print info messages option (see infoMessages).


other options to pass on to lines and plot, see par


This function plots the fitted effects, including intercept and other predictors.


Jacolien van Rij, idea of Tino Sering

See Also

Other Functions for model inspection: dispersion(), fvisgam(), gamtabs(), inspect_random(), plot_parametric(), plot_smooth(), plot_topo(), pvisgam()



## Not run: 
# 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'),

# 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',
# 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),
# which is the same as:
plot_data(m1, view='Time', split_by=list(Subject=simdat$Subject, Trial=simdat$Trial),
# 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)

## End(Not run)

itsadug documentation built on June 17, 2022, 5:05 p.m.