Learn R Programming

itsadug (version 2.0)

plot_diff: Plot difference curve based on model predictions.

Description

Plot difference curve based on model predictions.

Usage

plot_diff(model, view, comp, cond = NULL, plotCI = TRUE, f = 1.96,
  eegAxis = FALSE, col = "black", shade = TRUE, n.grid = 100,
  add = FALSE, print.summary = getOption("itsadug_print"), plot = TRUE,
  rm.ranef = NULL, main = NULL, ylab = NULL, xlab = NULL, xlim = NULL,
  ylim = NULL, transform.view = NULL, mark.diff = TRUE,
  hide.label = FALSE, ...)

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.
cond
A named list of the values to use for the predictor terms. Variables omitted from this list will have the closest observed value to the median for continuous variables, or the reference level for factors.
plotCI
Logical: whether or not to plot confidence intervals. Default is TRUE.
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.
eegAxis
Logical: whether or not to reverse the y-axis, plotting negative values upwards. Default is FALSE.
col
Line color. Shading color is derived from line color.
shade
Logical: plot shaded confidence interval (TRUE) or dashed lines that indicate confidence region (FALSE).
n.grid
Number of data points sampled as predictions. Defaults to 100.
add
Logical: whether or not to add the line to an existing plot. Default is FALSE. When no plot window is available and add=TRUE, the function will generate an error.
print.summary
Logical: whether or not to print the summary. Default set to the print info messages option (see infoMessages).
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
rm.ranef
Logical: whether or not to remove random effects. Default is FALSE. Alternatively a string (or vector of strings) with the name of the random effect(s) to remove.
main
Text string, alternative title for plot.
ylab
Text string, alternative label for y-axis.
xlab
Text string, alternative label for x-axis.
xlim
Range of x-axis. If not specified, the function automatically generates an appropriate x-axis.
ylim
Range of y-axis. If not specified, the function automatically generates an appropriate y-axis.
transform.view
Function for transforming the values on the x-axis. Defaults to NULL (no transformation). (See plot_smooth for more info.)
mark.diff
Logical: whether or not marking where the difference is significantly different from 0.
hide.label
Logical: whether or not to hide the label (i.e., "difference"). Default is FALSE.
...
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) and the x-values (x) is returned.

See Also

Other Testing for significance: compareML, plot_diff2, report_stats, wald_gam

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')

Run the code above in your browser using DataLab