学习函数回归模型，特别关注r代码：This is the first of two chapters on the functional linear model. Here we have a dependent or response variable whose value is to be predicted or approximated on the basis of a set of independent or covariate variables, and at least one of these is functional in nature. The focus here is on linear models, or functional analogues of linear regression analysis. This chapter is confined to considering the prediction of a scalar response on the basis of one or more functional covariates, as well as possible scalar covariates.
Confidence intervals are developed for estimated regression functions in order to permit conclusions about where along the t axis a covariate plays a strong role in predicting a functional responses. The chapter also offers some permutation tests of hypotheses.
More broadly, we begin here the study of input/output systems. This and the next chapter lead in to Chapter 11, where the response is the derivative of the output from the system.
9.1	Functional Linear Regression with a Scalar Response
We have so far focused on representing a finite number of observations as a func-tional data object, which can theoretically be evaluated at an infinite number of points, and on graphically exploring the variation and covariation of populations of functions. However, we often need to model predictive relationships between differ-ent types of data, and here we expect that some of these data will be functional.
In classic linear regression, predictive models are often of the form
p
yi = XxijBj + a, i= 1,…,N	(9.1)
j=0
that model the relationship between a response yi, and covariates xij as a linear structure. The dummy covariate with j = 0, which has the value one for all i, is
J.O. Ramsay et al., Functional Data Analysis with R and MATLAB, Use R,
DOI: 10.1007/978-0-387-98185-7_9,
© Springer Science + Business Media, LLC 2009 usually included because origin of the response variable and/or one or more of the independent variables can be arbitrary, and 00 codes the constant needed to allow for this. It is often called the intercept term.
The term & allows for sources of variation considered extraneous, such as mea-surement error, unimportant additional causal factors, sources of nonlinearity and so forth, all swept under the statistical rug called error. The a are assumed to add to the prediction of the response, and are usually considered to be independently and identically distributed.
In this chapter we replace at least one of the p observed scalar covariate vari¬ables on the right side of the classic equation by a functional covariate. To simplify the exposition, though, we will describe a model consisting of a single functional independent variable plus an intercept term.
9.2	A Scalar Response Model for Log Annual Precipitation
Our test-bed problem in this section is to predict the logarithm of annual precipita-tion for 35 Canadian weather stations from their temperature profiles. The response in this case is, in terms of the fda package in R,
annualprec = log10(apply(daily$precav,2,sum))
We want to use as the predictor variable the complete temperature profile as well as a constant intercept. These two covariates can be stored in a list of length 2, or in Matlab as a cell array. Here we set up a functional data object for the 35 temperature profiles, called tempfd. To keep things simple and the computation rapid, we will use 65 basis functions without a roughness penalty. This number of basis functions has been found to be adequate for most purposes, and can, for example, capture the ripples observed in early spring in many weather stations.
tempbasis =create.fourier.basis(c(0,365),65)
tempSmooth=smooth.basis(day.5,daily$tempav,tempbasis) tempfd =tempSmooth$fd
9.3	Setting Up the Functional Linear Model
But what can we do when the vector of covariate observations x i = (x〃,..., Xip) in (9.1) is replaced by a function Xi(t)? A first idea might be to discretize each of the N functional covariates Xi (t) by choosing a set of times 11,..., tq and consider fitting the model
q
yi = «O + f Xi(tj )0j + &i.
j=1 
But which times tj are important, given that we must have q < N?
If we choose a finer and finer mesh of times, the summation approaches an inte-gral equation:

We now have a finite number N of observations with which to determine the infinite-dimensional B(t). This is an impossible problem: it is almost always possible to find a B(t) so that (9.2) is satisfied with Ei = 0. More importantly, there are always an infinite number of possible regression coefficient functions B(t) that will produce exactly the same predictions yi. Even if we expand each functional covariate in terms of a limited number of basis functions, it is entirely possible that the total number of basis functions will exceed or at least approach N.