Learn R Programming

itsadug (version 0.8)

plot_diff: Plot difference curve based on model predictions.

Description

Plot difference curve based on model predictions.

Usage

plot_diff(model, view, comp, eegAxis = F, f = 1.96, ylim = NULL,
  ylab = NULL, main = NULL, plot = TRUE, ...)

Arguments

model
A GAMM model, resulting from the functions gam or bam.
view
Name of continuous predictor that should be plotted on the x- axis.
comp
Named list with the grouping predictor (categorical variable) and the 2 levels to calculate the difference for.
eegAxis
Logical: whether or not to reverse the y-axis, plotting negative values upwards. Default is FALSE.
f
A number to scale the standard error. Defaults to 1.96, resulting in 95% confidence intervals. For 99% confidence intervals use a value of 2.58.
ylim
Range of y-axis. If not specified, the function automatically generates an appropriate y-axis.
ylab
Text string, alternative label for y-axis.
main
Text string, alternative title for plot.
plot
Logical: whether or not to plot the difference. If FALSE, then the output is returned as a list, with the estimated difference (est) and the standard error over the estimate (se.est) and the x-values (x). Default is
...
Optional arguments for plot.

Value

  • If the result is not being plotted, a list is returned with the estimated difference (est) and the standard error over the estimate (se.est) and the x-values (x) is returned.

See Also

Other functions for interpreting nonlinear effects: fvisgam, vis.gam2; plotDiff2D, plot_diff2; plot_parametric; plot_smooth; pvis.gam, pvisgam

Examples

Run this code
data(simdat)
m1 <- bam(Y ~ Group + te(Time, Trial, by=Group),
    data=simdat)
plot_diff(m1, view='Time', comp=list(Group=c("Children", "Adults")))
# Reversed y-axis (for EEG data):
plot_diff(m1, view='Time', comp=list(Group=c("Children", "Adults")),
    eegAxis=TRUE)
# retrieving plot values...
out <- plot_diff(m1, view='Time', comp=list(Group=c("Children", "Adults")),
   plot=FALSE)
#... which might be used for indicating differences:
x <- find_difference(out$est, out$se, f=1.96, xVals=out$xVals)
# add lines:
arrows(x0=x$start, x1=x$end, y0=0, y1=0,code=3, length=.1, col='red')
# see the vignette for examples:
vignette("plotfunctions", package="itsadug")

Run the code above in your browser using DataLab