Learn R Programming

rbart (version 1.0)

plotFunctionDraws: Plot matrix of function draws evaluated on a set of x

Description

Given draws of a function \(f_d\), \(d=1,2,\ldots,D\) and a set of \(x\) vectors \(x_j, j=1,2,\ldots,J\), we have a \(D \times J\) matrix of evaluations whose \((d,j)\) element is \(f_d(x_j)\), the \(d^{th}\) draw of the function evaluated at the \(j^{th}\) \(x\). This function plots the draws by plotting estimates of \(f(x_j)\) versus intervals for \(f(x_j)\). The estimates are the mean of the \(j^{th}\) column and the intervals are two quantiles of the \(j^{th}\) column (e.g 5% and 95%).

Usage

plotFunctionDraws(fd,complevel=mean(fd),probs=c(.025,.975),
      xlab="posterior mean of function",ylab="posterior intervals",
      intervalcol="green",linecol="red",
      pts=NA,ptscol="blue", ptspch=1, ptscex=1, ...)

Arguments

fd

\(D \times J\) matrix whose \((d,j)\) element is the \(d^th\) function draw evaluated at the \(j^{th}\) \(x\).

complevel

A horizontal line is drawn a complevel to compare the intervals to.

probs

The two quantiles used to construct the intervals.

xlab

Label for x axis.

ylab

Label for y axis.

intervalcol

Color to draw the intervals with.

linecol

Color to draw the comparizon horizontal line with.

pts

Add \((x_j,pts_j)\) to the plot. For example pts could be fitted values from and alternative model such as the linear model.

ptscol

Color to draw the points pts with.

ptspch

plot charactor to plot the points pts with.

ptscex

cex to plot the points pts with.

...

Arguments passed on to call to graphics::plot.

Value

NULL

Examples

Run this code
# NOT RUN {
##################################################
## please see vignette and/or www.rob-mcculloch.org for more realistic examples
##################################################

## get simulated data
data(simdat)

##get rbart run on the simulated data
data(rbartonsimd)

## plot function (f and s) draws
shat = sqrt(mean((simdat$yp-rbartonsimd$mmean)^2)) #overall estimate of sigma
lmfit = lm(y~x,data.frame(x=simdat$x,y=simdat$y)) 
yhatlm = predict(lmfit,data.frame(x=simdat$xp)) #fits from a linear model

#Now we use plotFunctionDraws to look at mdraws (left panel) and sdraws (right panel).

## in the mean inference, you can see that the linear model seem unlikely
## in the variance inference, you can see that the posteriors of s(x) are far from a constant value
par(mfrow=c(1,2))

## look at mean inference
plotFunctionDraws(rbartonsimd$mdraws,complevel=mean(simdat$y), probs=c(.05,.95),
   xlab=expression(hat(f)(x)), pts=yhatlm, ptscol="black",
   cex.lab=1.2, cex.axis=1.4, main="intervals for f(x)")

##look at the standard deviation inference
plotFunctionDraws(rbartonsimd$sdraws, complevel=shat, xlab=expression(hat(s)(x)),
   intervalcol="magenta", linecol="blue",
   cex.lab=1.2, cex.axis=1.4, main="intervals for s(x)")

# }

Run the code above in your browser using DataLab