##
## plot.fd
##
daybasis65 <- create.fourier.basis(c(0, 365), 65,
axes=list("axesIntervals"))
harmaccelLfd <- vec2Lfd(c(0,(2*pi/365)^2,0), c(0, 365))
harmfdPar <- fdPar(daybasis65, harmaccelLfd, lambda=1e5)
daytempfd <- with(CanadianWeather, Data2fd(day.5,
dailyAv[,,"Temperature.C"], daybasis65))
# plot all the temperature functions for the monthly weather data
plot(daytempfd, main="Temperature Functions")
# To plot one at a time:
# The following pauses to request page changes.
\dontshow{
# (Without 'dontrun', the package build process
# might encounter problems with the par(ask=TRUE)
# feature.)
}
plot(daytempfd, ask=TRUE)
##
## plot.fdSmooth
##
b3.4 <- create.bspline.basis(norder=3, breaks=c(0, .5, 1))
# 4 bases, order 3 = degree 2 =
# continuous, bounded, locally quadratic
fdPar3 <- fdPar(b3.4, lambda=1)
# Penalize excessive slope Lfdobj=1;
# (Can not smooth on second derivative Lfdobj=2 at it is discontinuous.)
fd3.4s0 <- smooth.basis(0:1, 0:1, fdPar3)
# using plot.fd directly
plot(fd3.4s0$fd)
# same plot via plot.fdSmooth
plot(fd3.4s0)
##
## with Date and POSIXct argvals
##
# Date
invasion1 <- as.Date('1775-09-04')
invasion2 <- as.Date('1812-07-12')
earlyUS.Canada <- c(invasion1, invasion2)
BspInvasion <- create.bspline.basis(earlyUS.Canada)
earlyUSyears <- seq(invasion1, invasion2, length.out=7)
(earlyUScubic <- (as.numeric(earlyUSyears-invasion1)/365.24)^3)
fitCubic <- smooth.basis(earlyUSyears, earlyUScubic, BspInvasion)
plot(fitCubic)
# POSIXct
AmRev.ct <- as.POSIXct1970(c('1776-07-04', '1789-04-30'))
BspRev.ct <- create.bspline.basis(AmRev.ct)
AmRevYrs.ct <- seq(AmRev.ct[1], AmRev.ct[2], length.out=14)
(AmRevLin.ct <- as.numeric(AmRevYrs.ct-AmRev.ct[2]))
fitLin.ct <- smooth.basis(AmRevYrs.ct, AmRevLin.ct, BspRev.ct)
plot(fitLin.ct)
Run the code above in your browser using DataLab