plot_diff: Plot difference curve based on model predictions.

View source: R/test.R

plot_diffR Documentation

Plot difference curve based on model predictions.

Description

Plot difference curve based on model predictions.

Usage

plot_diff(
  model,
  view,
  comp,
  cond = NULL,
  se = 1.96,
  sim.ci = FALSE,
  n.grid = 100,
  add = FALSE,
  rm.ranef = TRUE,
  mark.diff = TRUE,
  col.diff = "red",
  col = "black",
  eegAxis = FALSE,
  transform.view = NULL,
  print.summary = getOption("itsadug_print"),
  plot = TRUE,
  main = NULL,
  ylab = NULL,
  xlab = NULL,
  xlim = NULL,
  ylim = NULL,
  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.

se

If less than or equal to zero then only the predicted smooth is plotted, but if greater than zero, then the predicted values plus confidence intervals are plotted. The value of se will be multiplied with the standard error (i.e., 1.96 results in 95%CI and 2.58). Default is set to 1.96 (95%CI).

sim.ci

Logical: Using simultaneous confidence intervals or not (default set to FALSE). The implementation of simultaneous CIs follows Gavin Simpson's blog of December 15, 2016: https://fromthebottomoftheheap.net/2016/12/15/simultaneous-interval-revisited/. This interval is calculated from simulations based. Please specify a seed (e.g., set.seed(123)) for reproducable results. Note: in contrast with Gavin Simpson's code, here the Bayesian posterior covariance matrix of the parameters is uncertainty corrected (unconditional=TRUE) to reflect the uncertainty on the estimation of smoothness parameters.

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.

rm.ranef

Logical: whether or not to remove random effects. Default is TRUE. Alternatively a string (or vector of strings) with the name of the random effect(s) to remove.

mark.diff

Logical: whether or not marking where the difference is significantly different from 0.

col.diff

Color to mark differences (red by default).

col

Line color. Shading color is derived from line color.

eegAxis

Logical: whether or not to reverse the y-axis, plotting negative values upwards. Default is FALSE.

transform.view

Function for transforming the values on the x-axis. Defaults to NULL (no transformation). (See plot_smooth for more info.)

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 is TRUE.

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.

hide.label

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

...

Optional arguments for emptyPlot, or plot_error.

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.

Author(s)

Martijn Wieling, Jacolien van Rij

See Also

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

Examples

data(simdat)
## Not run: 
m1 <- bam(Y ~ Group + te(Time, Trial, by=Group)
    + s(Time, Subject, bs='fs', m=1),
    data=simdat, discrete=TRUE)
plot_diff(m1, view='Time', comp=list(Group=c('Children', 'Adults')))
# in this model, excluding random effects does not change the difference:
plot_diff(m1, view='Time', comp=list(Group=c('Children', 'Adults')), 
    rm.ranef=TRUE)
# simultaneous CI:
plot_diff(m1, view='Time', comp=list(Group=c('Children', 'Adults')), 
    rm.ranef=TRUE, sim.ci=TRUE)
# Reversed y-axis (for EEG data) and no shading:
plot_diff(m1, view='Time', comp=list(Group=c('Children', 'Adults')), 
    eegAxis=TRUE, shade=FALSE)
plot_diff(m1, view='Time', comp=list(Group=c('Children', 'Adults')),
density=15, angle=90, ci.lwd=3)
# 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')

## End(Not run)


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