Learn R Programming

R2BayesX (version 0.1-1)

plot2d: 2D Effect Plot

Description

Function to plot simple 2D graphics for univariate effects/functions, typically used for objects of class "linear.bayesx" and "sm.bayesx" returned from function bayesx and read.bayesx.output.

Usage

plot2d(x, residuals = FALSE, rug = TRUE, jitter = TRUE, 
  col.residuals = NULL, col.lines = NULL, col.polygons = NULL, 
  col.rug = NULL, c.select = NULL, fill.select = NULL, 
  data = NULL, ...)

Arguments

x
a matrix or data frame, containing the covariate for which the effect should be plotted in the first column and at least a second column containing the effect, typically the structure for univariate functions returned within
residuals
if set to TRUE, partial residuals may also be plotted if available.
rug
add a rug to the plot.
jitter
if set to TRUE a jittered rug plot is added.
col.residuals
the color of the partial residuals.
col.lines
the color of the lines.
col.polygons
specify the background color of polygons, if x has at least 3 columns, i.e. column 2 and 3 can form one polygon.
col.rug
specify the color of the rug representation.
c.select
integer vector of maximum length of columns of x, selects the columns of the resulting data matrix that should be used for plotting. E.g. if x has 5 columns, then c.select = c(1, 2, 5) will sele
fill.select
integer vector, select pairwise the columns of the resulting data matrix that should form one polygon with a certain background color specified in argument col. E.g. x has three columns, or is specified wit
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 plot2d is called.
...
other graphical parameters, please see the details.

Details

For 2D plots the following graphical parameters may be specified additionally:
  • cex: specify the size of partial residuals,
  • lty: the line type for each column that is plotted, e.g.lty = c(1, 2),
  • lwd: the line width for each column that is plotted, e.g.lwd = c(1, 2),
  • poly.lty: the line type to be used for the polygons,
  • poly.lwd: the line width to be used for the polygons,
  • densityangle,border: seepolygon,
  • ...: other graphical parameters, see functionplot.

See Also

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

Examples

Run this code
## generate some data
set.seed(111)
n <- 500
## regressor
dat <- data.frame(x = runif(n,-3,3))

##  response 
dat$y <- with(dat, 10 + sin(x) + rnorm(n,sd=0.6))

## estimate model
b <- bayesx(y ~ sx(x), data = dat)
summary(b)

## plot estimated effect
plot(b, which = 1)
plot(b, which = 1, rug = FALSE)

## extract fitted effects
f <- fitted(b, term = "sx(x)")

## now use plot2d
plot2d(f)
plot2d(f, residuals = TRUE)
plot2d(f, residuals = TRUE, pch = 2, col.resid = "green3")
plot2d(f, col.poly = NA, lwd = 1, lty = 1)
plot2d(f, col.poly = NA, lwd = 1, lty = 1, col.lines = 4)
plot2d(f, col.poly = c(2, 3), lwd = 1, col.lines = 4, lty = 1)
plot2d(f, lwd = c(1, 3, 2, 2, 3), col.poly = NA, lty = 1)
plot2d(f, lwd = c(1, 3, 2, 2, 3), col.poly = NA, lty = 1, col.lines = 2:6)
plot2d(f, lwd = c(1, 3, 2, 2, 3), col.poly = NA, lty = 1, col.lines = 2:6,
  resid = TRUE, pch = 4, col.resid = 7)

## another variation
plot2d(sin(x) ~ x, data = dat)
dat$f <- with(dat, sin(dat$x))
plot2d(f ~ x, data = dat)
dat$f1 <- with(dat, f + 0.1)
dat$f2 <- with(dat, f - 0.1)
plot2d(f1 + f2 ~ x, data = dat)
plot2d(f1 + f2 ~ x, data = dat, fill.select = c(0, 1, 1), lty = 0)
plot2d(f1 + f2 ~ x, data = dat, fill.select = c(0, 1, 1), lty = 0,
  density = 20, poly.lty = 1, poly.lwd = 2)
plot2d(f1 + f + f2 ~ x, data = dat, fill.select = c(0, 1, 0, 1), 
  lty = c(0, 1, 0), density = 20, poly.lty = 1, poly.lwd = 2)

Run the code above in your browser using DataLab