##### Octane data example #####
data(gasoline)
# Create the requisite functional data objects
bbasis = create.bspline.basis(c(900, 1700), 40)
wavelengths = 2*450:850
nir = matrix(NA, 401, 60)
for (i in 1:60) nir[ , i] = gasoline$NIR[i, ]
# Why not just take transpose of gasoline$NIR above?
# Because for some reason it leads to an error in the following statement
gas.fd = smooth.basisPar(wavelengths, nir, bbasis)$fd
# Method 1: Call fpcr with fdobj argument
gasmod1 = fpcr(gasoline$octane, fdobj = gas.fd, nc = 30)
# Method 2: Call fpcr with explicit signal matrix
gasmod2 = fpcr(gasoline$octane, sigmat = gasoline$NIR, nc = 30)
# Method 3: Call fpcr with explicit signal, basis, and penalty matrices
gasmod3 = fpcr(gasoline$octane, sigmat = gasoline$NIR,
basismat = eval.basis(wavelengths, bbasis),
penmats = list(getbasispenalty(bbasis)), nc = 30)
plot(gasmod1, xlab='Wavelength')
# 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.
Run the code above in your browser using DataLab