Description Usage Arguments Details Value See Also Examples
This function converts an array y
of function values
plus an array argvals
of argument values into a
functional data object. This a function that tries to
do as much for the user as possible. A basis function
expansion is used to represent the curve, but no roughness
penalty is used. The data are fit using the least squares
fitting criterion. NOTE: Interpolation with data2fd(...) can be
shockingly bad, as illustrated in one of the examples.
1 2 3 |
y |
an array containing sampled values of curves. If If If |
argvals |
a set of argument values. If this is a vector, the same set of argument values is used for all
columns of |
basisobj |
either: A |
fdnames |
A list of length 3, each member being a string vector containing labels for the levels of the corresponding dimension of the discrete data. The first dimension is for argument values, and is given the default name "time", the second is for replications, and is given the default name "reps", and the third is for functions, and is given the default name "values". These default names are assigned in function {tt data2fd}, which also assigns default string vectors by using the dimnames attribute of the discrete data array. |
argnames |
a character vector of length 3 containing:
These strings are used as names for the members of list |
This function tends to be used in rather simple applications where
there is no need to control the roughness of the resulting curve
with any great finesse. The roughness is essentially controlled
by how many basis functions are used. In more sophisticated
applications, it would be better to use the function smooth.basis
an object of the fd
class containing:
coefs |
the coefficient array |
basis |
a basis object and |
fdnames |
a list containing names for the arguments, function values and variables |
Data2fd
smooth.basis
,
smooth.basisPar
,
project.basis
,
smooth.fd
,
smooth.monotone
,
smooth.pos
day.5
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # Simplest possible example
b1.2 <- create.bspline.basis(norder=1, breaks=c(0, .5, 1))
# 2 bases, order 1 = degree 0 = step functions
str(fd1.2 <- data2fd(0:1, basisobj=b1.2))
plot(fd1.2)
# A step function: 0 to time=0.5, then 1 after
b2.3 <- create.bspline.basis(norder=2, breaks=c(0, .5, 1))
# 3 bases, order 2 = degree 1 =
# continuous, bounded, locally linear
str(fd2.3 <- data2fd(0:1, basisobj=b2.3))
round(fd2.3$coefs, 4)
# 0, -.25, 1
plot(fd2.3)
# Officially acceptable but crazy:
# Initial negative slope from (0,0) to (0.5, -0.25),
# then positive slope to (1,1).
b3.4 <- create.bspline.basis(norder=3, breaks=c(0, .5, 1))
# 4 bases, order 3 = degree 2 =
# continuous, bounded, locally quadratic
str(fd3.4 <- data2fd(0:1, basisobj=b3.4))
round(fd3.4$coefs, 4)
# 0, .25, -.5, 1
plot(fd3.4)
# Officially acceptable but crazy:
# Initial positive then swings negative
# between 0.4 and ~0.75 before becoming positive again
# with a steep slope running to (1,1).
# Simple example
gaitbasis3 <- create.fourier.basis(nbasis=3)
str(gaitbasis3) # note: 'names' for 3 bases
gaitfd3 <- data2fd(gait, basisobj=gaitbasis3)
str(gaitfd3)
# Note: dimanes for 'coefs' + basis[['names']]
# + 'fdnames'
# set up the fourier basis
daybasis <- create.fourier.basis(c(0, 365), nbasis=65)
# Make temperature fd object
# Temperature data are in 12 by 365 matrix tempav
# See analyses of weather data.
# Convert the data to a functional data object
tempfd <- data2fd(CanadianWeather$dailyAv[,,"Temperature.C"],
day.5, daybasis)
# plot the temperature curves
plot(tempfd)
# Terrifying interpolation
hgtbasis <- with(growth, create.bspline.basis(range(age),
breaks=age, norder=6))
girl.data2fd <- with(growth, data2fd(hgtf, age, hgtbasis))
age2 <- with(growth, sort(c(age, (age[-1]+age[-length(age)])/2)))
girlPred <- eval.fd(age2, girl.data2fd)
range(growth$hgtf)
range(growth$hgtf-girlPred[seq(1, by=2, length=31),])
# 5.5e-6 0.028 <
# The predictions are consistently too small
# but by less than 0.05 percent
matplot(age2, girlPred, type="l")
with(growth, matpoints(age, hgtf))
# girl.data2fd fits the data fine but goes berzerk
# between points
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.