plot_diff2: Plot difference surface based on model predictions.

View source: R/test.R

plot_diff2R Documentation

Plot difference surface based on model predictions.

Description

Plot difference surface based on model predictions.

Usage

plot_diff2(
  model,
  view,
  comp,
  cond = NULL,
  color = "terrain",
  nCol = 100,
  col = NULL,
  add.color.legend = TRUE,
  se = 1.96,
  sim.ci = FALSE,
  show.diff = FALSE,
  col.diff = 1,
  alpha.diff = 0.5,
  n.grid = 30,
  nlevels = 10,
  zlim = NULL,
  xlim = NULL,
  ylim = NULL,
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  rm.ranef = TRUE,
  transform.view = NULL,
  hide.label = FALSE,
  dec = NULL,
  f = 1.96,
  print.summary = getOption("itsadug_print"),
  ...
)

Arguments

model

A GAMM model, resulting from the functions gam or bam.

view

Name of continuous predictors that should be plotted on the x- and y-axes. Vector of two values.

comp

Named list with the grouping predictor (categorical variable) and the 2 levels to calculate the difference for.

cond

Named list of the values to use for the other predictor terms (not in view).

color

The color scheme to use for plots. One of 'topo', 'heat', 'cm', 'terrain', 'gray' or 'bw'. Alternatively a vector with some colors can be provided for a custom color palette.

nCol

Range of colors of background of contour plot.

col

Line color.

add.color.legend

Logical: whether or not to add a color legend. Default is TRUE. If FALSE (omitted), one could use the function gradientLegend to add a legend manually at any position.

se

If less than or equal to zero then only the predicted surface 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.

show.diff

Logical: whether or not to indicate the regions that are significantly different from zero. Note that these regions are just an indication and dependent on the value of n.grid. Defaults to FALSE.

col.diff

Color to shade the nonsignificant areas.

alpha.diff

Level of transparency to mark the nonsignificant areas.

n.grid

Resolution.

nlevels

Levels of contour lines.

zlim

A two item array giving the lower and upper limits for the z- axis scale. NULL to choose automatically.

xlim

A two item array giving the lower and upper limits for the x- axis scale. NULL to choose automatically.

ylim

A two item array giving the lower and upper limits for the y- axis scale. NULL to choose automatically.

main

Title of plot.

xlab

Label x-axis.

ylab

Label y-axis.

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.

transform.view

List with two functions for transforming the values on the x- and y-axis respectively. If one of the axes need to be transformed, set the other to NULL (no transformation). (See fvisgam for more info.)

hide.label

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

dec

Numeric: number of decimals for rounding the color legend. When NULL (default), no rounding. If -1 (default), automatically determined. Note: if value = -1 (default), rounding will be applied also when zlim is provided.

f

Scaling factor to determine the CI from the se, for marking the difference with 0. Only applies when se is smaller or equal to zero and show.diff is set to TRUE.

print.summary

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

...

Optional arguments for plotsurface.

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.

Warning

When the argument show.diff is set to TRUE a shading area indicates where the confidence intervals include zero. Or, in other words, the areas that are not significantly different from zero. Be careful with the interpretation, however, as the precise shape of the surface is dependent on model constraints such as the value of choose.k and the smooth function used, and the size of the confidence intervals are dependent on the model fit and model characteristics (see vignette('acf', package='itsadug')). In addition, the value of n.grid determines the precision of the plot.

Author(s)

Martijn Wieling, reimplemented by Jacolien van Rij

See Also

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

Examples

data(simdat)
## Not run: 
m1 <- bam(Y ~ Group + te(Time, Trial, by=Group),
    data=simdat)
plot_diff2(m1, view=c('Time', 'Trial'), 
    comp=list(Group=c('Children', 'Adults')))

## End(Not run)

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