Re: [R] Smooth periodic splines
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.p...@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@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. -- Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK +44 1225 386603 www.maths.bath.ac.uk/~sw283 __ R-help@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.
Re: [R] Smooth periodic splines
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.p...@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@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. __ R-help@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.
Re: [R] Smooth periodic splines
2009/1/16 Spencer Graves spencer.gra...@pdf.com: 1. RSiteSearch('{periodic spline}') produced 12 hits. I looked at the first five and found that four of them seemed relevant to your question. 2. The third hit in this list notes that the DierckxSpline package has periodic splines, while 'fda' recommends finite Fourier series for periodic functions; this hit documents an as.fd function that approximates a 'dierckx' periodic object with a periodic 'fd' object. Hope this helps. Spencer Many thanks, DierckxSpline is what I was looking for. Andrey __ R-help@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.
Re: [R] Smooth periodic splines
cmr.p...@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. I don't know one, but you could use the same technique that periodicSpline uses: repeat a copy of the data to the left and right of the main copy (similarly replicating the knots if you want regression splines rather than smoothing splines), then fit to the augmented dataset. I don't think it is guaranteed to be exactly periodic, but it will be very close. There is also the periodic option to splinefun and you might be able to use it to construct a true periodic basis, but you'll have to work out some tricky details to get that right. Duncan Murdoch __ R-help@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.
Re: [R] Smooth periodic splines
1. RSiteSearch('{periodic spline}') produced 12 hits. I looked at the first five and found that four of them seemed relevant to your question. 2. The third hit in this list notes that the DierckxSpline package has periodic splines, while 'fda' recommends finite Fourier series for periodic functions; this hit documents an as.fd function that approximates a 'dierckx' periodic object with a periodic 'fd' object. Hope this helps. Spencer Duncan Murdoch wrote: cmr.p...@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. I don't know one, but you could use the same technique that periodicSpline uses: repeat a copy of the data to the left and right of the main copy (similarly replicating the knots if you want regression splines rather than smoothing splines), then fit to the augmented dataset. I don't think it is guaranteed to be exactly periodic, but it will be very close. There is also the periodic option to splinefun and you might be able to use it to construct a true periodic basis, but you'll have to work out some tricky details to get that right. Duncan Murdoch __ R-help@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. __ R-help@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.