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

Description Usage Arguments Details Value See Also Examples

View source: R/argvalsy.swap.R

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

1
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).

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.

Value

a list with components argvals, y, and basisobj.

See Also

Data2fd smooth.basis, smooth.basisPar

Examples

 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
74
75
##
## 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))


all.equal(argy1[[1]], argy1a[[2]]) &&
all.equal(argy1[[2]], argy1a[[1]])
# TRUE;  basisobj different 


# lengths do not match 
## Not run: 
argvalsy.swap(1:4, 1:5)

## End(Not run) 

##
## two numeric arguments, different dimensions:  put simplest first 
##
argy2 <- argvalsy.swap(seq(0, 1, .2), matrix(1:12, 6))


all.equal(argy2,
argvalsy.swap(matrix(1:12, 6), seq(0, 1, .2)) )
# TRUE with a warning ... 


## Not run: 
argvalsy.swap(seq(0, 1, .2), matrix(1:12, 2))
# ERROR:  first dimension does not match 

## End(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) 

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: 
# neither match basisobj:  error  
argvalsy.swap(seq(0, 1, .2), 1:6, 
              create.bspline.basis(breaks=1:3) ) 

## End(Not run)

fda documentation built on May 2, 2019, 5:12 p.m.