draw.gam: Plot estimated smooths from a fitted GAM

Description Usage Arguments Value Author(s) Examples

Description

Plots estimated smooths from a fitted GAM model in a similar way to mgcv::plot.gam() but instead of using base graphics, ggplot2::ggplot() is used instead.

Usage

1
2
3
4
## S3 method for class 'gam'
draw(object, select, scales = c("free", "fixed"),
  align = "hv", n = 100, unconditional = FALSE, inc.mean = FALSE,
  dist = 0.1, ...)

Arguments

object

a fitted GAM, the result of a call to mgcv::gam().

select

character;

scales

character; should all univariate smooths be plotted with the same y-axis scale? The default, scales = "fixed", ensures this is done. If scales = "free" each univariate smooth has its own y-axis scale.

align

characer; see argument align in cowplot::plot_grid(). Defaults to "hv" so that plots are nicely aligned.

n

numeric; the number of points over the range of the covariate at which to evaluate the smooth.

unconditional

logical; should confidence intervals include the uncertainty due to smoothness selection? If TRUE, the corrected Bayesian covariance matrix will be used.

inc.mean

logical; should the uncertainty in the model constant term be included in the standard error of the evaluate values of the smooth? Currently not implemented.

dist

numeric; if greater than 0, this is used to determine when a location is too far from data to be plotted when plotting 2-D smooths. The data are scaled into the unit square before deciding what to exclude, and dist is a distance within the unit square. See mgcv::exclude.too.far() for further details.

...

arguments passed to cowplot::plot_grid(). Any arguments to plot_grid() may be supplied, except for: plotlist and align.

Value

A ggplot2::ggplot() object.

Author(s)

Gavin L. Simpson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
library("mgcv")

set.seed(2)
dat <- gamSim(1, n = 400, dist = "normal", scale = 2)
m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")

draw(m1)

set.seed(2)
dat <- gamSim(2, n = 4000, dist = "normal", scale = 1)
m2 <- gam(y ~ s(x, z, k = 30), data = dat$data, method = "REML")

draw(m2)

dat <- gamSim(4)
m3 <- gam(y ~ fac + s(x2, by = fac) + s(x0), data = dat)

draw(m3, scales = "fixed")

gavinsimpson/tsgam documentation built on May 16, 2019, 10:11 p.m.