[R] Smooth periodic splines
Spencer Graves
spencer.graves at prodsyse.com
Sun Jan 18 19:32:29 CET 2009
Two other possibilities:
The 'DierckxSpline' package includes a function 'percur' for
fitting periodic splines. Unfortunately, it has a known bug that kills
R with a segmentation fault, though it not affect your application.
The 'fda' package supports the use of finite Fourier series for
fitting periodic functions. Below please find code for this that I just
posted to R-devel in response to a report of the 'percur' bug.
Hope this helps.
Spencer Graves
# problem
x <- seq(0.2, 0.8, 0.01)
y <- cos(2*pi*x2) + 0.1*rnorm(length(x))
plot(x, y, xlim=0:1)
# simple solution
library(fda)
Fourier1 <- create.fourier.basis()
FourierFit <- Data2fd(x, y, Fourier1)
plotfit.fd(y, x, FourierFit)
# Allow more flexibility
Fourier9 <- create.fourier.basis(nbasis=2*9+1)
# constant + 9 cosine & sine terms
# Naive initial solution
FourierSmooth0 <- smooth.basisPar(x, y, Fourier9)
plotfit.fd(y, x, FourierSmooth0$fd)
# Oops: Need some smoothing
# Try again.
FourierSmooth1 <- smooth.basisPar(x, y, Fourier9, lambda=1)
plotfit.fd(y, x, FourierSmooth1$fd)
# Much better.
######################################
Simon Wood wrote:
> The "cc" and "cp" bases in package `mgcv' provide periodic splines,
> [e.g. gam(y~s(x,bs="cc"))], but this may not be exactly the functionality you
> want.
>
> best,
> Simon
>
> On Friday 16 January 2009 08:42, cmr.Pent at gmail.com wrote:
>
>> Hello group!
>>
>> Is there a package that allows to fit smooth *periodic* splines to
>> data? I'm interested in a function which combines the functionality of
>> smooth.spline and splines::periodicSpline.
>>
>> Thanks,
>> Andrey
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html and provide commented, minimal,
>> self-contained, reproducible code.
>>
>
>
More information about the R-help
mailing list