Learn R Programming

refund (version 0.1-11)

vis.fgam: Visualization of FGAM objects

Description

Produces perspective or contour plot views of an estimated surface corresponding to af terms fit using fgam or plots "slices"" of the estimated surface or estimated second derivative surface with one of its arguments fixed and corresponding twice-standard error "Bayesian" confidence bands constructed using the method in Marra and Wood (2012). See the details.

Usage

vis.fgam(object, af.term, xval = NULL, tval = NULL, deriv2 = FALSE, theta = 50, 
plot.type = "persp", ticktype = "detailed", ...)

Arguments

object
an fgam object, produced by gam().
af.term
the name of the functional predictor to be plotted. Only important if multiple af terms are fit. Defaults to the first af term in object$call.
xval
a number in the range of functional predictor to be plotted. The surface will be plotted with the first argument of the estimated surface fixed at this value.
tval
a number in the domain of the functional predictor to be plotted. The surface will be plotted with the second argument of the estimated surface fixed at this value. Ignored if xval is specified.
deriv2
If TRUE, plot the estimated second derivative surface along with Bayesian confidence bands. Only implemented for the "slices" plot from either xval or tval being specified.
theta
plot.type
one of "contour" or "persp". Ignored if either xval or tval is specified.
ticktype
how to draw the tick marks if plot.type="persp". Defaults to "detailed".
...
other options to be passed to persp, levelplot, or plot.

Value

  • Simply produces a plot.

Details

The confidence bands used when plotting slices of the estimated surface or second derivative surface are the ones proposed in Marra and Wood (2012). These are a generalization of the "Bayesian" intevals of Wahba (1983) with an adjustment for the uncertainty about the model intercept. The estimated covariance matrix of the model parameters is obtained from assuming a particular Bayesian model on the parameters.

References

McLean, M. W., Hooker, G., Staicu, A.-M., Scheipl, F., and Ruppert, D. (2013). Functional generalized additive models. Journal of Computational and Graphical Statistics, to appear. Available at http://courses2.cit.cornell.edu/mwmclean Marra, G., and Wood, S. N. (2012) Coverage properties of confidence intervals for generalized additive model components. Scandinavian Journal of Statistics, 39(1), 53--74. Wabha, G. (1983) "Confidence intervals" for the cross-validated smoothing spline. Journal of the Royal Statistical Society, Series B, 45(1), 133--150.

See Also

vis.gam, plot.gam, fgam, persp, levelplot

Examples

Run this code
require(splines)
################# DTI Example #####################
data(DTI)

## only consider first visit and cases (since no PASAT scores for controls)
y <- DTI$pasat[DTI$visit==1 & DTI$case==1]
X <- DTI$cca[DTI$visit==1 & DTI$case==1,]

## remove samples containing missing data
ind <- rowSums(is.na(X))>0

y <- y[!ind]
X <- X[!ind,]

## fit the fgam using FA measurements along corpus 
## callosum as functional predictor with PASAT as response
## using 8 cubic B-splines for each marginal bases with 
## third order marginal difference penalties
## specifying gamma>1 enforces more smoothing when using GCV 
## to choose smoothing parameters
fit <- fgam(y~af(X,splinepars=list(k=c(8,8),m=list(c(2,3),c(2,3)))),gamma=1.2)

## contour plot of the fitted surface
vis.fgam(fit,plot.type='contour')

## similar to Figure 5 from McLean et al.
## Bands seem too conservative in some cases
xval=runif(1,min(fit$fgam$ft[[1]]$Xrange),max(fit$fgam$ft[[1]]$Xrange))
tval=runif(1,min(fit$fgam$ft[[1]]$xind),max(fit$fgam$ft[[1]]$xind))
par(mfrow=c(4,1))
vis.fgam(fit,af.term='X',deriv2=FALSE,xval=xval)
vis.fgam(fit,af.term='X',deriv2=FALSE,tval=tval)
vis.fgam(fit,af.term='X',deriv2=TRUE,xval=xval)
vis.fgam(fit,af.term='X',deriv2=TRUE,tval=tval)

Run the code above in your browser using DataLab