Last data update: 2014.03.03

R: Plot Slices of Bivariate Functions
sliceplotR Documentation

Plot Slices of Bivariate Functions

Description

This function plots slices from user defined values of bivariate surfaces.

Usage

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 = "akima", linear = FALSE,
  extrap = FALSE, k = 40, rug = TRUE, rug.col = NULL,
  jitter = TRUE, ...)

Arguments

x

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.

y

if x is a vector the argument y and z must also be supplied as vectors.

z

if x is a vector the argument y and z must also be supplied as vectors, z defines the surface given by z = f(x, y).

view

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.

c.select

integer, selects the column that is used in the resulting matrix to be used as the z argument.

values

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.

probs

numeric vector of probabilities with values in [0,1] to be used within function quantile to compute the values for plotting the slices.

grid

the grid size of the surface where the slices are generated from.

legend

if set to TRUE, a legend with the values that where used for slicing will be added.

pos

the position of the legend, see also function legend.

digits

the decimal place the legend values should be rounded.

data

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.

rawdata

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.

type

character. Which type of interpolation metjod should be used. The default is type = "akima", 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.

linear

logical. Should linear interpolation be used withing function interp?

extrap

logical. Should interpolations be computed outside the observation area (i.e., extrapolated)?

k

integer. The number of basis functions to be used to compute the interpolated surface when type = "mgcv".

rug

add a rug to the plot.

jitter

if set to TRUE a jittered rug plot is added.

rug.col

specify the color of the rug representation.

...

parameters passed to matplot and legend.

Details

Similar to function plot3d, this function first applies bivariate interpolation on a regular grid, afterwards the slices are computed from the resulting surface.

Note

Function sliceplot uses per default the akima package to construct smooth interpolated surfaces, therefore, package akima needs to be installed. The akima package has an ACM license that restricts applications to non-commercial usage, see

http://www.acm.org/publications/policies/softwarecrnotice

Function sliceplot prints a note refering to the ACM licence. This note can be supressed by setting

options("use.akima" = TRUE)

Author(s)

Nikolaus Umlauf, Thomas Kneib, Stefan Lang, Achim Zeileis.

See Also

plot.bayesx, bayesx, read.bayesx.output, fitted.bayesx, plot3d.

Examples

## 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))

## Not run: 
## 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))

## End(Not run)

## 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)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(R2BayesX)
Loading required package: BayesXsrc
Loading required package: colorspace
Loading required package: mgcv
Loading required package: nlme
This is mgcv 1.8-12. For overview type 'help("mgcv-package")'.
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/R2BayesX/sliceplot.Rd_%03d_medium.png", width=480, height=480)
> ### Name: sliceplot
> ### Title: Plot Slices of Bivariate Functions
> ### Aliases: sliceplot
> ### Keywords: hplot
> 
> ### ** Examples
> 
> ## 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))
> 
> ## Not run: 
> ##D ## estimate model
> ##D b <- bayesx(y ~ sx(z, w, bs = "te", knots = 5), data = dat, method = "REML")
> ##D summary(b)
> ##D 
> ##D ## plot estimated effect
> ##D plot(b, term = "sx(z,w)", sliceplot = TRUE)
> ##D plot(b, term = "sx(z,w)", sliceplot = TRUE, view = 2)
> ##D plot(b, term = "sx(z,w)", sliceplot = TRUE, view = "w")
> ##D plot(b, term = "sx(z,w)", sliceplot = TRUE, c.select = 4)
> ##D plot(b, term = "sx(z,w)", sliceplot = TRUE, c.select = 6)
> ##D plot(b, term = "sx(z,w)", sliceplot = TRUE, probs = seq(0, 1, length = 10))
> ## End(Not run)
> 
> ## another variation
> dat$f1 <- with(dat, sin(z) * cos(w))
> sliceplot(cbind(z = dat$z, w = dat$w, f1 = dat$f1))
Loading required namespace: akima
NOTE: Package 'akima' has an ACM license that restricts applications to non-commercial usage.
> 
> ## same with formula 
> sliceplot(sin(z) * cos(w) ~ z + w, ylab = "f(z)", data = dat)
NOTE: Package 'akima' has an ACM license that restricts applications to non-commercial usage.
> 
> ## compare with plot3d()
> plot3d(sin(z) * 1.5 * w ~ z + w, zlab = "f(z,w)", data = dat)
NOTE: Package 'akima' has an ACM license that restricts applications to non-commercial usage.
> sliceplot(sin(z) * 1.5 * w ~ z + w, ylab = "f(z)", data = dat)
NOTE: Package 'akima' has an ACM license that restricts applications to non-commercial usage.
> sliceplot(sin(z) * 1.5 * w ~ z + w, view = 2, ylab = "f(z)", data = dat)
NOTE: Package 'akima' has an ACM license that restricts applications to non-commercial usage.
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>