Skip to content

Commit 5a062bd

Browse files
committed
improvements in smooth.surp and smooth.morph
1 parent e62c60c commit 5a062bd

16 files changed

+1001
-286
lines changed

.DS_Store

0 Bytes
Binary file not shown.

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: fda
22
Version: 5.5.2
3-
Date: 2022-03-04
3+
Date: 2022-04-19
44
Title: Functional Data Analysis
55
Author: J. O. Ramsay <ramsay@psych.mcgill.ca> [aut,cre],
66
Spencer Graves <spencer.graves@effectivedefense.org> [ctb],

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export(AmpPhaseDecomp,
3535
CSTRfn,
3636
CSTRres,
3737
CSTRsse,
38+
cumfd,
3839
cycleplot.fd,
3940
Data2fd,
4041
density.fd,
@@ -84,6 +85,7 @@ export(AmpPhaseDecomp,
8485
lambda2df,
8586
lambda2gcv,
8687
landmarkreg,
88+
landmarkreg2,
8789
Lfd,
8890
lines.fdSmooth,
8991
linmod,

R/cumfd.R

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cumfd <- function(xrnd, xrng, nbreaks=7, nfine=101) {
2+
# Compute cdf_fd over a closed interval using smooth.morph.
3+
# Only the values of x within the interior of xrng are used
4+
# in order to avoid distortion due to boundary inflation.
5+
# Arguments:
6+
# xrnd ... A vector of variable values (unsorted)
7+
# xrng ... A vector of length 2 containing the boundary values.
8+
# Wnbasis ... Number of basis functions used by smooth.morph.
9+
# Snbasis ... Number of basis functions used by smooth.basis.
10+
# nfine ... Length of vector of equally spaced values spanning xrng.
11+
12+
# Last modified 25 March 2022 by Jim Ramsay
13+
14+
# check that values of x are within xrng
15+
16+
if (min(xrnd) < xrng[1] || max(xrnd) > xrng[2])
17+
stop("Values of x outside of xrng.")
18+
19+
# sort the data and set up probability values
20+
21+
xsort <- sort(xrnd[xrnd > xrng[1] & xrnd < xrng[2]])
22+
N <- length(xsort)
23+
prbvec <- (1:N)/(N+1)
24+
25+
# add boundary values
26+
27+
pmesh <- c(0, prbvec, 1)
28+
xmesh <- c(xrng[1], xsort, xrng[2])
29+
30+
# set up fdPar object for smooth.morph
31+
32+
index = c(1, round(N*2:(nbreaks-1)/nbreaks), N+2)
33+
34+
Wnorder <- 4
35+
Wnbasis <- nbreaks + Wnorder - 2
36+
Wbreaks <- xmesh[index]
37+
Wbasis <- create.bspline.basis(xrng, Wnbasis, Wnorder, Wbreaks)
38+
WfdPar <- fdPar(fd(matrix(0,Wnbasis,1), Wbasis))
39+
40+
# use smooth.morph to map sorted data into the interior of [0,1]
41+
42+
result <- smooth.morph(xmesh, pmesh, c(0,1), WfdPar)
43+
xfine <- seq(0,1,len=101)
44+
Wfdobj <- result$Wfdobj
45+
46+
cdffine <- result$hfine
47+
cdffine[1] <- 0
48+
cdffine[length(cdffine)] <- 1
49+
50+
# plot(xfine, cdffine, type="l")
51+
# points(xmesh, pmesh)
52+
53+
# plot(Wfdobj)
54+
55+
return(list(Wfdobj=Wfdobj, cdffine=cdffine))
56+
57+
}

0 commit comments

Comments
 (0)