Plot difference curve based on model predictions.
plot_diff(model, view, comp, cond = NULL, se = 1.96, sim.ci = FALSE,
n.grid = 100, add = FALSE, rm.ranef = NULL, 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, ...)
Name of continuous predictor that should be plotted on the x- axis.
Named list with the grouping predictor (categorical variable) and the 2 levels to calculate the difference for.
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.
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).
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:
http://www.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.
Number of data points sampled as predictions. Defaults to 100.
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.
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.
Logical: whether or not marking where the difference is significantly different from 0.
Color to mark differences (red by default).
Line color. Shading color is derived from line color.
Logical: whether or not to reverse the y-axis, plotting negative values upwards. Default is FALSE.
Function for transforming
the values on the x-axis. Defaults to NULL (no transformation).
(See plot_smooth
for more info.)
Logical: whether or not to print the summary.
Default set to the print info messages option
(see infoMessages
).
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.
Text string, alternative title for plot.
Text string, alternative label for y-axis.
Text string, alternative label for x-axis.
Range of x-axis. If not specified, the function automatically generates an appropriate x-axis.
Range of y-axis. If not specified, the function automatically generates an appropriate y-axis.
Logical: whether or not to hide the label (i.e., "difference"). Default is FALSE.
Optional arguments for emptyPlot
,
or plot_error
.
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.
Other Testing for significance: compareML
,
plot_diff2
, report_stats
,
wald_gam
# NOT RUN {
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')
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab