Skip to content

Commit c251256

Browse files
committed
Data2fd now works
1 parent 4f8a9bd commit c251256

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: fda
22
Version: 6.1.7
3-
Date: 2024-02-26
3+
Date: 2024-02-27
44
Title: Functional Data Analysis
55
Authors@R: c(person("James", "Ramsay", role=c("aut","cre"),
66
email="ramsay@psych.mcgill.ca"),

R/Data2fd.R

+30-26
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ Data2fd <- function(argvals=NULL, y=NULL, basisobj=NULL, nderiv=NULL,
1717

1818
# another rest with messages
1919

20+
argChk <- argvalsySwap(argvals, y, basisobj)
21+
2022
if(!is.numeric(AV <- argChk$argvals)){
21-
# terminal message
22-
if(is.null(AV)) stop('is.null(argChk$argvals); should be numeric')
23-
#. otherwise alert message
23+
print(AV)
24+
if(is.null(AV))
25+
stop('is.null(argChk$argvals); should be numeric')
2426
cat('argChk$argvals is not numeric.\n')
2527
cat('class(argChk$argvals) = ', class(AV), '\n')
2628
print(AV)
27-
}
29+
}
2830

2931
#. Success and smoothing ... S3 object of class fdSmooth is returned
3032

@@ -46,7 +48,7 @@ argvalsySwap = function(argvals=NULL, y=NULL, basisobj=NULL) {
4648
if (inherits(basisobj, 'basisfd')) rangeval <- basisobj$rangeval
4749

4850
##. --------------------------------------------------------------------------
49-
## 1. if(is.null(y)) use argvals
51+
## 1. if(is.null(y)) use argvals for y
5052
##. --------------------------------------------------------------------------
5153

5254
if(is.null(y)){
@@ -58,44 +60,49 @@ argvalsySwap = function(argvals=NULL, y=NULL, basisobj=NULL) {
5860
}
5961

6062
##. --------------------------------------------------------------------------
61-
## 2. if(is.null(argvals)). argvals <- seq(basisobj$rangeval, dim(y)[1])
63+
## 2. test for missing argvals, if so construct a sequence
6264
##. --------------------------------------------------------------------------
6365

6466
dimy <- dim(as.array(y))
65-
if(is.null(argvals)){
66-
{
67+
if(is.null(argvals)) {
68+
# the following code block is run if TRUE
69+
{ # beginning of code block
6770
if(is.null(basisobj)){
6871
basisobj <- create.bspline.basis(basisobj)
6972
} else {
7073
if(is.numeric(basisobj)) {
7174
if(length(basisobj)>1){
7275
basisobj <- create.bspline.basis(basisobj)
73-
} else
76+
} else
7477
basisobj <- create.bspline.basis(norder=basisobj)
7578
}
7679
else {
7780
if(inherits(basisobj, 'fd')){
7881
basisobj <- basisobj$basis
79-
} else
82+
} else
8083
if(inherits(basisobj, 'fdPar'))
8184
basisobj <- basisobj$fd$basis
8285
}
8386
}
84-
}
85-
if(is.null(rangeval))
86-
stop('basisobj does not have a required ',
87-
'rangeval component.')
88-
#
87+
} #. end of code block
88+
# This is executed whether or not the previous was
89+
#. locate the range from basisobj
90+
a01 <- basisobj$rangeval
91+
# if range is null, error message and stop
92+
if(is.null(a01))
93+
stop('basisobj does not have a required rangeval component.')
8994
n <- dimy[1]
90-
#. alert message
91-
cat(paste("'argvals' is missing; using seq(", rangeval[1],
92-
", ", rangeval[2], ", length=", n, ")\n"))
93-
argvals <- seq(rangeval[1], rangeval[2], length=n)
95+
# construct the argval sequence
96+
argvals <- seq(a01[1], a01[2], length=n)
97+
# warning message about the swap
98+
cat(paste("'argvals' is missing; using seq(", a01[1],
99+
", ", a01[2], ", length=", n, ")\n"))
100+
#. return
94101
return(list(argvals=argvals, y=y, basisobj=basisobj))
95102
}
96103

97104
##. --------------------------------------------------------------------------
98-
## 3. if(length(dim(argvals)) == length(dim(y))) ...
105+
## 3. swapping y and argvals
99106
##. --------------------------------------------------------------------------
100107

101108
dima <- dim(as.array(argvals))
@@ -214,24 +221,21 @@ argvalsySwap = function(argvals=NULL, y=NULL, basisobj=NULL) {
214221

215222
# set up a safety zone for argvals out of range by a tiny amount
216223
delta <- 1e-7*(rangeval[2]-rangeval[1]) # the tiny amount
217-
errwrd <- FALSE
218224
for (i in 1:length(argvals)) {
219225
argi <- argvals[i]
226+
# print(argi)
220227
if (argi < rangeval[1] && argi >= rangeval[1]-delta) {
221228
argi <- rangeval[1]
222-
} else {
223-
errwrd <- TRUE
224229
}
225230
if (argi > rangeval[2] && argi <= rangeval[2]+delta) {
226231
argi <- rangeval[2]
227-
} else {
228-
errwrd <- TRUE
229232
}
230233
}
231-
if (errwrd) {
234+
if (any(argvals < rangeval[1]) || any(argvals > rangeval[2])) {
232235
# error message
233236
stop("There are argvals not contained within interval basisobj$rangeval")
234237
}
238+
return(list(argvals=argvals, y=y, basisobj=basisobj))
235239

236240
}
237241

R/smooth.basisPar.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ smooth.basisPar <- function(argvals, y, fdobj=NULL, Lfdobj=NULL,
4141
##
4242
## 2. fdPar: set up the functional parameter object from arguments
4343
##
44-
fdobj <- fd(matrix(0,fdobj$nbasis,1), fdobj)
44+
# fdobj <- fd(matrix(0,nbasis,1), fdobj)
4545
fdP <- fdPar(fdobj, Lfdobj=Lfdobj, lambda=lambda,
4646
estimate=estimate, penmat=penmat)
4747

man/smooth.basisPar.Rd

-4
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ smooth.basisPar(argvals, y, fdobj=NULL, Lfdobj=NULL,
194194
curve. If the smooth is multivariate, the result is a matrix of gcv
195195
values, with columns corresponding to variables.
196196
}
197-
% \item{coef}{
198-
% the coefficient matrix or array for the basis function expansion of
199-
% the smoothing function
200-
% }
201197
\item{SSE}{
202198
the error sums of squares. SSE is a vector or a matrix of the same
203199
size as 'gcv'.

0 commit comments

Comments
 (0)