Learn R Programming

refund (version 0.1-4)

fosr: Function-on-scalar regression

Description

Fit linear regression with functional responses and scalar predictors, with efficient selection of optimal smoothing parameters.

Usage

fosr(fdobj, Z, L = NULL, eval.pts = seq(min(fdobj$basis$range), 
max(fdobj$basis$range), length.out = 201), method = "OLS", 
gam.method = "REML", lambda = NULL, multi.sp = FALSE, max.iter = 1, 
maxlam = NULL, cv1 = FALSE, scale = FALSE)

Arguments

fdobj
a functional data object (class fd) giving the functional responses.
Z
the model matrix, whose columns represent scalar predictors.
L
a row vector or matrix of linear contrasts of the coefficient functions, to be restricted to equal zero.
eval.pts
argument values at which the coefficient functions will be evaluated.
method
estimation method: "OLS" for penalized ordinary least squares, "GLS" for penalized generalized least squares.
gam.method
smoothing parameter selection method, to be passed to gam(): "REML" for restricted maximum likelihood, "GCV.Cp" for generalized cross-validation.
lambda
smoothing parameter value. If NULL, the smoothing parameter(s) will be estimated. See Details.
multi.sp
a logical value indicating whether separate smoothing parameters should be estimated for each coefficient function. Currently must be FALSE if method = "OLS".
max.iter
maximum number of iterations if method = "GLS".
maxlam
maximum smoothing parameter value to consider (when lamvec=NULL; see lofocv)
cv1
logical value indicating whether a cross-validation score should be computed even if a fixedlambda is specified (when method = "OLS").
scale
logical value or vector determining scaling of the matrix Z (see scale, to which the value of this argument is passed).

Value

  • An object of class fosr, which is a list with the following elements:
  • Bmatrix of basis coefficients for the estimated coefficient functions.
  • yhatan object of class fd giving the fitted values for the functional responses.
  • est.funcmatrix of values of the coefficient function estimates at the points given by eval.pts.
  • se.funcmatrix of values of the standard error estimates for the coefficient functions, at the points given by eval.pts.
  • eval.ptspoints at which the coefficient functions are evaluated.
  • fitfit object outputted by amc().
  • edfeffective degrees of freedom of the fit.
  • lambdasmoothing parameter, or vector of smoothing parameters.
  • cvcross-validated integrated squared error if method="OLS", otherwise NULL.
  • roughnessvalue of the roughness penalty.

Details

There are three types of values for argument lambda:
  1. ifNULL, the smoothing parameter is estimated bygam(packagemgcv) ifmethod = "GLS", or byoptimizeifmethod = "GLS";
  2. if a scalar, this value is used as the smoothing parameter (but only for the initial model, ifmethod = "GLS");
  3. if a vector, this is used as a grid of values for optimizing the cross-validation score (providedmethod = "OLS"; otherwise an error message is issued).

Please note that currently, if multi.sp = TRUE, then lambda must be NULL and method must be "GLS".

References

Ramsay, J. O., and Silverman, B. W. (2005). Functional Data Analysis, 2nd ed., Chapter 13. New York: Springer.

Reiss, P. T., Huang, L., and Mennes, M. (2010). Fast function-on-scalar regression with penalized basis expansions. International Journal of Biostatistics, 6(1), article 28. Available at http://works.bepress.com/phil_reiss/16/

See Also

plot.fosr

Examples

Run this code
# The first two lines, adapted from help(fRegress) in package fda,
# set up a functional data object representing daily average 
# temperatures at 35 sites in Canada
daybasis25 <- create.fourier.basis(rangeval=c(0, 365), nbasis=25,
                  axes=list('axesIntervals'))
Temp.fd <- with(CanadianWeather, smooth.basisPar(day.5,
                dailyAv[,,'Temperature.C'], daybasis25)$fd)

modmat = cbind(1, model.matrix(~ factor(CanadianWeather$region) - 1))
constraints = matrix(c(0,1,1,1,1), 1)

# Penalized OLS with smoothing parameter chosen by grid search
olsmod = fosr(Temp.fd, modmat, constraints, method="OLS", lambda=100*10:30)
plot(olsmod, 1)

# Penalized GLS
glsmod = fosr(Temp.fd, modmat, constraints, method="GLS")
plot(glsmod, 1)

Run the code above in your browser using DataLab