
This function plots slices from user defined values of bivariate surfaces.
sliceplot(x, y = NULL, z = NULL, view = 1, c.select = NULL,
values = NULL, probs = c(0.1, 0.5, 0.9), grid = 100,
legend = TRUE, pos = "topright", digits = 2, data = NULL,
rawdata = FALSE, type = "interp", linear = FALSE,
extrap = FALSE, k = 40, rug = TRUE, rug.col = NULL,
jitter = TRUE, ...)
a matrix or data frame, containing the covariates for which the effect should be plotted
in the first and second column and at least a third column containing the effect, typically
the structure for bivariate functions returned within bayesx
and
read.bayesx.output
model term objects is used, also see
fitted.bayesx
. Another possibility is to specify the plot via a formula
,
e.g. for simple plotting of bivariate surfaces z ~ x + y
, also see the example.
if x
is a vector the argument y
and z
must also be supplied as
vectors.
if x
is a vector the argument y
and z
must also be supplied as
vectors, z
defines the surface given by
which variable should be used for the x-axis of the plot, the other variable will be
used to compute the slices. May also be a character
with the name of the corresponding
variable.
integer
, selects the column that is used in the resulting matrix to be
used as the z
argument.
the values of the x
or y
variable that should be used for computing
the slices, if set to NULL
, slices will be constructed according to the quantiles, see
also argument probs
.
numeric vector of probabilities with values in [0,1] to be used within function
quantile
to compute the values
for plotting the slices.
the grid size of the surface where the slices are generated from.
if set to TRUE
, a legend with the values
that where used for slicing
will be added.
the position of the legend, see also function legend
.
the decimal place the legend values should be rounded.
if x
is a formula
, a data.frame
or list
. By default the
variables are taken from environment(x)
: typically the environment from which
plot3d
is called.
if set to TRUE
, the data will not be interpolated, only raw data will be
used. This is useful when displaying data on a regular grid.
character. Which type of interpolation metjod should be used. The default is
type = "interp"
, see function interp
. The two other options are
type = "mba"
, which calls function mba.surf
of package MBA, or
type = "mgcv"
, which uses a spatial smoother withing package mgcv for interpolation.
The last option is definitely the slowest, since a full regression model needs to be estimated.
logical. Should linear interpolation be used withing function
interp
?
logical. Should interpolations be computed outside the observation area (i.e., extrapolated)?
integer. The number of basis functions to be used to compute the interpolated surface
when type = "mgcv"
.
add a rug
to the plot.
specify the color of the rug representation.
Nikolaus Umlauf, Thomas Kneib, Stefan Lang, Achim Zeileis.
Similar to function plot3d
, this function first applies bivariate interpolation
on a regular grid
, afterwards the slices are computed from the resulting surface.
plot.bayesx
, bayesx
, read.bayesx.output
,
fitted.bayesx
, plot3d
.
## generate some data
set.seed(111)
n <- 500
## regressors
dat <- data.frame(z = runif(n, -3, 3), w = runif(n, 0, 6))
## response
dat$y <- with(dat, 1.5 + cos(z) * sin(w) + rnorm(n, sd = 0.6))
if (FALSE) {
## estimate model
b <- bayesx(y ~ sx(z, w, bs = "te", knots = 5), data = dat, method = "REML")
summary(b)
## plot estimated effect
plot(b, term = "sx(z,w)", sliceplot = TRUE)
plot(b, term = "sx(z,w)", sliceplot = TRUE, view = 2)
plot(b, term = "sx(z,w)", sliceplot = TRUE, view = "w")
plot(b, term = "sx(z,w)", sliceplot = TRUE, c.select = 4)
plot(b, term = "sx(z,w)", sliceplot = TRUE, c.select = 6)
plot(b, term = "sx(z,w)", sliceplot = TRUE, probs = seq(0, 1, length = 10))
}
## another variation
dat$f1 <- with(dat, sin(z) * cos(w))
sliceplot(cbind(z = dat$z, w = dat$w, f1 = dat$f1))
## same with formula
sliceplot(sin(z) * cos(w) ~ z + w, ylab = "f(z)", data = dat)
## compare with plot3d()
plot3d(sin(z) * 1.5 * w ~ z + w, zlab = "f(z,w)", data = dat)
sliceplot(sin(z) * 1.5 * w ~ z + w, ylab = "f(z)", data = dat)
sliceplot(sin(z) * 1.5 * w ~ z + w, view = 2, ylab = "f(z)", data = dat)
Run the code above in your browser using DataLab