Description Usage Arguments Value Examples
View source: R/plotFunctionDraws.R
Given draws of a function fd, d=1,2,...D and a set of x vectors x(j), j=1,2,...J, we have a D x J matrix of evaluations whose (d,j) element is fd(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%).
1 2 3 4 | 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, ...)
|
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. |
NULL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ##################################################
## 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)")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.