fpcr: Functional principal component regression In refund: Regression with Functional Data

Description

Implements functional principal component regression (Reiss and Ogden, 2007, 2010) for generalized linear models with scalar responses and functional predictors.

Usage

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 fpcr( y, xfuncs = NULL, fdobj = NULL, ncomp = NULL, pve = 0.99, nbasis = NULL, basismat = NULL, penmat = NULL, argvals = NULL, covt = NULL, mean.signal.term = FALSE, spline.order = NULL, family = "gaussian", method = "REML", sp = NULL, pen.order = 2, cv1 = FALSE, nfold = 5, store.cv = FALSE, store.gam = TRUE, ... ) 

Arguments

 y scalar outcome vector. xfuncs for 1D predictors, an n \times d matrix of signals/functional predictors, where n is the length of y and d is the number of sites at which each signal is defined. For 2D predictors, an n \times d1 \times d2 array representing n images of dimension d1 \times d2. fdobj functional data object (class "fd") giving the functional predictors. Allowed only for 1D functional predictors. ncomp number of principal components. If NULL, this is chosen by pve. pve proportion of variance explained: used to choose the number of principal components. nbasis number(s) of B-spline basis functions: either a scalar, or a vector of values to be compared. For 2D predictors, tensor product B-splines are used, with the given basis dimension(s) in each direction; alternatively, nbasis can be given in the form list(v1,v2), in which case cross-validation will be performed for each combination of the first-dimension basis sizes in v1 and the second-dimension basis sizes in v2. Ignored if fdobj is supplied. If fdobj is not supplied, this defaults to 40 (i.e., 40 B-spline basis functions) for 1D predictors, and 15 (i.e., tensor product B-splines with 15 functions per dimension) for 2D predictors. basismat a d \times K matrix of values of K basis functions at the d sites. penmat a K \times K matrix defining a penalty on the basis coefficients. argvals points at which the functional predictors and the coefficient function are evaluated. By default, if 1D functional predictors are given by the n \times d matrix xfuncs, argvals is set to d equally spaced points from 0 to 1; if they are given by fdobj, argvals is set to 401 equally spaced points spanning the domain of the given functions. For 2D (image) predictors supplied as an n \times d1 \times d2 array, argvals defaults to a list of (1) d1 equally spaced points from 0 to 1; (2) d2 equally spaced points from 0 to 1. covt covariates: an n-row matrix, or a vector of length n. mean.signal.term logical: should the mean of each subject's signal be included as a covariate? spline.order order of B-splines used, if fdobj is not supplied; defaults to 4, i.e., cubic B-splines. family generalized linear model family. Current version supports "gaussian" (the default) and "binomial". method smoothing parameter selection method, passed to function gam; see the gam documentation for details. sp a fixed smoothing parameter; if NULL, an optimal value is chosen (see method). pen.order order of derivative penalty applied when estimating the coefficient function; defaults to 2. cv1 logical: should cross-validation be performed to select the best model if only one set of tuning parameters provided? By default, FALSE. Note that, if there are multiple sets of tuning parameters provided, cv is always performed. nfold the number of validation sets ("folds") into which the data are divided; by default, 5. store.cv logical: should a CV result table be in the output? By default, FALSE. store.gam logical: should the gam object be included in the output? Defaults to TRUE. ... other arguments passed to function gam.

Details

One-dimensional functional predictors can be given either in functional data object form, using argument fdobj (see the fda package of Ramsay, Hooker and Graves, 2009, and Method 1 in the example below), or explicitly, using xfuncs (see Method 2 in the example). In the latter case, arguments basismat and penmat can also be used to specify the basis and/or penalty matrices (see Method 3).

For two-dimensional predictors, functional data object form is not supported. Instead of radial B-splines as in Reiss and Ogden (2010), this implementation employs tensor product cubic B-splines, sometimes known as bivariate O-splines (Ormerod, 2008).

For purposes of interpreting the fitted coefficients, please note that the functional predictors are decorrelated from the scalar predictors before fitting the model (when there are no scalar predictors other than the intercept, this just means the columns of the functional predictor matrix are de-meaned); see section 3.2 of Reiss (2006) for details.

Value

A list with components

 gamObject if store.gam = TRUE, an object of class gam (see gamObject in the mgcv package documentation). fhat coefficient function estimate. se pointwise Bayesian standard error. undecor.coef undecorrelated coefficient for covariates. argvals the supplied value of argvals. cv.table a table giving the CV criterion for each combination of nbasis and ncomp, if store.cv = TRUE; otherwise, the CV criterion only for the optimized combination of these parameters. Set to NULL if CV is not performed. nbasis, ncomp when CV is performed, the values of nbasis and comp that minimize the CV criterion.

Author(s)

Philip Reiss phil.reiss@nyumc.org, Lan Huo lan.huo@nyumc.org, and Lei Huang huangracer@gmail.com

References

Ormerod, J. T. (2008). On semiparametric regression and data mining. Ph.D. dissertation, School of Mathematics and Statistics, University of New South Wales.

Ramsay, J. O., Hooker, G., and Graves, S. (2009). Functional Data Analysis with R and MATLAB. New York: Springer.

Reiss, P. T. (2006). Regression with signals and images as predictors. Ph.D. dissertation, Department of Biostatistics, Columbia University.

Reiss, P. T., and Ogden, R. T. (2007). Functional principal component regression and functional partial least squares. Journal of the American Statistical Association, 102, 984–996.

Reiss, P. T., and Ogden, R. T. (2010). Functional generalized linear models with images as predictors. Biometrics, 66, 61–69.

Wood, S. N. (2006). Generalized Additive Models: An Introduction with R. Boca Raton, FL: Chapman & Hall.

Examples

  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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 require(fda) ### 1D functional predictor example ### ######### Octane data example ######### data(gasoline) # Create the requisite functional data objects bbasis = create.bspline.basis(c(900, 1700), 40) wavelengths = 2*450:850 nir <- t(gasoline$NIR) gas.fd = smooth.basisPar(wavelengths, nir, bbasis)$fd # Method 1: Call fpcr with fdobj argument gasmod1 = fpcr(gasoline$octane, fdobj = gas.fd, ncomp = 30) plot(gasmod1, xlab="Wavelength") ## Not run: # Method 2: Call fpcr with explicit signal matrix gasmod2 = fpcr(gasoline$octane, xfuncs = gasoline$NIR, ncomp = 30) # Method 3: Call fpcr with explicit signal, basis, and penalty matrices gasmod3 = fpcr(gasoline$octane, xfuncs = gasoline$NIR, basismat = eval.basis(wavelengths, bbasis), penmat = getbasispenalty(bbasis), ncomp = 30) # Check that all 3 calls yield essentially identical estimates all.equal(gasmod1$fhat, gasmod2$fhat, gasmod3$fhat) # But note that, in general, you'd have to specify argvals in Method 1 # to get the same coefficient function values as with Methods 2 & 3. ## End(Not run) ### 2D functional predictor example ### n = 200; d = 70 # Create true coefficient function ftrue = matrix(0,d,d) ftrue[40:46,34:38] = 1 # Generate random functional predictors, and scalar responses ii = array(rnorm(n*d^2), dim=c(n,d,d)) iimat = ii; dim(iimat) = c(n,d^2) yy = iimat %*% as.vector(ftrue) + rnorm(n, sd=.3) mm = fpcr(yy, ii, ncomp=40) image(ftrue) contour(mm$fhat, add=TRUE) ## Not run: ### Cross-validation ### cv.gas = fpcr(gasoline$octane, xfuncs = gasoline$NIR, nbasis=seq(20,40,5), ncomp = seq(10,20,5), store.cv = TRUE) image(seq(20,40,5), seq(10,20,5), cv.gas$cv.table, xlab="Basis size", ylab="Number of PCs", xaxp=c(20,40,4), yaxp=c(10,20,2)) ## End(Not run) 

refund documentation built on July 1, 2021, 9:06 a.m.