fda (version 2.4.7)

argvalsy.swap: Swap argvals with y if the latter is simpler.

Description

Preprocess argvals, y, and basisobj. If only one of argvals and y is provided, use it as y and take argvals as a vector spanning basisobj[['rangreval']]. If both are provided, the simpler becomes argvals. If both have the same dimensions but only one lies in basisobj[['rangreval']], that becomes argvals.

Usage

argvalsy.swap(argvals=NULL, y=NULL, basisobj=NULL)

Arguments

argvals

a vector or array of argument values.

y

an array containing sampled values of curves.

basisobj

One of the following:

  • basisfd a functional basis object (class basisfd.

  • fd a functional data object (class fd), from which its basis component is extracted.

  • fdPar a functional parameter object (class fdPar), from which its basis component is extracted.

  • integer an integer giving the order of a B-spline basis, create.bspline.basis(argvals, norder=basisobj)

  • numeric vector specifying the knots for a B-spline basis, create.bspline.basis(basisobj)

  • NULL Defaults to create.bspline.basis(argvals).

Value

a list with components argvals, y, and basisobj.

Details

1. If y is NULL, replace by argvals.

2. If argvals is NULL, replace by seq(basisobj[['rangeval']][1], basisobj[['rangeval']][2], dim(y)[1]) with a warning.

3. If the dimensions of argvals and y match and only one is contained in basisobj[['rangeval']], use that as argvals and the other as y.

4. if y has fewer dimensions than argvals, swap them.

See Also

Data2fd smooth.basis, smooth.basisPar

Examples

Run this code
# NOT RUN {
##
## one argument:  y
##
argvalsy.swap(1:5)
# warning ... 

##
## (argvals, y), same dimensions:  retain order 
##
argy1 <- argvalsy.swap(seq(0, 1, .2), 1:6)
argy1a <- argvalsy.swap(1:6, seq(0, 1, .2))

# }
# NOT RUN {
all.equal(argy1[[1]], argy1a[[2]]) &&
all.equal(argy1[[2]], argy1a[[1]])
# TRUE;  basisobj different 
# }
# NOT RUN {
# lengths do not match 
# }
# NOT RUN {
argvalsy.swap(1:4, 1:5)
# }
# NOT RUN {
##
## two numeric arguments, different dimensions:  put simplest first 
##
argy2 <- argvalsy.swap(seq(0, 1, .2), matrix(1:12, 6))

# }
# NOT RUN {
all.equal(argy2,
argvalsy.swap(matrix(1:12, 6), seq(0, 1, .2)) )
# TRUE with a warning ... 
# }
# NOT RUN {
# }
# NOT RUN {
argvalsy.swap(seq(0, 1, .2), matrix(1:12, 2))
# ERROR:  first dimension does not match 
# }
# NOT RUN {
##
## one numeric, one basisobj
##
argy3 <- argvalsy.swap(1:6, b=4)
# warning:  argvals assumed seq(0, 1, .2) 

argy3. <- argvalsy.swap(1:6, b=create.bspline.basis(breaks=0:1))
# warning:  argvals assumed seq(0, 1, .2) 

argy3.6 <- argvalsy.swap(seq(0, 1, .2), b=create.bspline.basis(breaks=1:3))
# warning:  argvals assumed seq(1, 3 length=6)

##
## two numeric, one basisobj:  first matches basisobj
##
#  OK 
argy3a <- argvalsy.swap(1:6, seq(0, 1, .2),
              create.bspline.basis(breaks=c(1, 4, 8))) 

#  Swap (argvals, y) 
# }
# NOT RUN {
all.equal(argy3a,
argvalsy.swap(seq(0, 1, .2), 1:6, 
              create.bspline.basis(breaks=c(1, 4, 8))) )
# TRUE with a warning 
# }
# NOT RUN {

# }
# NOT RUN {
# neither match basisobj:  error  
argvalsy.swap(seq(0, 1, .2), 1:6, 
              create.bspline.basis(breaks=1:3) ) 
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace